integration tests success
This commit is contained in:
parent
477e3dba33
commit
e1c9c0ef08
1
AUTHORS
1
AUTHORS
|
@ -1,2 +1 @@
|
|||
AJ ONeal <coolaj86@gmail.com> (https://coolaj86.com/)
|
||||
Hitesh Walia <hiteshwar.walia@gmail.com>
|
|
@ -0,0 +1,3 @@
|
|||
ZONE=example.co.uk
|
||||
USERNAME=johndoe
|
||||
PASSWORD=xxxxxxxx
|
72
lib/index.js
72
lib/index.js
|
@ -1,22 +1,16 @@
|
|||
'use strict';
|
||||
|
||||
var request;
|
||||
var defaults = {
|
||||
baseUrl: 'https://api.dnsimple.com/v2/'
|
||||
};
|
||||
|
||||
var defaults = {};
|
||||
|
||||
module.exports.create = function(config) {
|
||||
var baseUrl = (config.baseUrl || defaults.baseUrl).replace(/\/$/, '');
|
||||
var token = config.token;
|
||||
var account = config.account;
|
||||
|
||||
return {
|
||||
init: function(opts) {
|
||||
request = opts.request;
|
||||
return null;
|
||||
},
|
||||
zones: function(data) {
|
||||
<<<<<<< HEAD
|
||||
// console.info('List Zones', data);
|
||||
return api('GET', '/' + account + '/zones')
|
||||
.then(function(resp) {
|
||||
|
@ -25,30 +19,22 @@ module.exports.create = function(config) {
|
|||
return elem.name;
|
||||
});
|
||||
});
|
||||
=======
|
||||
//console.info('List Zones', data);
|
||||
throw Error('listing zones not implemented');
|
||||
>>>>>>> parent of 16db087... integration tests passed
|
||||
},
|
||||
set: function(data) {
|
||||
// console.info('Add TXT', data);
|
||||
var ch = data.challenge;
|
||||
//console.log('DEBUG >>> ch: ' + JSON.stringify(ch, null, 2));
|
||||
var txt = ch.dnsAuthorization;
|
||||
//console.log('DEBUG >>> txt: ' + txt);
|
||||
|
||||
return api('POST', '/' + account + '/zones/' + ch.dnsZone + '/records', {
|
||||
name: '',
|
||||
type: 'TXT',
|
||||
content: txt
|
||||
}).then(function(resp) {
|
||||
//console.log('DEBUG >>> resp: ' + JSON.stringify(resp, null, 2));
|
||||
|
||||
if (resp.statusCode === 201) {
|
||||
return true;
|
||||
}
|
||||
throw new Error('record did not set. check subdomain, api key, etc');
|
||||
|
||||
});
|
||||
throw Error('setting TXT not implemented');
|
||||
},
|
||||
remove: function(data) {
|
||||
// console.info('Remove TXT', data);
|
||||
throw Error('removing TXT not implemented');
|
||||
},
|
||||
get: function(data) {
|
||||
// console.info('List TXT', data);
|
||||
<<<<<<< HEAD
|
||||
|
||||
return api('GET', '/' + account + '/zones/' + data.challenge.dnsZone + '/records')
|
||||
.then(function(resp) {
|
||||
|
@ -83,35 +69,9 @@ module.exports.create = function(config) {
|
|||
throw new Error('Txt Record not found for removal');
|
||||
}
|
||||
});
|
||||
=======
|
||||
throw Error('listing TXTs not implemented');
|
||||
>>>>>>> parent of 16db087... integration tests passed
|
||||
}
|
||||
}
|
||||
|
||||
// Authentication and Error handling here
|
||||
function api(method, path, form) {
|
||||
var req = {
|
||||
method: method,
|
||||
url: baseUrl + path,
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + token,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
json: true,
|
||||
form: form
|
||||
};
|
||||
return request(req).then(function(resp) {
|
||||
if (2 !== Math.floor(resp.statusCode / 100)) {
|
||||
console.error(resp.statusCode, req.url);
|
||||
console.error();
|
||||
console.error('Request:');
|
||||
console.error(req);
|
||||
console.error();
|
||||
console.error('Response:');
|
||||
console.error(resp.body);
|
||||
console.error();
|
||||
throw new Error('Error response. Check token, baseUrl, domains, etc.');
|
||||
}
|
||||
return resp;
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
|
7
test.js
7
test.js
|
@ -5,12 +5,11 @@
|
|||
var tester = require('acme-challenge-test');
|
||||
require('dotenv').config();
|
||||
|
||||
// Usage: node ./test.js example.com token account
|
||||
// Usage: node ./test.js example.com username xxxxxxxxx
|
||||
var zone = process.argv[2] || process.env.ZONE;
|
||||
|
||||
var challenger = require('./index.js').create({
|
||||
token: process.argv[3] || process.env.TOKEN,
|
||||
account: process.argv[4] || process.env.ACCOUNT
|
||||
username: process.argv[3] || process.env.USERNAME,
|
||||
password: process.argv[4] || process.env.PASSWORD
|
||||
});
|
||||
|
||||
// The dry-run tests can pass on, literally, 'example.com'
|
||||
|
|
Loading…
Reference in New Issue