Skip to content

Commit

Permalink
Fix Ide not showing (#393)
Browse files Browse the repository at this point in the history
Signed-off-by: Max batleforc <[email protected]>
  • Loading branch information
batleforc authored Aug 5, 2024
1 parent afee599 commit 225a8c4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
4 changes: 2 additions & 2 deletions launcher/src/local-storage-key-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ export class LocalStorageKeyProvider {

async getPartOfPublicKey(file: string): Promise<string> {
let content = await fs.readFile(file);
content = content.substring(content.indexOf(' ') + 1);
content = content.split(' ')[1];

let secret = '';
for (let i = 0; i < 32; i++) {
secret += content.charAt(i * 4);
secret += content.charAt(i * 2);
}

return secret;
Expand Down
49 changes: 48 additions & 1 deletion launcher/tests/local-storage-key-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});

0 comments on commit 225a8c4

Please sign in to comment.