-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
74 additions
and
3 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
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
68 changes: 68 additions & 0 deletions
68
packages/docusaurus/src/webpack/utils/__tests__/getHttpsConfig.test.ts
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,68 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import path from 'path'; | ||
import getHttpsConfig from '../getHttpsConfig'; | ||
|
||
describe('getHttpsConfig', () => { | ||
const originalEnv = process.env; | ||
|
||
function getFixture(name: string) { | ||
return path.join(__dirname, '__fixtures__/getHttpsConfig', name); | ||
} | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
process.env = {...originalEnv}; | ||
}); | ||
|
||
afterAll(() => { | ||
process.env = originalEnv; | ||
}); | ||
|
||
it('returns true for HTTPS not env', async () => { | ||
await expect(getHttpsConfig()).resolves.toBe(false); | ||
}); | ||
|
||
it('returns true for HTTPS in env', async () => { | ||
process.env.HTTPS = 'true'; | ||
await expect(getHttpsConfig()).resolves.toBe(true); | ||
}); | ||
|
||
it('returns custom certs if they are in env', async () => { | ||
process.env.HTTPS = 'true'; | ||
process.env.SSL_CRT_FILE = getFixture('host.crt'); | ||
process.env.SSL_KEY_FILE = getFixture('host.key'); | ||
await expect(getHttpsConfig()).resolves.toEqual({ | ||
key: expect.any(Buffer), | ||
cert: expect.any(Buffer), | ||
}); | ||
}); | ||
|
||
it("throws if file doesn't exist", async () => { | ||
process.env.HTTPS = 'true'; | ||
process.env.SSL_CRT_FILE = getFixture('nonexistent.crt'); | ||
process.env.SSL_KEY_FILE = getFixture('host.key'); | ||
await expect(getHttpsConfig()).rejects.toThrowErrorMatchingInlineSnapshot( | ||
`"You specified SSL_CRT_FILE in your env, but the file "<PROJECT_ROOT>/packages/docusaurus/src/webpack/utils/__tests__/__fixtures__/getHttpsConfig/nonexistent.crt" can't be found."`, | ||
); | ||
}); | ||
|
||
it('throws for invalid key', async () => { | ||
process.env.HTTPS = 'true'; | ||
process.env.SSL_CRT_FILE = getFixture('host.crt'); | ||
process.env.SSL_KEY_FILE = getFixture('invalid.key'); | ||
await expect(getHttpsConfig()).rejects.toThrow(); | ||
}); | ||
|
||
it('throws for invalid cert', async () => { | ||
process.env.HTTPS = 'true'; | ||
process.env.SSL_CRT_FILE = getFixture('invalid.crt'); | ||
process.env.SSL_KEY_FILE = getFixture('host.key'); | ||
await expect(getHttpsConfig()).rejects.toThrow(); | ||
}); | ||
}); |
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