-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Max batleforc <[email protected]>
- Loading branch information
Showing
2 changed files
with
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,11 @@ some code, some code, a mask to be replaced {{LOCAL-STORAGE}}/{{SECURE-KEY}}, so | |
`; | ||
|
||
const NEW_WORKBENCH_FILE = ` | ||
some code, some code, a mask to be replaced 1234567890ABCDEFGHIJKLMNOPQRSTUV, some code | ||
some code, some code, a mask to be replaced 11223344556677889900AABBCCDDEEFF, some code | ||
`; | ||
|
||
const NEW_WORKBENCH_FILE_NEW_LINE = ` | ||
some code, some code, a mask to be replaced AACNa1ZINEAAIblpQoqFHrJPOyAt2gX1, some code | ||
`; | ||
|
||
describe('Test setting of Local Storage public key to VS Code', () => { | ||
|
@@ -70,4 +74,47 @@ describe('Test setting of Local Storage public key to VS Code', () => { | |
|
||
expect(writeFileMock).toBeCalledWith('out/vs/code/browser/workbench/workbench.js', NEW_WORKBENCH_FILE); | ||
}); | ||
|
||
test('should work with a public key including new lines', async () => { | ||
const pathExistsMock = jest.fn(); | ||
const readdirMock = jest.fn(); | ||
const isFileMock = jest.fn(); | ||
const readFileMock = jest.fn(); | ||
const writeFileMock = jest.fn(); | ||
Object.assign(fs, { | ||
pathExists: pathExistsMock, | ||
readdir: readdirMock, | ||
isFile: isFileMock, | ||
readFile: readFileMock, | ||
writeFile: writeFileMock, | ||
}); | ||
|
||
pathExistsMock.mockImplementation(async (path: string) => { | ||
return '/etc/ssh' === path || '/etc/ssh/first-key.pub' === path; | ||
}); | ||
|
||
readdirMock.mockImplementation(async (path: string) => { | ||
return ['some-file', 'first-key', 'second-key', 'first-key.pub', 'second-key.pub']; | ||
}); | ||
|
||
isFileMock.mockImplementation(async (path: string) => { | ||
return '/etc/ssh/first-key' === path || '/etc/ssh/first-key.pub' === path; | ||
}); | ||
|
||
readFileMock.mockImplementation(async (file: string) => { | ||
switch (file) { | ||
case '/etc/ssh/first-key.pub': | ||
// This key has new lines, and was randomly generated for this test | ||
return `ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIObHl2pRQsoCqvF7HrrUJwPcOByIAOtS2ggoX51xMWAQ [email protected] | ||
`; | ||
case 'out/vs/code/browser/workbench/workbench.js': | ||
return ORIGIN_WORKBENCH_FILE; | ||
} | ||
}); | ||
|
||
const localStorageKeyProvider = new LocalStorageKeyProvider(); | ||
await localStorageKeyProvider.configure(); | ||
|
||
expect(writeFileMock).toBeCalledWith('out/vs/code/browser/workbench/workbench.js', NEW_WORKBENCH_FILE_NEW_LINE); | ||
}); | ||
}); |