Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
feat: certificates are created before live-server launch
Browse files Browse the repository at this point in the history
The "selfsign" npm package is used to create the server key and certificate.
  • Loading branch information
ValeraS committed Aug 18, 2018
1 parent b880861 commit 70d3167
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 66 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions .travis.yml
@@ -1,5 +1,3 @@
env:
- PASS="$PASS"
language: node_js
node_js:
- '6'
Expand All @@ -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
Expand Down
47 changes: 4 additions & 43 deletions CONTRIBUTING.md
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions 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
};
17 changes: 0 additions & 17 deletions config/live-server-https.js.example

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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"
},
Expand Down
2 changes: 2 additions & 0 deletions test/setup.js.example
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 70d3167

Please sign in to comment.