From 70d31670bd9f9c431ff24b46d705b2d81bb0cd72 Mon Sep 17 00:00:00 2001 From: ValeraS Date: Thu, 16 Aug 2018 17:21:31 +0300 Subject: [PATCH] feat: certificates are created before live-server launch The "selfsign" npm package is used to create the server key and certificate. --- .gitignore | 1 - .travis.yml | 6 +--- CONTRIBUTING.md | 47 +++-------------------------- config/live-server-https.js | 14 +++++++++ config/live-server-https.js.example | 17 ----------- package.json | 1 + test/setup.js.example | 2 ++ yarn.lock | 10 ++++++ 8 files changed, 32 insertions(+), 66 deletions(-) create mode 100644 config/live-server-https.js delete mode 100644 config/live-server-https.js.example diff --git a/.gitignore b/.gitignore index 71e2faa0..4cc1fdfc 100644 --- a/.gitignore +++ b/.gitignore @@ -31,7 +31,6 @@ node_modules jspm_packages # Some config files. -config/live-server-https.js config/server.crt config/server.csr config/server.key diff --git a/.travis.yml b/.travis.yml index 31785e6e..419641cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,3 @@ -env: - - PASS="$PASS" language: node_js node_js: - '6' @@ -16,11 +14,9 @@ before_script: - "export DISPLAY=:99.0" - cp test/setup.js.travis test/setup.js # Start https server (and sleep) so we can get the local bundle.js via https. - # This is basically the same process for generating self-signed certificates - # outlined in CONTRIBUTING, followed by npm run `live-serve-build &` # The `&` at the end tells this process to fork into the background # https://github.com/travis-ci/travis-ci/issues/1321 - - cd config && openssl genrsa -des3 -passout pass:PASS -out server.key 2048 && openssl req -passin pass:PASS -new -key server.key -out server.csr -subj "/C=BR/ST=Parana/L=Curitiba/O=fCC/OU=test/CN=freeCodeCamp" && cp server.key server.key.org && openssl rsa -in server.key.org -passin pass:PASS -out server.key && openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt && cp live-server-https.js.example live-server-https.js && sleep 3 && npm run live-serve-build & + - npm run live-serve-build & # Increase the shared memory mountpoint. Chrome or something in the tests is # taking up more shared memory than is available which causes tests to fail. # See https://github.com/SeleniumHQ/docker-selenium/issues/431 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 64566e2c..fdc4d0b9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -81,53 +81,14 @@ need to be run one time. 1. You should have already run `yarn` per the forking instructions. 1. Make sure you have the Chrome browser installed. You should have version 59.0.3071.115 or later. -1. To make your local `bundle.js` available via https you will need to create -server certificates (see below). +1. To make your local `bundle.js` available via https you will need to start +the live-server (see below). 1. You need to configure your test environment by setting up the `test/setup.js` file (see below). +**Starting the live-server** -**Creating Self-Signed Server Certificates** - -In order to serve your local bundle.js and test it, you need to use https. We -have done most of the work for you, but you will need to run a few quick -commands. The below works for both Linux and Mac. (YMMV for Windows, and please -update these docs if you figure out how to do this for Windows). - -Create the Certificates -- Make sure you have OpenSSL installed. -- From this project's root directory run the following and follow the prompts. -You will need to enter a passphrase (which you will need later), and the answers -to the other questions do not matter so put whatever you want: - -``` -cd config -openssl genrsa -des3 -out server.key 2048 -openssl req -new -key server.key -out server.csr -openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt -cp live-server-https.example live-server-https.js -``` - -You should now have the following files in your `config` directory: - -``` -live-server-https.js -live-server-https.js.example -server.crt -server.csr -server.key -``` - -Edit the `live-server-https.js` file and change the passphrase to what you used -above. (The `live-server-https.js` file along with your certificates are all -ignored by git, so you don't need to worry about your passphrase being committed -to the repo and the files should be safe from being overwritten once you create -them). - -If for some reason these files get clobbered, you can safely re-run the above -commands to recreate the certs. - -You can test your work by running the following command: +You can start the live-server with the following command: ``` yarn run live-serve-build diff --git a/config/live-server-https.js b/config/live-server-https.js new file mode 100644 index 00000000..8d36faa1 --- /dev/null +++ b/config/live-server-https.js @@ -0,0 +1,14 @@ +/** + * Used by live-server to serve https. We use live-server for the + * automated tests to serve up the local version of bundle.js. + */ + +const selfsigned = require('selfsigned'); + +let attrs = [{ name: 'commonName', value: 'localhost' }]; +let pems = selfsigned.generate(attrs, { days: 365 }); + +module.exports = { + cert: pems.cert, + key: pems.private +}; diff --git a/config/live-server-https.js.example b/config/live-server-https.js.example deleted file mode 100644 index 504521e5..00000000 --- a/config/live-server-https.js.example +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Used by live-server to serve https. We use live-server for the - * automated tests to serve up the local version of bundle.js. - * - * You will have to create a server.crt and server.key file in this directory - * which should be straightforward on most OSes. Change the password below to - * whatever you used when creating the certificate. - * - */ -var fs = require('fs'); -var path = require('path'); - -module.exports = { - cert: fs.readFileSync(path.join(__dirname, '/server.crt')), - key: fs.readFileSync(path.join(__dirname, '/server.key')), - passphrase: process.env.PASS -}; diff --git a/package.json b/package.json index 0bcb6e01..b743fe3d 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "live-server": "^1.2.0", "mocha": "^5.2.0", "selenium-webdriver": "^3.4.0", + "selfsigned": "^1.10.3", "style-loader": "^0.18.2", "webpack-cli": "^2.1.5" }, diff --git a/test/setup.js.example b/test/setup.js.example index cdb30741..399a51b2 100644 --- a/test/setup.js.example +++ b/test/setup.js.example @@ -12,6 +12,8 @@ // global.chromeBinaryPath = '/usr/bin/google-chrome-stable'; // global.chromeBinaryPath = // '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'; +// global.chromeBinaryPath = +// 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'; // The URL you want to be used for the bundle.js when running local tests. // The below value is typically used when you are using: diff --git a/yarn.lock b/yarn.lock index 39a3e2c3..6d2e04cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4949,6 +4949,10 @@ node-fetch@^1.0.1: encoding "^0.1.11" is-stream "^1.0.1" +node-forge@0.7.5: + version "0.7.5" + resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.7.5.tgz#6c152c345ce11c52f465c2abd957e8639cd674df" + node-libs-browser@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/node-libs-browser/-/node-libs-browser-2.1.0.tgz#5f94263d404f6e44767d726901fff05478d600df" @@ -6330,6 +6334,12 @@ selenium-webdriver@^3.4.0: tmp "0.0.30" xml2js "^0.4.17" +selfsigned@^1.10.3: + version "1.10.3" + resolved "https://registry.yarnpkg.com/selfsigned/-/selfsigned-1.10.3.tgz#d628ecf9e3735f84e8bafba936b3cf85bea43823" + dependencies: + node-forge "0.7.5" + "semver@2 || 3 || 4 || 5", semver@^5.3.0, semver@^5.4.1, semver@^5.5.0: version "5.5.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab"