| ... | @@ -36,6 +36,41 @@ describe("ElectronShell", () => { | ... | @@ -36,6 +36,41 @@ describe("ElectronShell", () => { |
| 36 | }).pipe(Effect.provide(ElectronShell.layer)), | 36 | }).pipe(Effect.provide(ElectronShell.layer)), |
| 37 | ); | 37 | ); |
| 38 | | 38 | |
| | 39 | it.effect("opens remote SSH editor URLs", () => |
| | 40 | Effect.gen(function* () { |
| | 41 | openExternalMock.mockResolvedValue(undefined); |
| | 42 | |
| | 43 | const electronShell = yield* ElectronShell.ElectronShell; |
| | 44 | const result = yield* electronShell.openExternal( |
| | 45 | "vscode://vscode-remote/ssh-remote+example.com/home/user/project", |
| | 46 | ); |
| | 47 | |
| | 48 | assert.equal(result, true); |
| | 49 | assert.deepEqual(openExternalMock.mock.calls, [ |
| | 50 | ["vscode://vscode-remote/ssh-remote+example.com/home/user/project"], |
| | 51 | ]); |
| | 52 | }).pipe(Effect.provide(ElectronShell.layer)), |
| | 53 | ); |
| | 54 | |
| | 55 | it.effect("does not open remote editor URLs with userinfo", () => |
| | 56 | Effect.gen(function* () { |
| | 57 | openExternalMock.mockResolvedValue(undefined); |
| | 58 | |
| | 59 | const electronShell = yield* ElectronShell.ElectronShell; |
| | 60 | const results = yield* Effect.all([ |
| | 61 | electronShell.openExternal( |
| | 62 | "vscode://user@vscode-remote/ssh-remote+example.com/home/user/project", |
| | 63 | ), |
| | 64 | electronShell.openExternal( |
| | 65 | "vscode://:secret@vscode-remote/ssh-remote+example.com/home/user/project", |
| | 66 | ), |
| | 67 | ]); |
| | 68 | |
| | 69 | assert.deepEqual(results, [false, false]); |
| | 70 | assert.equal(openExternalMock.mock.calls.length, 0); |
| | 71 | }).pipe(Effect.provide(ElectronShell.layer)), |
| | 72 | ); |
| | 73 | |
| 39 | it.effect("does not open unsafe external URLs", () => | 74 | it.effect("does not open unsafe external URLs", () => |
| 40 | Effect.gen(function* () { | 75 | Effect.gen(function* () { |
| 41 | const electronShell = yield* ElectronShell.ElectronShell; | 76 | const electronShell = yield* ElectronShell.ElectronShell; |
| ... | @@ -46,6 +81,20 @@ describe("ElectronShell", () => { | ... | @@ -46,6 +81,20 @@ describe("ElectronShell", () => { |
| 46 | }).pipe(Effect.provide(ElectronShell.layer)), | 81 | }).pipe(Effect.provide(ElectronShell.layer)), |
| 47 | ); | 82 | ); |
| 48 | | 83 | |
| | 84 | it.effect("does not open non-remote editor URLs", () => |
| | 85 | Effect.gen(function* () { |
| | 86 | openExternalMock.mockResolvedValue(undefined); |
| | 87 | |
| | 88 | const electronShell = yield* ElectronShell.ElectronShell; |
| | 89 | const result = yield* electronShell.openExternal( |
| | 90 | "vscode://ms-python.python/some-command?argument=attacker", |
| | 91 | ); |
| | 92 | |
| | 93 | assert.equal(result, false); |
| | 94 | assert.equal(openExternalMock.mock.calls.length, 0); |
| | 95 | }).pipe(Effect.provide(ElectronShell.layer)), |
| | 96 | ); |
| | 97 | |
| 49 | it.effect("returns false when Electron rejects openExternal", () => | 98 | it.effect("returns false when Electron rejects openExternal", () => |
| 50 | Effect.gen(function* () { | 99 | Effect.gen(function* () { |
| 51 | openExternalMock.mockRejectedValue(new Error("open failed")); | 100 | openExternalMock.mockRejectedValue(new Error("open failed")); |