greenlock-manager-test.js/tester.js

166 lines
4.1 KiB
JavaScript

'use strict';
var request = require('@root/request');
var domains = ['example.com', 'www.example.com'];
module.exports.test = async function(pkg, config) {
if ('function' !== typeof pkg.create) {
throw new Error(
'must have a create function that accepts a single options object'
);
}
var manager = pkg.create(config);
if (manager.init) {
await manager.init({
request: request
});
} else {
console.warn(
'WARN: should have an init(deps) function which returns a promise'
);
}
await manager.set({
subject: domains[0],
altnames: domains
});
await manager.find({}).then(function(results) {
if (!results.length) {
console.log(results);
throw new Error('should have found all managed sites');
}
});
console.log('PASS: set');
await manager.find({ subject: 'www.example.com' }).then(function(results) {
if (results.length) {
console.log(results);
throw new Error(
"shouldn't find what doesn't exist, exactly, by subject"
);
}
});
await manager
.find({ altnames: ['www.example.com'] })
.then(function(results) {
if (!results.length) {
console.log(results);
throw new Error('should have found sites matching altname');
}
});
await manager.find({ altnames: ['*.example.com'] }).then(function(results) {
if (results.length) {
console.log(results);
throw new Error(
'should only find an exact (literal) wildcard match'
);
}
});
console.log('PASS: find');
await manager.remove({ subject: '*.example.com' }).then(function(result) {
if (result) {
throw new Error(
'should not return prior object when deleting non-existing site'
);
}
});
await manager.remove({ subject: 'www.example.com' }).then(function(result) {
if (result) {
throw new Error(
'should not return prior object when deleting non-existing site'
);
}
});
await manager.remove({ subject: 'example.com' }).then(function(result) {
if (!result || !result.subject || !result.altnames) {
throw new Error('should return prior object when deleting site');
}
});
await manager
.find({ altnames: ['example.com', 'www.example.com'] })
.then(function(results) {
if (results.length) {
console.log(results);
throw new Error('should not find deleted sites');
}
});
console.log('PASS: remove');
var originalInput = {
serverKeyType: 'RSA-2048',
accountKeyType: 'P-256',
subscriberEmail: 'jon@example.com',
agreeToTerms: true,
store: { module: '/path/to/store-module', foo: 'foo' },
challenges: {
'http-01': { module: '/path/to/http-01-module', bar: 'bar' },
'dns-01': { module: '/path/to/dns-01-module', baz: 'baz' },
'tls-alpn-01': {
module: '/path/to/tls-alpn-01-module',
qux: 'quux'
}
},
customerEmail: 'jane@example.com'
};
//var backup = JSON.parse(JSON.stringify(originalInput));
var configUpdate = {
renewOffset: '45d',
renewStagger: '12h',
subscriberEmail: 'pat@example.com'
};
var internalConfig;
await manager.defaults().then(function(result) {
internalConfig = result;
if (!result) {
throw new Error(
'should at least return an empty object, perhaps one with some defaults set'
);
}
});
await manager.defaults(originalInput).then(function(result) {
// can't say much... what _should_ this return?
// probably nothing? or maybe the full config object?
if (internalConfig === result) {
console.warn(
'WARN: should return a new copy, not the same internal object'
);
}
if (originalInput === result) {
console.warn(
'WARN: should probably return a copy, not the original input'
);
}
});
await manager.defaults().then(function(result) {
if (originalInput === result) {
console.warn('WARN: should probably return a copy, not the prior input');
}
});
await manager.defaults(configUpdate).then(function() {
if (originalInput.renewOffset) {
console.warn('WARN: should probably modify the prior input');
}
});
await manager.defaults().then(function(result) {
if (!result.subscriberEmail || !result.renewOffset) {
throw new Error('should merge config values together');
}
});
console.log('PASS: defaults');
};