Remove inquirer from test.js. (#1994)
We never use test.js in interactive mode so it was unnecessary complexity. Also allow registering with no email.
This commit is contained in:
parent
d0eef4b498
commit
b6c554b623
117
test/js/test.js
117
test/js/test.js
|
@ -16,67 +16,11 @@ var crypto = require("crypto");
|
||||||
var child_process = require('child_process');
|
var child_process = require('child_process');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
var inquirer = require("inquirer");
|
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
var url = require('url');
|
var url = require('url');
|
||||||
var util = require("./acme-util");
|
var util = require("./acme-util");
|
||||||
var Acme = require("./acme");
|
var Acme = require("./acme");
|
||||||
|
|
||||||
var questions = {
|
|
||||||
email: [{
|
|
||||||
type: "input",
|
|
||||||
name: "email",
|
|
||||||
message: "Please enter your email address (for recovery purposes)",
|
|
||||||
validate: function(value) {
|
|
||||||
var pass = value.match(/[\w.+-]+@[\w.-]+/i);
|
|
||||||
if (pass) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return "Please enter a valid email address";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
|
|
||||||
domain: [{
|
|
||||||
type: "input",
|
|
||||||
name: "domain",
|
|
||||||
message: "Please enter the domain name for the certificate",
|
|
||||||
validate: function(value) {
|
|
||||||
var pass = value.match(/[\w.-]+/i);
|
|
||||||
if (pass) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return "Please enter a valid domain name";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
|
|
||||||
anotherDomain: [{
|
|
||||||
type: "confirm",
|
|
||||||
name: "anotherDomain",
|
|
||||||
message: "Any more domains to validate?",
|
|
||||||
default: true,
|
|
||||||
}],
|
|
||||||
|
|
||||||
readyToValidate: [{
|
|
||||||
type: "input",
|
|
||||||
name: "noop",
|
|
||||||
message: "Press enter to when you're ready to proceed",
|
|
||||||
}],
|
|
||||||
|
|
||||||
files: [{
|
|
||||||
type: "input",
|
|
||||||
name: "keyFile",
|
|
||||||
message: "Name for key file",
|
|
||||||
default: "key.pem",
|
|
||||||
},{
|
|
||||||
type: "input",
|
|
||||||
name: "certFile",
|
|
||||||
message: "Name for certificate file",
|
|
||||||
default: "cert.der",
|
|
||||||
}],
|
|
||||||
};
|
|
||||||
|
|
||||||
var cliOptions = cli.parse({
|
var cliOptions = cli.parse({
|
||||||
// To test against the demo instance, pass --newReg "https://www.letsencrypt-demo.org/acme/new-reg"
|
// To test against the demo instance, pass --newReg "https://www.letsencrypt-demo.org/acme/new-reg"
|
||||||
// To get a cert from the demo instance, you must be publicly reachable on
|
// To get a cert from the demo instance, you must be publicly reachable on
|
||||||
|
@ -97,7 +41,6 @@ var state = {
|
||||||
newRegistrationURL: cliOptions.newReg,
|
newRegistrationURL: cliOptions.newReg,
|
||||||
registrationURL: "",
|
registrationURL: "",
|
||||||
|
|
||||||
haveCLIDomains: !!(cliOptions.domains),
|
|
||||||
domains: cliOptions.domains && cliOptions.domains.replace(/\s/g, "").split(/[^\w.-]+/),
|
domains: cliOptions.domains && cliOptions.domains.replace(/\s/g, "").split(/[^\w.-]+/),
|
||||||
validatedDomains: [],
|
validatedDomains: [],
|
||||||
validAuthorizationURLs: [],
|
validAuthorizationURLs: [],
|
||||||
|
@ -150,7 +93,7 @@ var post = function(url, body, callback) {
|
||||||
|
|
||||||
The asynchronous nature of node.js libraries makes the control flow a
|
The asynchronous nature of node.js libraries makes the control flow a
|
||||||
little hard to follow here, but it pretty much goes straight down the
|
little hard to follow here, but it pretty much goes straight down the
|
||||||
page, with detours through the `inquirer` and `http` libraries.
|
page.
|
||||||
|
|
||||||
main
|
main
|
||||||
|
|
|
|
||||||
|
@ -197,7 +140,7 @@ function makeKeyPair() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeAccountKeyPair(answers) {
|
function makeAccountKeyPair() {
|
||||||
console.log("Generating account key pair...");
|
console.log("Generating account key pair...");
|
||||||
child_process.exec("openssl genrsa -out account-key.pem 2048", function (error, stdout, stderr) {
|
child_process.exec("openssl genrsa -out account-key.pem 2048", function (error, stdout, stderr) {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -207,22 +150,19 @@ function makeAccountKeyPair(answers) {
|
||||||
state.accountKeyPair = cryptoUtil.importPemPrivateKey(fs.readFileSync("account-key.pem"));
|
state.accountKeyPair = cryptoUtil.importPemPrivateKey(fs.readFileSync("account-key.pem"));
|
||||||
state.acme = new Acme(state.accountKeyPair);
|
state.acme = new Acme(state.accountKeyPair);
|
||||||
|
|
||||||
console.log();
|
register();
|
||||||
if (cliOptions.email) {
|
|
||||||
register({email: cliOptions.email});
|
|
||||||
} else {
|
|
||||||
inquirer.prompt(questions.email, register)
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function register(answers) {
|
function register() {
|
||||||
var email = answers.email;
|
var contact = [];
|
||||||
|
if (cliOptions.email) {
|
||||||
|
contact.push("mailto:" + cliOptions.email);
|
||||||
|
}
|
||||||
// Register public key
|
// Register public key
|
||||||
post(state.newRegistrationURL, {
|
post(state.newRegistrationURL, {
|
||||||
resource: "new-reg",
|
resource: "new-reg",
|
||||||
contact: [ "mailto:" + email ],
|
contact: contact
|
||||||
}, getTerms);
|
}, getTerms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,17 +200,13 @@ function sendAgreement(termsURL) {
|
||||||
console.log("Couldn't POST agreement back to server, aborting.");
|
console.log("Couldn't POST agreement back to server, aborting.");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} else {
|
} else {
|
||||||
if (!state.domains || state.domains.length == 0) {
|
getChallenges({domain: state.domains.pop()});
|
||||||
inquirer.prompt(questions.domain, getChallenges);
|
|
||||||
} else {
|
|
||||||
getChallenges({domain: state.domains.pop()});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getChallenges(answers) {
|
function getChallenges(params) {
|
||||||
state.domain = answers.domain;
|
state.domain = params.domain;
|
||||||
|
|
||||||
// Register public key
|
// Register public key
|
||||||
post(state.newAuthorizationURL, {
|
post(state.newAuthorizationURL, {
|
||||||
|
@ -413,23 +349,12 @@ function ensureValidation(err, resp, body) {
|
||||||
state.validatedDomains.push(state.domain);
|
state.validatedDomains.push(state.domain);
|
||||||
state.validAuthorizationURLs.push(state.authorizationURL);
|
state.validAuthorizationURLs.push(state.authorizationURL);
|
||||||
|
|
||||||
if (state.haveCLIDomains) {
|
console.log("have CLI domains: ");
|
||||||
console.log("have CLI domains: ");
|
console.log(state.domains);
|
||||||
console.log(state.domains);
|
if (state.domains.length > 0) {
|
||||||
if (state.haveCLIDomains && state.domains.length > 0) {
|
getChallenges({domain: state.domains.pop()});
|
||||||
getChallenges({domain: state.domains.pop()});
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
getCertificate();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
inquirer.prompt(questions.anotherDomain, function(answers) {
|
getCertificate();
|
||||||
if (answers.anotherDomain) {
|
|
||||||
inquirer.prompt(questions.domain, getChallenges);
|
|
||||||
} else {
|
|
||||||
getCertificate();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else if (authz.status == "invalid") {
|
} else if (authz.status == "invalid") {
|
||||||
console.log("The CA was unable to validate the file you provisioned:");
|
console.log("The CA was unable to validate the file you provisioned:");
|
||||||
|
@ -490,13 +415,13 @@ function downloadCertificate(err, resp, body) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveFiles(answers) {
|
function saveFiles() {
|
||||||
fs.writeFileSync(state.certFile, state.certificate);
|
fs.writeFileSync(state.certFile, state.certificate);
|
||||||
|
|
||||||
console.log("Done!")
|
console.log("Done!")
|
||||||
console.log("To try it out:");
|
console.log("Key:", state.keyFile);
|
||||||
console.log("openssl s_server -accept 8080 -www -certform der -key "+
|
console.log("Cert:", state.certFile);
|
||||||
state.keyFile +" -cert "+ state.certFile);
|
console.log("Account Key: account-key.pem");
|
||||||
|
|
||||||
// XXX: Explicitly exit, since something's tenacious here
|
// XXX: Explicitly exit, since something's tenacious here
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
|
|
Loading…
Reference in New Issue