-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
createCA() is async and thus doesn't finish till *after* it returns. createCert() *needs* the CA file to exist before it runs. If both files are missing, this command died every time because `createCert()` would be called before the CA file was created. It would then kill the node process before *either* file was created. Now we use async/await to order them appropriately and we add a test to ensure the files get created.
- Loading branch information
1 parent
0f8e0ce
commit bec0e9e
Showing
4 changed files
with
48 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Test ssl command ssl:make creates some files in .localhost_ssl 1`] = ` | ||
Array [ | ||
"ca.crt", | ||
"ca.key", | ||
"cert.crt", | ||
"cert.key", | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* eslint-env jest */ | ||
const ssl = require('../commands/ssl'); | ||
const mock = require('mock-fs'); | ||
const fs = require('fs'); | ||
const os = require('os'); | ||
const path = require('path'); | ||
|
||
beforeAll(() => { | ||
jest.spyOn(console, 'log').mockImplementation(() => {}); | ||
}); | ||
|
||
describe('Test ssl command', () => { | ||
beforeEach(() => { | ||
// Start with an empty file system | ||
mock({}); | ||
}); | ||
afterEach(() => { | ||
mock.restore(); | ||
}); | ||
test('ssl:make creates some files in .localhost_ssl', (done) => { | ||
ssl({make: true}) | ||
.then(() => { | ||
assertSnapshot(path.join(os.homedir(), '.localhost_ssl')); | ||
}) | ||
.then(done); | ||
}); | ||
}); | ||
|
||
function assertSnapshot(dir) { | ||
const result = fs.readdirSync(dir); | ||
mock.restore(); | ||
expect(result).toMatchSnapshot(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
const {checkSSL, validate} = require('../../src/server/ssl'); | ||
|
||
module.exports = (args) => { | ||
module.exports = async (args) => { | ||
if (args.check) { | ||
validate(); | ||
} | ||
if (args.make) { | ||
checkSSL(); | ||
await checkSSL(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters