#38 passes create test

This commit is contained in:
AJ ONeal 2016-08-08 19:14:53 -04:00
parent 29a4443d49
commit eebfe38d62
3 changed files with 28 additions and 45 deletions

View File

@ -28,8 +28,10 @@ LE._undefined = {
acme: u
, store: u
, challenger: u
, register: u
, check: u
, renewWithin: u
, memorizeFor: u
, acmeChallengePrefix: u
@ -61,6 +63,9 @@ LE.create = function (le) {
le.rsaKeySize = le.rsaKeySize || LE.rsaKeySize;
le.challengeType = le.challengeType || LE.challengeType;
le._ipc = ipc;
le.agreeToTerms = le.agreeToTerms || function (args, agreeCb) {
agreeCb(new Error("'agreeToTerms' was not supplied to LE and 'agreeTos' was not supplied to LE.register"));
};
if (!le.renewWithin) { le.renewWithin = 3 * 24 * 60 * 60 * 1000; }
if (!le.memorizeFor) { le.memorizeFor = 1 * 24 * 60 * 60 * 1000; }

View File

@ -2,9 +2,8 @@
module.exports.create = function (le) {
var PromiseA = require('bluebird');
var utils = require('./utils'); // merge, tplCopy;
var utils = require('./utils');
var RSA = PromiseA.promisifyAll(require('rsa-compat').RSA);
var crypto = require('crypto');
var core = {
//
@ -39,9 +38,11 @@ module.exports.create = function (le) {
registerAsync: function (args) {
var err;
var copy = utils.merge(args, le);
var disagreeTos;
args = utils.tplCopy(copy);
if (!args.email || !args.agreeTos || (parseInt(args.rsaKeySize, 10) < 2048)) {
disagreeTos = (!args.agreeTos && 'undefined' !== typeof args.agreeTos);
if (!args.email || disagreeTos || (parseInt(args.rsaKeySize, 10) < 2048)) {
err = new Error(
"In order to register an account both 'email' and 'agreeTos' must be present"
+ " and 'rsaKeySize' must be 2048 or greater."
@ -58,6 +59,7 @@ module.exports.create = function (le) {
}, function (/*err*/) {
return RSA.generateKeypairAsync(args.rsaKeySize, 65537, keypairOpts).then(function (keypair) {
keypair.privateKeyPem = RSA.exportPrivatePem(keypair);
keypair.publicKeyPem = RSA.exportPublicPem(keypair);
keypair.privateKeyJwk = RSA.exportPrivateJwk(keypair);
return le.store.accounts.setKeypairAsync(args, keypair);
});
@ -69,8 +71,6 @@ module.exports.create = function (le) {
return core.getAcmeUrlsAsync(args).then(function (urls) {
args._acmeUrls = urls;
throw new Error("WAIT! Don't go yet!!!");
return le.acme.registerNewAccountAsync({
email: args.email
, newRegUrl: args._acmeUrls.newReg
@ -88,28 +88,18 @@ module.exports.create = function (le) {
, accountKeypair: keypair
, debug: le.debug || args.debug
}).then(function (body) {
// TODO XXX use sha256 (the python client uses md5)
// TODO ssh fingerprint (noted on rsa-compat issues page, I believe)
keypair.publicKeyMd5 = crypto.createHash('md5').update(RSA.exportPublicPem(keypair)).digest('hex');
keypair.publicKeySha256 = crypto.createHash('sha256').update(RSA.exportPublicPem(keypair)).digest('hex');
var accountId = keypair.publicKeyMd5;
var regr = { body: body };
var account = {};
args.accountId = accountId;
account.keypair = keypair;
account.regr = regr;
account.accountId = accountId;
account.id = accountId;
account.email = args.email;
}).then(function (receipt) {
var reg = {
keypair: keypair
, receipt: receipt
, email: args.email
};
// TODO move templating of arguments to right here?
return le.store.accounts.setAsync(args, reg).then(function (account) {
// should now have account.id and account.accountId
args.account = account;
// TODO move templating to right here?
return le.store.accounts.setAsync(args, account).then(function () {
args.accountId = account.id;
return account;
});
});
@ -186,6 +176,7 @@ module.exports.create = function (le) {
}, function (/*err*/) {
return RSA.generateKeypairAsync(args.rsaKeySize, 65537, keypairOpts).then(function (keypair) {
keypair.privateKeyPem = RSA.exportPrivatePem(keypair);
keypair.publicKeyPem = RSA.exportPublicPem(keypair);
keypair.privateKeyJwk = RSA.exportPrivateJwk(keypair);
return le.store.certificates.setKeypairAsync(args, keypair);
});

View File

@ -11,7 +11,8 @@ var le = LE.create({
, debug: true
});
var testId = Math.round(Date.now() / 1000).toString();
//var testId = Math.round(Date.now() / 1000).toString();
var testId = 'test1000';
var fakeEmail = 'coolaj86+le.' + testId + '@example.com';
var testEmail = 'coolaj86+le.' + testId + '@gmail.com';
var testAccount;
@ -74,6 +75,10 @@ var tests = [
, rsaKeySize: 2048
}).then(function (account) {
testAccount = account;
console.log(testEmail);
console.log(testAccount);
if (!account) {
throw new Error("Registration should always return a new account.");
}
@ -85,24 +90,6 @@ var tests = [
}
});
}
, function () {
return le.core.accounts.checkAsync({
email: testAccount.email
}).then(function (account) {
if (!account) {
throw new Error("Test account should exist when searched by email.");
}
});
}
, function () {
return le.core.accounts.checkAsync({
accountId: testAccount.id
}).then(function (account) {
if (!account) {
throw new Error("Test account should exist when searched by account id.");
}
});
}
];
function run() {