Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): Switching from devcert-san to devcert to fix HTTPS issues #16726

Merged
merged 9 commits into from
Feb 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"debug": "^3.2.6",
"del": "^5.1.0",
"detect-port": "^1.3.0",
"devcert-san": "^0.3.3",
"devcert": "^1.0.2",
"dotenv": "^8.2.0",
"eslint": "^6.7.2",
"eslint-config-react-app": "^5.1.0",
Expand Down
22 changes: 15 additions & 7 deletions packages/gatsby/src/commands/develop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ import {
import { BuildHTMLStage, IProgram } from "./types"
import { waitUntilAllJobsComplete as waitUntilAllJobsV2Complete } from "../utils/jobs-manager"

// checks if a string is a valid ip
const REGEX_IP = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$/

const waitUntilAllJobsComplete = (): Promise<void> => {
const jobsV1Promise = new Promise(resolve => {
const onEndJob = (): void => {
Expand Down Expand Up @@ -377,16 +380,21 @@ module.exports = async (program: IProgram): Promise<void> => {
}

// Check if https is enabled, then create or get SSL cert.
// Certs are named after `name` inside the project's package.json.
// Scoped names are converted from @npm/package-name to npm--package-name.
// If the name is unavailable, generate one using the current working dir.
// Certs are named 'devcert' and issued to the host.
if (program.https) {
const name = program.sitePackageJson.name
? program.sitePackageJson.name.replace(`@`, ``).replace(`/`, `--`)
: process.cwd().replace(/[^A-Za-z0-9]/g, `-`)
const sslHost =
program.host === `0.0.0.0` || program.host === `::`
? `localhost`
: program.host

if (REGEX_IP.test(sslHost)) {
report.panic(
`You're trying to generate a ssl certificate for an IP (${sslHost}). Please use a hostname instead.`
)
}

program.ssl = await getSslCert({
name,
name: sslHost,
certFile: program[`cert-file`],
keyFile: program[`key-file`],
directory: program.directory,
Expand Down
14 changes: 8 additions & 6 deletions packages/gatsby/src/utils/__tests__/get-ssl-cert.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ jest.mock(`gatsby-cli/lib/reporter`, () => {
info: jest.fn(),
}
})
jest.mock(`devcert-san`, () => {
jest.mock(`devcert`, () => {
return {
default: jest.fn(),
certificateFor: jest.fn(),
}
})

const devcertSan = require(`devcert-san`).default
const { certificateFor } = require(`devcert`)
const reporter = require(`gatsby-cli/lib/reporter`)
const getSslCert = require(`../get-ssl-cert`)

describe(`gets ssl certs`, () => {
beforeEach(() => {
reporter.panic.mockClear()
reporter.info.mockClear()
devcertSan.mockClear()
certificateFor.mockClear()
})
describe(`Custom SSL certificate`, () => {
it.each([[{ certFile: `foo` }], [{ keyFile: `bar` }]])(
Expand Down Expand Up @@ -60,11 +60,13 @@ describe(`gets ssl certs`, () => {
describe(`automatic SSL certificate`, () => {
it(`sets up dev cert`, () => {
getSslCert({ name: `mock-cert` })
expect(devcertSan).toBeCalledWith(`mock-cert`, { installCertutil: true })
expect(certificateFor).toBeCalledWith(`mock-cert`, {
installCertutil: true,
})
expect(reporter.info.mock.calls).toMatchSnapshot()
})
it(`panics if certificate can't be created`, () => {
devcertSan.mockImplementation(() => {
certificateFor.mockImplementation(() => {
throw new Error(`mock error message`)
})
getSslCert({ name: `mock-cert` })
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/src/utils/get-ssl-cert.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const getDevelopmentCertificate = require(`devcert-san`).default
const certificateFor = require(`devcert`).certificateFor
const report = require(`gatsby-cli/lib/reporter`)
const fs = require(`fs`)
const path = require(`path`)
Expand Down Expand Up @@ -35,7 +35,7 @@ module.exports = async ({ name, certFile, keyFile, directory }) => {

report.info(`setting up automatic SSL certificate (may require sudo)\n`)
try {
return await getDevelopmentCertificate(name, {
return await certificateFor(name, {
installCertutil: true,
})
} catch (err) {
Expand Down
149 changes: 94 additions & 55 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3834,9 +3834,10 @@
dependencies:
"@types/node" "*"

"@types/debug@^0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-0.0.29.tgz#a1e514adfbd92f03a224ba54d693111dbf1f3754"
"@types/debug@^0.0.30":
version "0.0.30"
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-0.0.30.tgz#dc1e40f7af3b9c815013a7860e6252f6352a84df"
integrity sha512-orGL5LXERPYsLov6CWs3Fh6203+dXzJkR7OnddIr2514Hsecwc8xRpzCapshBbKFImCsvS/mk6+FWiN5LyZJAQ==

"@types/eslint-visitor-keys@^1.0.0":
version "1.0.0"
Expand Down Expand Up @@ -3875,22 +3876,24 @@
dependencies:
"@types/node" "*"

"@types/get-port@^0.0.4":
version "0.0.4"
resolved "https://registry.yarnpkg.com/@types/get-port/-/get-port-0.0.4.tgz#eb6bb7423d9f888b632660dc7d2fd3e69a35643e"
"@types/get-port@^3.2.0":
version "3.2.0"
resolved "https://registry.yarnpkg.com/@types/get-port/-/get-port-3.2.0.tgz#f9e0a11443cc21336470185eae3dfba4495d29bc"
integrity sha512-TiNg8R1kjDde5Pub9F9vCwZA/BNW9HeXP5b9j7Qucqncy/McfPZ6xze/EyBdXS5FhMIGN6Fx3vg75l5KHy3V1Q==

"@types/glob@^5.0.30":
version "5.0.35"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-5.0.35.tgz#1ae151c802cece940443b5ac246925c85189f32a"
"@types/glob@*", "@types/glob@^7.1.1":
version "7.1.1"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575"
integrity sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w==
dependencies:
"@types/events" "*"
"@types/minimatch" "*"
"@types/node" "*"

"@types/glob@^7.1.1":
version "7.1.1"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575"
integrity sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w==
"@types/glob@^5.0.34":
version "5.0.36"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-5.0.36.tgz#0c80a9c8664fc7d19781de229f287077fd622cb2"
integrity sha512-KEzSKuP2+3oOjYYjujue6Z3Yqis5HKA1BsIC+jZ1v3lrRNdsqyNNtX0rQf6LSuI4DJJ2z5UV//zBZCcvM0xikg==
dependencies:
"@types/events" "*"
"@types/minimatch" "*"
Expand Down Expand Up @@ -3938,7 +3941,7 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.3.tgz#bdfd69d61e464dcc81b25159c270d75a73c1a636"
integrity sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==

"@types/lodash@^4.14.149":
"@types/lodash@^4.14.149", "@types/lodash@^4.14.92":
version "4.14.149"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.149.tgz#1342d63d948c6062838fbf961012f74d4e638440"
integrity sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ==
Expand All @@ -3959,9 +3962,12 @@
version "3.0.3"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"

"@types/mkdirp@^0.3.29":
version "0.3.29"
resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-0.3.29.tgz#7f2ad7ec55f914482fc9b1ec4bb1ae6028d46066"
"@types/mkdirp@^0.5.2":
version "0.5.2"
resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-0.5.2.tgz#503aacfe5cc2703d5484326b1b27efa67a339c1f"
integrity sha512-U5icWpv7YnZYGsN4/cmh3WD2onMY0aJIiTE6+51TwJCttdHvtCYmkBNOobHlXwrJRL0nkH9jH4kD+1FAdMN4Tg==
dependencies:
"@types/node" "*"

"@types/node@*", "@types/node@^12.6.2":
version "12.6.8"
Expand All @@ -3978,9 +3984,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.7.5.tgz#e19436e7f8e9b4601005d73673b6dc4784ffcc2f"
integrity sha512-9fq4jZVhPNW8r+UYKnxF1e2HkDWOWKM5bC2/7c9wPV835I0aOrVbS/Hw/pWPk2uKrNXQqg9Z959Kz+IYDd5p3w==

"@types/node@^7.0.11":
version "7.0.70"
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.70.tgz#688aaeb6e6d374ed016c4dc2c46de695859d6887"
"@types/node@^8.5.7":
version "8.10.59"
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.59.tgz#9e34261f30183f9777017a13d185dfac6b899e04"
integrity sha512-8RkBivJrDCyPpBXhVZcjh7cQxVBSmRk9QM7hOketZzp6Tg79c0N8kkpAIito9bnJ3HCVCHVYz+KHTEbfQNfeVQ==

"@types/normalize-package-data@^2.4.0":
version "2.4.0"
Expand Down Expand Up @@ -4046,6 +4053,14 @@
dependencies:
"@types/node" "*"

"@types/rimraf@^2.0.2":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@types/rimraf/-/rimraf-2.0.3.tgz#0199a46af106729ba14213fda7b981278d8c84f2"
integrity sha512-dZfyfL/u9l/oi984hEXdmAjX3JHry7TLWw43u1HQ8HhPv6KtfxnrZ3T/bleJ0GEvnk9t5sM7eePkgMqz3yBcGg==
dependencies:
"@types/glob" "*"
"@types/node" "*"

"@types/serve-static@*":
version "1.13.3"
resolved "https://registry.yarnpkg.com/@types/serve-static/-/serve-static-1.13.3.tgz#eb7e1c41c4468272557e897e9171ded5e2ded9d1"
Expand Down Expand Up @@ -4083,9 +4098,10 @@
"@types/react-dom" "*"
"@types/testing-library__dom" "*"

"@types/tmp@^0.0.32":
version "0.0.32"
resolved "https://registry.yarnpkg.com/@types/tmp/-/tmp-0.0.32.tgz#0d3cb31022f8427ea58c008af32b80da126ca4e3"
"@types/tmp@^0.0.33":
version "0.0.33"
resolved "https://registry.yarnpkg.com/@types/tmp/-/tmp-0.0.33.tgz#1073c4bc824754ae3d10cfab88ab0237ba964e4d"
integrity sha1-EHPEvIJHVK49EM+riKsCN7qWTk0=

"@types/tough-cookie@*":
version "2.3.5"
Expand Down Expand Up @@ -4720,7 +4736,7 @@ ansi-colors@^3.0.0:
version "3.0.5"
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-3.0.5.tgz#cb9dc64993b64fd6945485f797fc3853137d9a7b"

ansi-escapes@^3.0.0, ansi-escapes@^3.2.0:
ansi-escapes@^3.0.0, ansi-escapes@^3.1.0, ansi-escapes@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.2.0.tgz#8780b98ff9dbf5638152d1f1fe5c1d7b4442976b"

Expand Down Expand Up @@ -4875,6 +4891,11 @@ append-buffer@^1.0.2:
dependencies:
buffer-equal "^1.0.0"

application-config-path@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/application-config-path/-/application-config-path-0.1.0.tgz#193c5f0a86541a4c66fba1e2dc38583362ea5e8f"
integrity sha1-GTxfCoZUGkxm+6Hi3DhYM2LqXo8=

aproba@^1.0.3, aproba@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a"
Expand Down Expand Up @@ -7008,9 +7029,10 @@ comma-separated-tokens@^1.0.0, comma-separated-tokens@^1.0.1:
dependencies:
trim "0.0.1"

command-exists@^1.2.2:
version "1.2.7"
resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.7.tgz#16828f0c3ff2b0c58805861ef211b64fc15692a8"
command-exists@^1.2.4:
version "1.2.8"
resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.8.tgz#715acefdd1223b9c9b37110a149c6392c2852291"
integrity sha512-PM54PkseWbiiD/mMsbvW351/u+dafwTJ0ye2qB60G1aGQP9j3xK2gmMDc+R34L3nDtx4qMCitXT75mkbkGJDLw==

commander@2.17.x, commander@~2.17.1:
version "2.17.1"
Expand Down Expand Up @@ -8096,7 +8118,7 @@ de-indent@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/de-indent/-/de-indent-1.0.2.tgz#b2038e846dc33baa5796128d0804b455b8c1e21d"

debug@2, debug@2.6.9, debug@^2.1.2, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.3, debug@^2.6.6, debug@^2.6.8, debug@^2.6.9:
debug@2, debug@2.6.9, debug@^2.1.2, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.6, debug@^2.6.8, debug@^2.6.9:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
dependencies:
Expand Down Expand Up @@ -8454,26 +8476,34 @@ detective@^4.0.0:
acorn "^5.2.1"
defined "^1.0.0"

devcert-san@^0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/devcert-san/-/devcert-san-0.3.3.tgz#aa77244741b2d831771c011f22ee25e396ad4ba9"
devcert@^1.0.2:
version "1.1.0"
resolved "https://registry.yarnpkg.com/devcert/-/devcert-1.1.0.tgz#255508c20dd21045e3020acf438491b745835dfd"
integrity sha512-ppyIBJueMMisYvJABaXESY10CwEm1pUXoLOm6TeBO2bbDUQE8ZjJPNADlu31I2InL7hduSgratzRG/dHUDF41w==
dependencies:
"@types/configstore" "^2.1.1"
"@types/debug" "^0.0.29"
"@types/get-port" "^0.0.4"
"@types/glob" "^5.0.30"
"@types/mkdirp" "^0.3.29"
"@types/node" "^7.0.11"
"@types/tmp" "^0.0.32"
command-exists "^1.2.2"
"@types/debug" "^0.0.30"
"@types/get-port" "^3.2.0"
"@types/glob" "^5.0.34"
"@types/lodash" "^4.14.92"
"@types/mkdirp" "^0.5.2"
"@types/node" "^8.5.7"
"@types/rimraf" "^2.0.2"
"@types/tmp" "^0.0.33"
application-config-path "^0.1.0"
command-exists "^1.2.4"
configstore "^3.0.0"
debug "^2.6.3"
eol "^0.8.1"
get-port "^3.0.0"
glob "^7.1.1"
debug "^3.1.0"
eol "^0.9.1"
get-port "^3.2.0"
glob "^7.1.2"
lodash "^4.17.4"
mkdirp "^0.5.1"
tmp "^0.0.31"
tslib "^1.6.0"
password-prompt "^1.0.4"
rimraf "^2.6.2"
sudo-prompt "^8.2.0"
tmp "^0.0.33"
tslib "^1.10.0"

dezalgo@^1.0.0:
version "1.0.3"
Expand Down Expand Up @@ -9014,9 +9044,10 @@ envinfo@^7.5.0:
resolved "https://registry.yarnpkg.com/envinfo/-/envinfo-7.5.0.tgz#91410bb6db262fb4f1409bd506e9ff57e91023f4"
integrity sha512-jDgnJaF/Btomk+m3PZDTTCb5XIIIX3zYItnCRfF73zVgvinLoRomuhi75Y4su0PtQxWz4v66XnLLckyvyJTOIQ==

eol@^0.8.1:
version "0.8.1"
resolved "https://registry.yarnpkg.com/eol/-/eol-0.8.1.tgz#defc3224990c7eca73bb34461a56cf9dc24761d0"
eol@^0.9.1:
version "0.9.1"
resolved "https://registry.yarnpkg.com/eol/-/eol-0.9.1.tgz#f701912f504074be35c6117a5c4ade49cd547acd"
integrity sha512-Ds/TEoZjwggRoz/Q2O7SE3i4Jm66mqTDfmdHdq/7DKVk3bro9Q8h6WdXKdPqFLMoqxrDK5SVRzHVPOS6uuGtrg==

err-code@^1.0.0:
version "1.1.2"
Expand Down Expand Up @@ -10714,9 +10745,10 @@ get-pkg-repo@^1.0.0:
parse-github-repo-url "^1.3.0"
through2 "^2.0.0"

get-port@^3.0.0:
get-port@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/get-port/-/get-port-3.2.0.tgz#dd7ce7de187c06c8bf353796ac71e099f0980ebc"
integrity sha1-3Xzn3hh8Bsi/NTeWrHHgmfCYDrw=

get-port@^4.0.0, get-port@^4.2.0:
version "4.2.0"
Expand Down Expand Up @@ -16799,7 +16831,7 @@ os-name@^3.0.0:
macos-release "^2.2.0"
windows-release "^3.1.0"

os-tmpdir@^1.0.0, os-tmpdir@^1.0.1, os-tmpdir@~1.0.1, os-tmpdir@~1.0.2:
os-tmpdir@^1.0.0, os-tmpdir@^1.0.1, os-tmpdir@~1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274"

Expand Down Expand Up @@ -17276,6 +17308,14 @@ passerror@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/passerror/-/passerror-1.1.1.tgz#a25b88dbdd910a29603aec7dcb96e9a7a97687b4"

password-prompt@^1.0.4:
version "1.1.2"
resolved "https://registry.yarnpkg.com/password-prompt/-/password-prompt-1.1.2.tgz#85b2f93896c5bd9e9f2d6ff0627fa5af3dc00923"
integrity sha512-bpuBhROdrhuN3E7G/koAju0WjVw9/uQOG5Co5mokNj0MiOSBVZS1JTwM4zl55hu0WFmIEFvO9cU9sJQiBIYeIA==
dependencies:
ansi-escapes "^3.1.0"
cross-spawn "^6.0.5"

path-browserify@0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.1.tgz#e6c4ddd7ed3aa27c68a20cc4e50e1a4ee83bbc4a"
Expand Down Expand Up @@ -21226,6 +21266,11 @@ subfont@^3.7.1:
urltools "^0.4.1"
yargs "^12.0.2"

sudo-prompt@^8.2.0:
version "8.2.5"
resolved "https://registry.yarnpkg.com/sudo-prompt/-/sudo-prompt-8.2.5.tgz#cc5ef3769a134bb94b24a631cc09628d4d53603e"
integrity sha512-rlBo3HU/1zAJUrkY6jNxDOC9eVYliG6nS4JA8u8KAshITd07tafMc/Br7xQwCSseXwJ2iCcHCE8SNWX3q8Z+kw==

supports-color@6.1.0, supports-color@^6.0.0, supports-color@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-6.1.0.tgz#0764abc69c63d5ac842dd4867e8d025e880df8f3"
Expand Down Expand Up @@ -21714,12 +21759,6 @@ title-case@^2.1.0:
no-case "^2.2.0"
upper-case "^1.0.3"

tmp@^0.0.31:
version "0.0.31"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.31.tgz#8f38ab9438e17315e5dbd8b3657e8bfb277ae4a7"
dependencies:
os-tmpdir "~1.0.1"

tmp@^0.0.33:
version "0.0.33"
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
Expand Down