greenlock.js/tests/create-account.js

106 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-08-08 19:17:09 +00:00
'use strict';
var LE = require('../').LE;
var le = LE.create({
server: 'staging'
, acme: require('le-acme-core').ACME.create()
, store: require('le-store-certbot').create({
configDir: '~/letsencrypt.test/etc/'
2016-08-08 22:11:25 +00:00
, webrootPath: '~/letsencrypt.test/tmp/:hostname'
2016-08-08 19:17:09 +00:00
})
2016-08-08 22:11:25 +00:00
, debug: true
2016-08-08 19:17:09 +00:00
});
2016-08-08 23:14:53 +00:00
//var testId = Math.round(Date.now() / 1000).toString();
var testId = 'test1000';
2016-08-08 19:17:09 +00:00
var fakeEmail = 'coolaj86+le.' + testId + '@example.com';
2016-08-08 22:11:25 +00:00
var testEmail = 'coolaj86+le.' + testId + '@gmail.com';
2016-08-08 19:17:09 +00:00
var testAccount;
var tests = [
function () {
return le.core.accounts.checkAsync({
email: testEmail
}).then(function (account) {
if (account) {
console.error(account);
throw new Error("Test account should not exist.");
}
});
}
, function () {
return le.core.accounts.registerAsync({
email: testEmail
, agreeTos: false
, rsaKeySize: 2048
}).then(function (/*account*/) {
throw new Error("Should not register if 'agreeTos' is not truthy.");
}, function (err) {
if (err.code !== 'E_ARGS') {
throw err;
}
});
}
, function () {
return le.core.accounts.registerAsync({
email: testEmail
, agreeTos: true
, rsaKeySize: 1024
}).then(function (/*account*/) {
throw new Error("Should not register if 'rsaKeySize' is less than 2048.");
}, function (err) {
if (err.code !== 'E_ARGS') {
throw err;
}
});
}
, function () {
return le.core.accounts.registerAsync({
email: fakeEmail
, agreeTos: true
, rsaKeySize: 2048
}).then(function (/*account*/) {
// TODO test mx record
throw new Error("Registration should NOT succeed with a bad email address.");
}, function (err) {
if (err.code !== 'E_EMAIL') {
throw err;
}
});
}
, function () {
return le.core.accounts.registerAsync({
2016-08-08 22:11:25 +00:00
email: testEmail
2016-08-08 19:17:09 +00:00
, agreeTos: true
, rsaKeySize: 2048
}).then(function (account) {
testAccount = account;
2016-08-08 23:14:53 +00:00
console.log(testEmail);
console.log(testAccount);
2016-08-08 19:17:09 +00:00
if (!account) {
throw new Error("Registration should always return a new account.");
}
if (!account.email) {
throw new Error("Registration should return the email.");
}
if (!account.id) {
throw new Error("Registration should return the account id.");
}
});
}
];
function run() {
var test = tests.shift();
if (!test) {
console.info('All tests passed');
return;
}
test().then(run);
}
run();