greenlock.js/tests/create-account.js

135 lines
2.5 KiB
JavaScript
Raw Permalink Normal View History

2016-08-08 19:17:09 +00:00
'use strict';
var LE = require('../').LE;
var le = LE.create({
2019-10-08 10:51:15 +00:00
server: 'staging',
acme: require('le-acme-core').ACME.create(),
store: require('le-store-certbot').create({
configDir: '~/letsencrypt.test/etc/',
webrootPath: '~/letsencrypt.test/tmp/:hostname'
}),
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 = [
2019-10-08 10:51:15 +00:00
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({
email: testEmail,
agreeTos: true,
rsaKeySize: 2048
})
.then(function(account) {
testAccount = account;
2016-08-08 23:14:53 +00:00
2019-10-08 10:51:15 +00:00
console.log(testEmail);
console.log(testAccount);
2016-08-08 23:14:53 +00:00
2019-10-08 10:51:15 +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.'
);
}
});
}
2016-08-08 19:17:09 +00:00
];
function run() {
2019-10-08 10:51:15 +00:00
var test = tests.shift();
if (!test) {
console.info('All tests passed');
return;
}
2016-08-08 19:17:09 +00:00
2019-10-08 10:51:15 +00:00
test().then(run);
2016-08-08 19:17:09 +00:00
}
run();