2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# [acme-dns-01-test](https://git.rootprojects.org/root/acme-dns-01-test.js.git) | a [Root](https://rootprojects.org) project
  
						 
					
						
							
								
									
										
										
										
											2019-04-07 15:55:48 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								An ACME dns-01 test harness for Let's Encrypt integrations.
							 
						 
					
						
							
								
									
										
										
										
											2019-04-07 15:55:48 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This was specificially designed for [ACME.js ](https://git.coolaj86.com/coolaj86/acme-v2.js ) and [Greenlock.js ](https://git.coolaj86.com/coolaj86/greenlock-express.js ), but will be generically useful to any ACME module.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-15 13:25:11 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Passing the tests is very easy. There are just five functions to implement:
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-15 13:25:11 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  `init(deps)`  - (optional) this gives you the `request`  object you should use for HTTP APIs 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  `zones(opts)`  - list domain zones (i.e. example.co.uk, example.com) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  `set(opts)`  - set a TXT record in a zone (i.e. `_acme-challenge.foo`  in `example.co.jp` ) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  `get(opts)`  - confirm that the record was set 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  `remove(opts)`  - clean up after the ACME challenge completes 
						 
					
						
							
								
									
										
										
										
											2019-04-07 15:55:48 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The tests account for single-domain certificates (`example.com` ) as well as multiple domain certs (SAN / AltName),
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 06:15:51 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								wildcards (`*.example.com` ), and valid private / localhost certificates. No worries on your end, just pass the tests. 👌
							 
						 
					
						
							
								
									
										
										
										
											2019-04-07 15:55:48 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								**Node v6 Support**: Please build community plugins using node v6 / vanillajs
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								to ensure that all acme.js and greenlock.js users are fully supported.
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 05:41:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-07 15:55:48 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								## Install
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```bash
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								npm install --save-dev acme-dns-01-test@3 .x
							 
						 
					
						
							
								
									
										
										
										
											2019-04-07 15:55:48 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Usage
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var tester = require('acme-dns-01-test');
							 
						 
					
						
							
								
									
										
										
										
											2019-04-07 15:55:48 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-02 22:08:29 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								//var challenger = require('acme-dns-01-cli').create({});
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var challenger = require('./YOUR-CHALLENGE-STRATEGY').create({
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									YOUR_TOKEN_OPTION: 'SOME_API_KEY'
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 06:20:19 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								});
							 
						 
					
						
							
								
									
										
										
										
											2019-04-07 15:55:48 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// The dry-run tests can pass on, literally, 'example.com'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// but the integration tests require that you have control over the domain
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var zone = 'example.com';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								tester.testZone('dns-01', zone, challenger).then(function() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									console.info('PASS');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								});
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2019-04-07 15:55:48 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								**Note**: If the service you are testing only handles individual records
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								(not multiple records in a zone), you can use `testRecord`  instead:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var record = 'foo.example.com';
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								tester.testRecord('dns-01', record, challenger).then(function() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									console.info('PASS');
							 
						 
					
						
							
								
									
										
										
										
											2019-04-07 15:55:48 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								});
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-15 22:50:02 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Reference Implementations
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-15 13:25:11 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  Compatibility 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  - [x]  Let's Encrypt v2.1 / ACME draft 18
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  - [x]  Node v6+
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  - [x]  Chrome, Firefox, Safari, Edge, etc
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  Quality 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  - [x]  Written in VanillaJS
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  - [x]  No compliers or build scripts
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  - [x]  Simple, minimal code, in a single file
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  - [x]  **Zero dependencies** 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								These libraries are useful as a model for any plugins that you create.
							 
						 
					
						
							
								
									
										
										
										
											2019-04-15 22:50:02 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  dns-01 
						 
					
						
							
								
									
										
										
										
											2019-06-15 13:25:11 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  -  [`cli` ](https://git.rootprojects.org/root/acme-dns-01-cli.js )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  -  [`digitalocean` ](https://git.rootprojects.org/root/acme-dns-01-digitalocean.js )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  -  [`vultr` ](https://git.rootprojects.org/root/acme-dns-01-vultr.js )
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  http-01 
						 
					
						
							
								
									
										
										
										
											2019-06-15 13:25:11 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  -  [`cli` ](https://git.rootprojects.org/root/acme-http-01-cli.js )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  -  [`fs` ](https://git.rootprojects.org/root/acme-http-01-fs.js )
							 
						 
					
						
							
								
									
										
										
										
											2019-04-15 22:50:02 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								You can find other implementations by searching npm for [acme-http-01- ](https://www.npmjs.com/search?q=acme-http-01- )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								and [acme-dns-01- ](https://www.npmjs.com/search?q=acme-dns-01- ).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								If you are building a plugin, please let us know.
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								We may like to co-author and help maintain and promote your module.
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 06:15:51 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-15 13:25:11 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< small > Note: In some cases (such as non-HTTP, or very complex APIs) you will not be able to maintain 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								browser compatibility. Other than than, if you keep your code simple, it will also work in browser
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								implementations of ACME.js.< / small > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-15 22:50:02 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Example
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								See `example.js`  (it works).
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 05:41:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Starter Template
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Here's what you could start with.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var tester = require('acme-dns-01-test');
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 05:41:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// The dry-run tests can pass on, literally, 'example.com'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// but the integration tests require that you have control over the domain
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var zone = 'example.com';
							 
						 
					
						
							
								
									
										
										
										
											2019-06-15 13:25:11 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var request;
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 06:49:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								tester
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									.testZone('dns-01', zone, {
							 
						 
					
						
							
								
									
										
										
										
											2019-06-15 13:25:11 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Gives you the promisified `request`  object for HTTP APIs
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										init: function(deps) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											request = deps.request;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return null;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										},
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Should return an array of zone domain name strings
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// (APIs that don't implement zones, such as DuckDNS, should return an empty array)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										zones: function(opts) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											console.log('dnsHosts:', opts.dnsHosts);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											throw new Error('_zone not implemented');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										},
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// Should set a TXT record for dnsHost with dnsAuthorization and ttl || 300
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										set: function(opts) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											console.log('set opts:', opts);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											throw new Error('set not implemented');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										},
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Should remove the *one*  TXT record for dnsHost with dnsAuthorization
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Should NOT remove otherrecords for dnsHost (wildcard shares dnsHost with
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// non-wildcard)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										remove: function(opts) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											console.log('remove opts:', opts);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											throw new Error('remove not implemented');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										},
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// Should get the record via the DNS server's API
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// (Note: gets different options than set or remove)
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										get: function(opts) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											console.log('get opts:', opts);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											throw new Error('get not implemented');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									.then(function() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										console.info('PASS');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									});
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 05:41:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 06:07:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## dns-01 vs http-01
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								For `type`  dns-01:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // `dnsHost`  is the domain/subdomain/host
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // `dnsAuthorization`  is the value of the TXT record
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // `dnsPrefix`  is the record-only part, if `zones()`  is implemented
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // `dnsZone`  is the zone-only part, if `zones()`  is implemented
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 06:07:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								For `type`  http-01:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // `altname`  is the name of the domain
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // `token`  is the name of the file ( .well-known/acme-challenge/`token`  )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // `keyAuthorization`  is the contents of the file
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								See [acme-http-01-test.js ](https://git.rootprojects.org/root/acme-dns-01-test.js.git ).
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 06:07:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 05:41:27 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Detailed Overview
  
						 
					
						
							
								
									
										
										
										
											2019-04-07 15:55:48 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-15 22:50:02 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Here's a quick pseudo stub-out of what a test-passing plugin object might look like:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-04-07 15:55:48 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
									
										
										
										
											2019-06-15 13:25:11 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								var request;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 06:49:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								tester
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									.testZone('dns-01', 'example.com', {
							 
						 
					
						
							
								
									
										
										
										
											2019-06-15 13:25:11 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										init: function(deps) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// { request: { get, post, put, delete }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											request = deps.request;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return null;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										},
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										zones: function(opts) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// { dnsHosts: [
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											//     '_acme-challenge.foo.example.com',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											//     '_acme-challenge.bar.example.com'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											//  ] }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return YourApi(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												'GET',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// Most Domain Zone apis don't have a search or filter option,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// but `opts`  includes list of dnsHosts is provided just in case.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												'https://exampledns.com/api/dns/zones?search=' + opts.dnsHosts.join(',')
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											).then(function(result) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return result.zones.map(function(zone) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													return zone.name;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												});
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											});
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										},
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										set: function(opts) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var ch = opts.challenge;
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// { type: 'dns-01'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// , identifier: { type: 'dns', value: 'foo.example.com' }
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// , wildcard: false
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// , dnsHost: '_acme-challenge.foo.example.com'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// , dnsPrefix: '_acme-challenge.foo'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// , dnsZone: 'example.com'
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// , dnsAuthorization: 'zzzz' }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return YourApi(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												'POST',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												'https://exampledns.com/api/dns/txt/' + ch.dnsZone + '/' + ch.dnsPrefix,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												{ value: ch.dnsAuthorization }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											);
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										},
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										get: function(query) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var ch = query.challenge;
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// { type: 'dns-01'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// , identifier: { type: 'dns', value: 'foo.example.com' }
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// , altname: '...'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// , dnsHost: '...'
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// , wildcard: false }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// Note: query.identifier.value is different for http-01 than for dns-01
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											//       because of how a DNS query is different from an HTTP request
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return YourApi(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												'GET',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												'https://exampledns.com/api/dns/txt/' + ch.dnsZone + '/' + ch.dnsPrefix
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											).then(function(secret) {
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												return { dnsAuthorization: secret };
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											});
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										},
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										remove: function(opts) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											var ch = opts.challenge;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// same options as in `set()`  (which are not the same as `get()` 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-13 00:36:53 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return YourApi(
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												'DELETE',
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												'https://exampledns.com/api/dns/txt/' + ch.dnsZone + '/' + ch.dnsPrefix
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											);
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									})
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									.then(function() {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										console.info('PASS');
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									});
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 06:49:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2019-04-07 15:55:48 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 06:49:46 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Where `YourApi`  might look something like this:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								var YourApi = function createApi(config) {
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									return function(method, url, body) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return request({
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											method: method,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											url: url,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											json: body || true,
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											headers: {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												Authorization: 'Bearer ' + config.apiToken
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										}).then(function(resp) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return resp.body;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										});
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									};
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								};
							 
						 
					
						
							
								
									
										
										
										
											2019-04-07 15:55:48 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-15 13:25:11 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Note: `request`  is actually `@root/request` , but the API is the same as the standard `request` .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Avoid using 3rd party API libraries where you can - they tend to bloat your dependencies and
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								add security risk. Instead, just use the API documentation and cURL examples.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 06:07:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Two notes:
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Note 1:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The `API.get()` , `API.set()` , and `API.remove()`  is where you do your magic up to upload a file to the correct
							 
						 
					
						
							
								
									
										
										
										
											2019-04-07 15:55:48 -06:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								location on an http serever, set DNS records, or add the appropriate data to the database that handles such things.
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 06:07:08 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Note 2:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-06-06 23:04:51 -06:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								-  When `altname`  is `foo.example.com`  the `dnsHost`  will be `_acme-challenge.foo.example.com`  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  When `altname`  is `*.foo.example.com`  the `dnsHost`  will _still_  be `_acme-challenge.foo.example.com` !! 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								-  When `altname`  is `bar.foo.example.com`  the `dnsHost`  will be `_acme-challenge.bar.foo.example.com`