@openchamber/web 1.23.2 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CodeMirrorCommentWidgets-DdNGwbBw.js → CodeMirrorCommentWidgets-C9kV-n7r.js} +1 -1
- package/dist/assets/DiffView-B7YkbY-u.js +4 -0
- package/dist/assets/DirtyBranchSwitchDialog-CU0A93Zx.js +1 -0
- package/dist/assets/FilesView-vjJx7VaM.js +13 -0
- package/dist/assets/GitView-BLhlMYEY.js +6 -0
- package/dist/assets/GuestAttachDialog-B-fwE8r3.js +3 -0
- package/dist/assets/{JsonTreeView-Chzx5Y6N.js → JsonTreeView-D_4G5X6-.js} +1 -1
- package/dist/assets/LinearIssuesView-1uKhePfH.js +1 -0
- package/dist/assets/{MarkdownImageGallery-CugnrZ6f.js → MarkdownImageGallery-Ix7N_2wp.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-Deel_y5S.js +12 -0
- package/dist/assets/{OnboardingScreen-hH9xcTjA.js → OnboardingScreen-ToIakxb_.js} +1 -1
- package/dist/assets/{PatchDiff-DRgNYc9l.js → PatchDiff-BjMgezr1.js} +1 -1
- package/dist/assets/{PierreDiffViewer-ZT2CKuzJ.js → PierreDiffViewer-53Ghfnlr.js} +5 -5
- package/dist/assets/PlanView-BGAzxDwD.js +5 -0
- package/dist/assets/SettingsView-n2X-jfBB.js +29 -0
- package/dist/assets/SettingsWindow-Bi8LE9XI.js +1 -0
- package/dist/assets/SubmoduleDiffSummary--YFqK6Ih.js +1 -0
- package/dist/assets/ToolOutputDialog-DRWBvdaJ.js +15 -0
- package/dist/assets/{ToolPartDiffPreview-oWxWCu-4.js → ToolPartDiffPreview-BxZJCU28.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-CiyrAq_I.js → VirtualizedFileDiff-DCXjBGRf.js} +3 -3
- package/dist/assets/{WalkthroughView-CKTevaea.js → WalkthroughView-CfIPvWWa.js} +2 -2
- package/dist/assets/appThemeRegistry-DDROzcUO.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-SUWoTyPe.js → computeVirtualFileMetrics-DHgQIkUq.js} +1 -1
- package/dist/assets/de-CX_f-T5U.js +10 -0
- package/dist/assets/es-BERmWNn_.js +16 -0
- package/dist/assets/fr-BjYYE_-z.js +14 -0
- package/dist/assets/index-DpzTz2UH.css +1 -0
- package/dist/assets/index-Dy8xgawx.js +40 -0
- package/dist/assets/{index-C4jJ3Ur5.js → index-WjufPkIV.js} +1 -1
- package/dist/assets/{isDiffPlainText-DfG0cZxr.js → isDiffPlainText-D9faP70y.js} +1 -1
- package/dist/assets/{isFilePlainText-CyNivOCU.js → isFilePlainText-6qOcz5Ky.js} +1 -1
- package/dist/assets/ja-DxqeAk9N.js +16 -0
- package/dist/assets/ko-Dty1aUod.js +16 -0
- package/dist/assets/main-BOYSXfYn.js +896 -0
- package/dist/assets/{main-B8cGozKr.js → main-Bjcre_GE.js} +2 -2
- package/dist/assets/{markdown-shiki.worker-D5fBU-lw.js → markdown-shiki.worker-CahLvHIq.js} +5 -5
- package/dist/assets/{markdownCore-kyGrWGsn.js → markdownCore-DPrwM1rU.js} +5 -5
- package/dist/assets/{miniChat-Cay99IxR.js → miniChat-Dz_bPgMc.js} +2 -2
- package/dist/assets/{mobile-Zfhix7nz.js → mobile-BbZPBJrK.js} +2 -2
- package/dist/assets/{patchFileDiff-CJ5AN9Ql.js → patchFileDiff-BvU6KOQC.js} +3 -3
- package/dist/assets/pl-CX-_ROkr.js +16 -0
- package/dist/assets/{pt-BR-CLosVawq.js → pt-BR-DhRR1arx.js} +4 -4
- package/dist/assets/renderElectronMiniChatApp-uNEUkeAI.js +2 -0
- package/dist/assets/renderMobileApp-BK1kFlcJ.js +25 -0
- package/dist/assets/runtimeEndpointReset-BULHvOwb.js +25 -0
- package/dist/assets/{scheduledTasksApi-CGFV4Pap.js → scheduledTasksApi-DW3xqMQ8.js} +1 -1
- package/dist/assets/shikiHighlight-DsxD9QEa.js +1 -0
- package/dist/assets/textMateThemeFromAppTheme-Da7ed8qM.js +1 -0
- package/dist/assets/tr-cIQtYBpg.js +7 -0
- package/dist/assets/uk-CD21CXFV.js +16 -0
- package/dist/assets/{useAppFontEffects-DgCHy6Mr.js → useAppFontEffects-hfv2s6mZ.js} +198 -147
- package/dist/assets/useInlineCommentController-BmtfVbo8.js +2 -0
- package/dist/assets/useRootScrollLock-Cwc4kSl2.js +1 -0
- package/dist/assets/{vendor-base-ui-BY_5qla_.js → vendor-base-ui-CsXYnR5c.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-ES33GhKK.js → vendor-codemirror-language-data-BPMJpOpT.js} +2 -2
- package/dist/assets/vendor-framer-motion-Bq3iTZ6r.js +1 -0
- package/dist/assets/{vendor-motion-dom-D_o3BTI3.js → vendor-motion-dom-DcCgeG69.js} +1 -1
- package/dist/assets/vendor-strip-json-comments-5dJlOkP1.js +4 -0
- package/dist/assets/{vendor-zod-B6551dwG.js → vendor-zod-fZppILAM.js} +4 -4
- package/dist/assets/{web-components-CJZwV5BE.js → web-components-U-hWbgJo.js} +2 -2
- package/dist/assets/zh-CN-BWvlPHY-.js +16 -0
- package/dist/assets/zh-TW-CRp5dJU2.js +16 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +7 -5
- package/server/built-in-extensions/registry.json +4 -0
- package/server/index.d.ts +2 -0
- package/server/index.js +15 -3
- package/server/lib/fs/DOCUMENTATION.md +8 -0
- package/server/lib/fs/git-process.test.js +77 -0
- package/server/lib/fs/routes.js +2 -1
- package/server/lib/fs/search.js +2 -1
- package/server/lib/git/DOCUMENTATION.md +3 -1
- package/server/lib/git/routes.js +16 -3
- package/server/lib/git/service.js +112 -8
- package/server/lib/git/service.test.js +127 -0
- package/server/lib/guests/DOCUMENTATION.md +66 -0
- package/server/lib/guests/auth-store.js +184 -0
- package/server/lib/guests/auth-store.test.js +112 -0
- package/server/lib/guests/builtins.js +34 -0
- package/server/lib/guests/builtins.test.js +174 -0
- package/server/lib/guests/catalog.js +466 -0
- package/server/lib/guests/catalog.test.js +390 -0
- package/server/lib/guests/clone.js +297 -0
- package/server/lib/guests/extract-zip.js +136 -0
- package/server/lib/guests/extract-zip.test.js +109 -0
- package/server/lib/guests/files.js +308 -0
- package/server/lib/guests/files.test.js +262 -0
- package/server/lib/guests/grant-scope.js +81 -0
- package/server/lib/guests/grant-scope.test.js +75 -0
- package/server/lib/guests/host-session.js +73 -0
- package/server/lib/guests/host-session.test.js +30 -0
- package/server/lib/guests/html-styles.js +6 -0
- package/server/lib/guests/html-styles.test.js +45 -0
- package/server/lib/guests/html-tokens.js +73 -0
- package/server/lib/guests/html-tokens.test.js +53 -0
- package/server/lib/guests/install.js +406 -0
- package/server/lib/guests/install.test.js +338 -0
- package/server/lib/guests/oauth.js +501 -0
- package/server/lib/guests/oauth.test.js +481 -0
- package/server/lib/guests/persist.js +336 -0
- package/server/lib/guests/persist.test.js +288 -0
- package/server/lib/guests/request.js +112 -0
- package/server/lib/guests/request.test.js +206 -0
- package/server/lib/guests/routes.js +838 -0
- package/server/lib/guests/service.js +538 -0
- package/server/lib/guests/service.test.js +277 -0
- package/server/lib/guests/sockets.js +129 -0
- package/server/lib/guests/sockets.test.js +110 -0
- package/server/lib/guests/ssh-install.test.js +188 -0
- package/server/lib/guests/storage.js +68 -0
- package/server/lib/guests/storage.test.js +59 -0
- package/server/lib/guests/updates.js +294 -0
- package/server/lib/guests/updates.test.js +334 -0
- package/server/lib/guests/upload.js +50 -0
- package/server/lib/guests/upload.test.js +131 -0
- package/server/lib/linear/DOCUMENTATION.md +1 -1
- package/server/lib/openchamber-control/DOCUMENTATION.md +6 -0
- package/server/lib/openchamber-sessions/routes.js +44 -11
- package/server/lib/openchamber-sessions/routes.test.js +47 -0
- package/server/lib/opencode/DOCUMENTATION.md +40 -0
- package/server/lib/opencode/core-routes.js +39 -1
- package/server/lib/opencode/feature-routes-runtime.js +10 -0
- package/server/lib/opencode/lifecycle-process.test.js +84 -0
- package/server/lib/opencode/lifecycle.js +54 -67
- package/server/lib/opencode/settings-normalization-runtime.js +2 -0
- package/server/lib/opencode/settings-normalization-runtime.test.js +13 -0
- package/server/lib/opencode/settings-registry.json +4 -0
- package/server/lib/opencode/shutdown-runtime.js +3 -0
- package/server/lib/opencode/shutdown-runtime.test.js +24 -0
- package/server/lib/opencode/theme-archive.js +53 -0
- package/server/lib/opencode/theme-catalog.js +171 -0
- package/server/lib/opencode/theme-catalog.test.js +125 -0
- package/server/lib/opencode/theme-import.test.js +144 -0
- package/server/lib/opencode/theme-runtime.js +100 -28
- package/server/lib/opencode/theme-runtime.test.js +15 -0
- package/server/lib/quota/DOCUMENTATION.md +0 -1
- package/server/lib/quota/providers/index.js +0 -7
- package/server/lib/terminal/DOCUMENTATION.md +2 -0
- package/server/lib/terminal/runtime.js +17 -2
- package/server/lib/terminal/runtime.test.js +45 -0
- package/server/lib/ui-auth/ui-auth.js +43 -8
- package/server/lib/ui-auth/ui-auth.test.js +40 -0
- package/dist/assets/DiffView-GYriC0Wk.js +0 -4
- package/dist/assets/DirtyBranchSwitchDialog-Bv0C99hc.js +0 -1
- package/dist/assets/FilesView-2Lin13wx.js +0 -13
- package/dist/assets/GitView-9wKba3UO.js +0 -6
- package/dist/assets/LinearIssuesView-DXS9QJiR.js +0 -1
- package/dist/assets/MarkdownRendererImpl-CaMyct2Q.js +0 -12
- package/dist/assets/PlanView-DiTBm2BD.js +0 -5
- package/dist/assets/SettingsView-CN8VeM99.js +0 -28
- package/dist/assets/SettingsWindow-DisOghhD.js +0 -1
- package/dist/assets/ToolOutputDialog-BqiKydxR.js +0 -15
- package/dist/assets/appThemeRegistry-BK0dHKa6.js +0 -1
- package/dist/assets/de-DQWC94VK.js +0 -10
- package/dist/assets/es-DixFUD3m.js +0 -16
- package/dist/assets/fr-D6u8tvfA.js +0 -14
- package/dist/assets/index-BvpFzhLs.js +0 -40
- package/dist/assets/index-n5p3SnES.css +0 -1
- package/dist/assets/ja-4u4pCorB.js +0 -16
- package/dist/assets/ko-C27-LW_b.js +0 -16
- package/dist/assets/main-tEA-fFPg.js +0 -930
- package/dist/assets/pl-FtCjsNdW.js +0 -16
- package/dist/assets/registerCustomTheme-BBXUCRnG.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-CuHOGlF4.js +0 -2
- package/dist/assets/renderMobileApp-C4X_KUH8.js +0 -25
- package/dist/assets/runtimeEndpointReset-CMg-KUx3.js +0 -41
- package/dist/assets/shikiHighlight-DdKWYWrV.js +0 -1
- package/dist/assets/tr-D2j6wUez.js +0 -7
- package/dist/assets/uk-C6IzmwM_.js +0 -16
- package/dist/assets/useGitComparison-BIaI0WZI.js +0 -1
- package/dist/assets/useInlineCommentController-2wcCtpM3.js +0 -2
- package/dist/assets/useRootScrollLock-CbWA03xR.js +0 -1
- package/dist/assets/vendor-framer-motion-livSKyyV.js +0 -1
- package/dist/assets/zh-CN-Wl6tIDz1.js +0 -16
- package/dist/assets/zh-TW-hgphoWSN.js +0 -16
- package/server/lib/quota/providers/crof.js +0 -96
- package/server/lib/quota/providers/crof.test.js +0 -98
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
|
|
6
|
+
import { spawnSync } from 'node:child_process';
|
|
7
|
+
|
|
8
|
+
import { listInstalledGuests } from './catalog.js';
|
|
9
|
+
import { buildStoreZip } from './extract-zip.test.js';
|
|
10
|
+
import { gitNetworkArgs } from './clone.js';
|
|
11
|
+
import {
|
|
12
|
+
downloadZip,
|
|
13
|
+
installGuestFromGitSource,
|
|
14
|
+
installGuestFromPath,
|
|
15
|
+
installGuestFromUrl,
|
|
16
|
+
parseInstallRequest,
|
|
17
|
+
uninstallGuest,
|
|
18
|
+
} from './install.js';
|
|
19
|
+
import { guestCopiesDir } from './persist.js';
|
|
20
|
+
|
|
21
|
+
const writeGuest = async (root, id) => {
|
|
22
|
+
await fs.mkdir(path.join(root, 'panel'), { recursive: true });
|
|
23
|
+
await fs.writeFile(path.join(root, 'panel', 'index.html'), '<html></html>');
|
|
24
|
+
await fs.writeFile(path.join(root, 'package.json'), JSON.stringify({
|
|
25
|
+
name: `@openchamber/${id}`,
|
|
26
|
+
version: '1.0.0',
|
|
27
|
+
openchamber: {
|
|
28
|
+
apiVersion: 1,
|
|
29
|
+
contributes: {
|
|
30
|
+
panel: { id, name: id, icon: 'window', entry: 'panel/index.html' },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
describe('installGuestFromPath', () => {
|
|
37
|
+
test('installs a folder extension and refuses a second copy', async () => {
|
|
38
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'oc-ext-'));
|
|
39
|
+
const persistPath = path.join(dir, 'extensions.json');
|
|
40
|
+
const guestRoot = path.join(dir, 'clone');
|
|
41
|
+
await writeGuest(guestRoot, 'clone-hello');
|
|
42
|
+
|
|
43
|
+
expect(parseInstallRequest({ path: guestRoot })).toEqual({ path: guestRoot });
|
|
44
|
+
expect(parseInstallRequest({ url: 'https://github.com/acme/panel.git' })).toEqual({
|
|
45
|
+
url: 'https://github.com/acme/panel.git',
|
|
46
|
+
});
|
|
47
|
+
expect(parseInstallRequest({ path: guestRoot, replace: true })).toEqual({
|
|
48
|
+
path: guestRoot,
|
|
49
|
+
replace: true,
|
|
50
|
+
});
|
|
51
|
+
expect(parseInstallRequest({})).toBeNull();
|
|
52
|
+
expect(parseInstallRequest({ path: guestRoot, url: 'https://github.com/acme/panel.git' })).toBeNull();
|
|
53
|
+
|
|
54
|
+
const installed = await installGuestFromPath(guestRoot, persistPath);
|
|
55
|
+
expect(installed.ok).toBe(true);
|
|
56
|
+
if (!installed.ok) {
|
|
57
|
+
throw new Error('expected install');
|
|
58
|
+
}
|
|
59
|
+
expect(installed.guest.id).toBe('clone-hello');
|
|
60
|
+
expect(installed.guest.source).toBe('path');
|
|
61
|
+
|
|
62
|
+
const listed = await listInstalledGuests({ persistPath });
|
|
63
|
+
expect(listed.some((guest) => guest.id === 'clone-hello')).toBe(true);
|
|
64
|
+
|
|
65
|
+
const again = await installGuestFromPath(guestRoot, persistPath);
|
|
66
|
+
expect(again).toEqual({ ok: false, code: 'already-installed', id: 'clone-hello' });
|
|
67
|
+
|
|
68
|
+
const replacedSame = await installGuestFromPath(guestRoot, persistPath, { replace: true });
|
|
69
|
+
expect(replacedSame.ok).toBe(true);
|
|
70
|
+
if (!replacedSame.ok) {
|
|
71
|
+
throw new Error('expected replace');
|
|
72
|
+
}
|
|
73
|
+
expect(replacedSame.replaced).toBe(true);
|
|
74
|
+
|
|
75
|
+
const otherRoot = path.join(dir, 'other');
|
|
76
|
+
await writeGuest(otherRoot, 'clone-hello');
|
|
77
|
+
const taken = await installGuestFromPath(otherRoot, persistPath);
|
|
78
|
+
expect(taken).toEqual({ ok: false, code: 'id-taken', id: 'clone-hello' });
|
|
79
|
+
|
|
80
|
+
const replacedOther = await installGuestFromPath(otherRoot, persistPath, { replace: true });
|
|
81
|
+
expect(replacedOther.ok).toBe(true);
|
|
82
|
+
if (!replacedOther.ok) {
|
|
83
|
+
throw new Error('expected replace other');
|
|
84
|
+
}
|
|
85
|
+
expect(replacedOther.replaced).toBe(true);
|
|
86
|
+
expect(replacedOther.guest.path).toBe(await fs.realpath(otherRoot));
|
|
87
|
+
|
|
88
|
+
const relative = await installGuestFromPath('clone', persistPath);
|
|
89
|
+
expect(relative).toEqual({ ok: false, code: 'invalid-path' });
|
|
90
|
+
|
|
91
|
+
const badIdRoot = path.join(dir, 'bad-id');
|
|
92
|
+
await writeGuest(badIdRoot, 'Not Kebab');
|
|
93
|
+
const badId = await installGuestFromPath(badIdRoot, persistPath);
|
|
94
|
+
expect(badId).toEqual({ ok: false, code: 'invalid-manifest' });
|
|
95
|
+
|
|
96
|
+
const removed = await uninstallGuest('clone-hello', persistPath);
|
|
97
|
+
expect(removed).toEqual({ ok: true });
|
|
98
|
+
const after = await listInstalledGuests({ persistPath });
|
|
99
|
+
expect(after.some((guest) => guest.id === 'clone-hello')).toBe(false);
|
|
100
|
+
|
|
101
|
+
const missing = await uninstallGuest('hello', persistPath);
|
|
102
|
+
expect(missing).toEqual({ ok: false, code: 'not-found' });
|
|
103
|
+
|
|
104
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('refuses a panel that has TypeScript but no built script', async () => {
|
|
108
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'oc-ext-'));
|
|
109
|
+
const persistPath = path.join(dir, 'extensions.json');
|
|
110
|
+
const guestRoot = path.join(dir, 'source-only');
|
|
111
|
+
await fs.mkdir(path.join(guestRoot, 'panel'), { recursive: true });
|
|
112
|
+
await fs.writeFile(path.join(guestRoot, 'panel', 'index.html'), '<script src="./main.js"></script>');
|
|
113
|
+
await fs.writeFile(path.join(guestRoot, 'panel', 'main.ts'), 'console.log(1)');
|
|
114
|
+
await fs.writeFile(path.join(guestRoot, 'package.json'), JSON.stringify({
|
|
115
|
+
name: '@openchamber/source-only',
|
|
116
|
+
version: '1.0.0',
|
|
117
|
+
openchamber: {
|
|
118
|
+
apiVersion: 1,
|
|
119
|
+
contributes: {
|
|
120
|
+
panel: { id: 'source-only', name: 'Source', icon: 'window', entry: 'panel/index.html' },
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
}));
|
|
124
|
+
const missing = await installGuestFromPath(guestRoot, persistPath);
|
|
125
|
+
expect(missing).toEqual({ ok: false, code: 'missing-build' });
|
|
126
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('refuses engines.openchamber newer than the host', async () => {
|
|
130
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'oc-ext-'));
|
|
131
|
+
const persistPath = path.join(dir, 'extensions.json');
|
|
132
|
+
const guestRoot = path.join(dir, 'future');
|
|
133
|
+
await fs.mkdir(path.join(guestRoot, 'panel'), { recursive: true });
|
|
134
|
+
await fs.writeFile(path.join(guestRoot, 'panel', 'index.html'), '<html></html>');
|
|
135
|
+
await fs.writeFile(path.join(guestRoot, 'package.json'), JSON.stringify({
|
|
136
|
+
name: '@openchamber/future',
|
|
137
|
+
version: '1.0.0',
|
|
138
|
+
openchamber: {
|
|
139
|
+
apiVersion: 1,
|
|
140
|
+
engines: { openchamber: '>=9.9.9' },
|
|
141
|
+
contributes: {
|
|
142
|
+
panel: { id: 'future', name: 'Future', icon: 'window', entry: 'panel/index.html' },
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
}));
|
|
146
|
+
|
|
147
|
+
const refused = await installGuestFromPath(guestRoot, persistPath, { openchamberVersion: '1.22.0' });
|
|
148
|
+
expect(refused).toEqual({ ok: false, code: 'host-too-old', required: '9.9.9' });
|
|
149
|
+
|
|
150
|
+
const allowed = await installGuestFromPath(guestRoot, persistPath, { openchamberVersion: '9.9.9' });
|
|
151
|
+
expect(allowed.ok).toBe(true);
|
|
152
|
+
|
|
153
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('keeps two instance catalogs apart', async () => {
|
|
157
|
+
const parent = await fs.mkdtemp(path.join(os.tmpdir(), 'oc-ext-'));
|
|
158
|
+
const persistA = path.join(parent, 'a', 'extensions.json');
|
|
159
|
+
const persistB = path.join(parent, 'b', 'extensions.json');
|
|
160
|
+
const guestRoot = path.join(parent, 'clone');
|
|
161
|
+
await writeGuest(guestRoot, 'clone-hello');
|
|
162
|
+
|
|
163
|
+
const installed = await installGuestFromPath(guestRoot, persistA);
|
|
164
|
+
expect(installed.ok).toBe(true);
|
|
165
|
+
expect(await listInstalledGuests({ persistPath: persistB })).toEqual([]);
|
|
166
|
+
expect((await listInstalledGuests({ persistPath: persistA })).some((guest) => guest.id === 'clone-hello')).toBe(true);
|
|
167
|
+
|
|
168
|
+
await fs.rm(parent, { recursive: true, force: true });
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test('installs a zip and deletes the copy on uninstall', async () => {
|
|
172
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'oc-ext-'));
|
|
173
|
+
const persistPath = path.join(dir, 'extensions.json');
|
|
174
|
+
const zipPath = path.join(dir, 'panel.zip');
|
|
175
|
+
await fs.writeFile(zipPath, buildStoreZip([
|
|
176
|
+
{ name: 'package.json', data: JSON.stringify({
|
|
177
|
+
name: '@openchamber/zip-hello',
|
|
178
|
+
version: '1.0.0',
|
|
179
|
+
openchamber: {
|
|
180
|
+
apiVersion: 1,
|
|
181
|
+
contributes: {
|
|
182
|
+
panel: { id: 'zip-hello', name: 'Zip', icon: 'window', entry: 'panel/index.html' },
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
}) },
|
|
186
|
+
{ name: 'panel/index.html', data: '<html></html>' },
|
|
187
|
+
]));
|
|
188
|
+
|
|
189
|
+
const installed = await installGuestFromPath(zipPath, persistPath);
|
|
190
|
+
expect(installed.ok).toBe(true);
|
|
191
|
+
if (!installed.ok) {
|
|
192
|
+
throw new Error('expected zip install');
|
|
193
|
+
}
|
|
194
|
+
expect(installed.guest.id).toBe('zip-hello');
|
|
195
|
+
expect(installed.guest.source).toBe('zip');
|
|
196
|
+
const copy = path.join(guestCopiesDir(persistPath), 'zip-hello');
|
|
197
|
+
expect(await fs.stat(copy).then((stat) => stat.isDirectory())).toBe(true);
|
|
198
|
+
|
|
199
|
+
const removed = await uninstallGuest('zip-hello', persistPath);
|
|
200
|
+
expect(removed).toEqual({ ok: true });
|
|
201
|
+
expect(await fs.stat(copy).then(() => true).catch(() => false)).toBe(false);
|
|
202
|
+
expect(await fs.stat(zipPath).then((stat) => stat.isFile())).toBe(true);
|
|
203
|
+
|
|
204
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
describe('installGuestFromUrl', () => {
|
|
209
|
+
test('refuses a non-https url', async () => {
|
|
210
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'oc-ext-'));
|
|
211
|
+
const persistPath = path.join(dir, 'extensions.json');
|
|
212
|
+
expect(await installGuestFromUrl('http://example.com/panel.git', persistPath)).toEqual({
|
|
213
|
+
ok: false,
|
|
214
|
+
code: 'invalid-url',
|
|
215
|
+
});
|
|
216
|
+
for (const privateUrl of [
|
|
217
|
+
'https://127.0.0.1/panel.git',
|
|
218
|
+
'https://localhost/panel.zip',
|
|
219
|
+
'https://10.0.0.5/panel.git',
|
|
220
|
+
'https://192.168.1.2/panel.zip',
|
|
221
|
+
'https://[::1]/panel.git',
|
|
222
|
+
'https://user:pass@example.com/panel.git',
|
|
223
|
+
]) {
|
|
224
|
+
expect(await installGuestFromUrl(privateUrl, persistPath)).toEqual({ ok: false, code: 'invalid-url' });
|
|
225
|
+
}
|
|
226
|
+
expect(await installGuestFromUrl('ftp://example.com/panel.git', persistPath)).toEqual({
|
|
227
|
+
ok: false,
|
|
228
|
+
code: 'invalid-url',
|
|
229
|
+
});
|
|
230
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe('installGuestFromGitSource', () => {
|
|
235
|
+
test('clones a local repo and deletes the copy on uninstall', async () => {
|
|
236
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'oc-ext-'));
|
|
237
|
+
const persistPath = path.join(dir, 'extensions.json');
|
|
238
|
+
const repo = path.join(dir, 'repo');
|
|
239
|
+
await writeGuest(repo, 'git-hello');
|
|
240
|
+
const git = (args) => {
|
|
241
|
+
const result = spawnSync('git', args, {
|
|
242
|
+
cwd: repo,
|
|
243
|
+
encoding: 'utf8',
|
|
244
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
|
|
245
|
+
});
|
|
246
|
+
if (result.status !== 0) {
|
|
247
|
+
throw new Error(result.stderr || 'git failed');
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
git(['init', '--template=']);
|
|
251
|
+
git(['add', '.']);
|
|
252
|
+
git(['-c', 'user.name=test', '-c', 'user.email=test@example.com', 'commit', '-m', 'init']);
|
|
253
|
+
|
|
254
|
+
const installed = await installGuestFromGitSource(repo, persistPath);
|
|
255
|
+
expect(installed.ok).toBe(true);
|
|
256
|
+
if (!installed.ok) {
|
|
257
|
+
throw new Error('expected git install');
|
|
258
|
+
}
|
|
259
|
+
expect(installed.guest.id).toBe('git-hello');
|
|
260
|
+
expect(installed.guest.source).toBe('git');
|
|
261
|
+
const copy = path.join(guestCopiesDir(persistPath), 'git-hello');
|
|
262
|
+
expect(await fs.stat(copy).then((stat) => stat.isDirectory())).toBe(true);
|
|
263
|
+
expect(await fs.stat(path.join(repo, 'package.json')).then((stat) => stat.isFile())).toBe(true);
|
|
264
|
+
|
|
265
|
+
const removed = await uninstallGuest('git-hello', persistPath);
|
|
266
|
+
expect(removed).toEqual({ ok: true });
|
|
267
|
+
expect(await fs.stat(copy).then(() => true).catch(() => false)).toBe(false);
|
|
268
|
+
expect(await fs.stat(path.join(repo, 'package.json')).then((stat) => stat.isFile())).toBe(true);
|
|
269
|
+
|
|
270
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
describe('downloadZip', () => {
|
|
275
|
+
const publicLookup = async () => [{ address: '93.184.216.34' }];
|
|
276
|
+
|
|
277
|
+
test('follows a public redirect by hand, pinned to the checked address, and returns the bytes', async () => {
|
|
278
|
+
const seen = [];
|
|
279
|
+
const request = async (url, target) => {
|
|
280
|
+
seen.push({ url, address: target.address });
|
|
281
|
+
if (url === 'https://example.com/panel.zip') {
|
|
282
|
+
return { status: 302, location: 'https://cdn.example.com/signed/abc', body: null };
|
|
283
|
+
}
|
|
284
|
+
return { status: 200, location: null, body: Buffer.from([1, 2, 3]) };
|
|
285
|
+
};
|
|
286
|
+
const bytes = await downloadZip('https://example.com/panel.zip', { request, lookup: publicLookup });
|
|
287
|
+
expect(bytes && [...bytes]).toEqual([1, 2, 3]);
|
|
288
|
+
expect(seen).toEqual([
|
|
289
|
+
{ url: 'https://example.com/panel.zip', address: '93.184.216.34' },
|
|
290
|
+
{ url: 'https://cdn.example.com/signed/abc', address: '93.184.216.34' },
|
|
291
|
+
]);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test('refuses a redirect to a private or non-https address before requesting it', async () => {
|
|
295
|
+
for (const location of ['http://127.0.0.1:8080/panel.zip', 'https://localhost/panel.zip', 'https://10.0.0.5/x.zip', 'http://example.com/panel.zip']) {
|
|
296
|
+
const requested = [];
|
|
297
|
+
const request = async (url) => {
|
|
298
|
+
requested.push(url);
|
|
299
|
+
return { status: 302, location, body: null };
|
|
300
|
+
};
|
|
301
|
+
expect(await downloadZip('https://example.com/panel.zip', { request, lookup: publicLookup })).toBeNull();
|
|
302
|
+
expect(requested).toEqual(['https://example.com/panel.zip']);
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test('refuses a public name that resolves to a private address', async () => {
|
|
307
|
+
let requested = 0;
|
|
308
|
+
const request = async () => {
|
|
309
|
+
requested += 1;
|
|
310
|
+
return { status: 200, location: null, body: Buffer.from([1]) };
|
|
311
|
+
};
|
|
312
|
+
const lookup = async () => [{ address: '93.184.216.34' }, { address: '10.1.1.1' }];
|
|
313
|
+
expect(await downloadZip('https://example.com/panel.zip', { request, lookup })).toBeNull();
|
|
314
|
+
expect(requested).toBe(0);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
test('gives up after too many redirects', async () => {
|
|
318
|
+
let hops = 0;
|
|
319
|
+
const request = async (url) => {
|
|
320
|
+
hops += 1;
|
|
321
|
+
return { status: 302, location: `${url}0`, body: null };
|
|
322
|
+
};
|
|
323
|
+
expect(await downloadZip('https://example.com/panel.zip', { request, lookup: publicLookup })).toBeNull();
|
|
324
|
+
expect(hops).toBeLessThanOrEqual(6);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
describe('gitNetworkArgs', () => {
|
|
329
|
+
test('pins a public https host to its resolved addresses and forbids redirects', async () => {
|
|
330
|
+
const lookup = async () => [{ address: '93.184.216.34' }, { address: '2606:2800:220:1:248:1893:25c8:1946' }];
|
|
331
|
+
expect(await gitNetworkArgs('https://example.com/org/panel.git', lookup)).toEqual([
|
|
332
|
+
'-c', 'http.followRedirects=false',
|
|
333
|
+
'-c', 'http.curloptResolve=example.com:443:93.184.216.34,2606:2800:220:1:248:1893:25c8:1946',
|
|
334
|
+
]);
|
|
335
|
+
expect(await gitNetworkArgs('https://example.com/org/panel.git', async () => [{ address: '127.0.0.1' }])).toBeNull();
|
|
336
|
+
expect(await gitNetworkArgs('/tmp/local/repo')).toEqual([]);
|
|
337
|
+
});
|
|
338
|
+
});
|