@myrialabs/clopen 0.4.46 → 0.4.48
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/README.md +11 -11
- package/backend/artifacts/project/sources.ts +1 -1
- package/backend/auth/auth-service.ts +52 -358
- package/backend/auth/onboarding.test.ts +2 -3
- package/backend/auth/permissions.test.ts +10 -20
- package/backend/auth/permissions.ts +4 -290
- package/backend/auth/rate-limiter.test.ts +8 -9
- package/backend/auth/rate-limiter.ts +0 -2
- package/backend/auth/tokens.ts +1 -8
- package/backend/bootstrap.ts +7 -0
- package/backend/chat/attachments.test.ts +88 -0
- package/backend/chat/attachments.ts +159 -0
- package/backend/chat/engine-handoff.test.ts +0 -2
- package/backend/chat/stream-manager.ts +62 -62
- package/backend/chat/turn-answer.test.ts +64 -0
- package/backend/chat/turn-answer.ts +125 -0
- package/backend/chat-apps/awaiting.test.ts +39 -0
- package/backend/chat-apps/awaiting.ts +49 -0
- package/backend/chat-apps/conversation.ts +746 -0
- package/backend/chat-apps/inbound.ts +324 -0
- package/backend/chat-apps/index.ts +309 -0
- package/backend/chat-apps/link-events.ts +20 -0
- package/backend/chat-apps/media.test.ts +62 -0
- package/backend/chat-apps/media.ts +208 -0
- package/backend/chat-apps/messages.test.ts +229 -0
- package/backend/chat-apps/messages.ts +365 -0
- package/backend/chat-apps/outbound.ts +243 -0
- package/backend/chat-apps/pairing.test.ts +45 -0
- package/backend/chat-apps/pairing.ts +74 -0
- package/backend/chat-apps/platforms/index.ts +20 -0
- package/backend/chat-apps/platforms/telegram.test.ts +35 -0
- package/backend/chat-apps/platforms/telegram.ts +191 -0
- package/backend/chat-apps/platforms/types.ts +114 -0
- package/backend/chat-apps/questions.ts +133 -0
- package/backend/chat-apps/runtime.ts +572 -0
- package/backend/chat-apps/storage.test.ts +201 -0
- package/backend/chat-apps/turns.test.ts +45 -0
- package/backend/chat-apps/turns.ts +208 -0
- package/backend/containers/pty.ts +3 -11
- package/backend/control/actions/accounts.ts +89 -0
- package/backend/control/actions/files.ts +116 -0
- package/backend/control/actions/models.ts +188 -0
- package/backend/control/actions/projects.ts +272 -0
- package/backend/control/actions/sessions.ts +280 -0
- package/backend/control/actions/skills.ts +111 -0
- package/backend/control/control.test.ts +169 -0
- package/backend/control/define.ts +20 -0
- package/backend/control/folders.test.ts +67 -0
- package/backend/control/index.ts +213 -0
- package/backend/control/invoke.ts +44 -0
- package/backend/control/links.ts +35 -0
- package/backend/control/paging.ts +26 -0
- package/backend/control/types.ts +117 -0
- package/backend/control/workspace.ts +127 -0
- package/backend/database/migrations/084_create_channel_links.ts +71 -0
- package/backend/database/migrations/085_add_home_projects.ts +36 -0
- package/backend/database/migrations/086_single_owner.test.ts +170 -0
- package/backend/database/migrations/086_single_owner.ts +418 -0
- package/backend/database/migrations/index.ts +21 -0
- package/backend/database/queries/auth-queries.ts +7 -85
- package/backend/database/queries/channel-queries.ts +270 -0
- package/backend/database/queries/db-client-connection-queries.ts +18 -56
- package/backend/database/queries/file-share-queries.ts +5 -23
- package/backend/database/queries/git-identity-queries.ts +31 -42
- package/backend/database/queries/graph-queries.ts +1 -1
- package/backend/database/queries/index.ts +13 -1
- package/backend/database/queries/message-queries.test.ts +146 -0
- package/backend/database/queries/message-queries.ts +42 -1
- package/backend/database/queries/permission-set-queries.ts +1 -1
- package/backend/database/queries/profile-queries.ts +1 -1
- package/backend/database/queries/project-mcp-trust-queries.ts +1 -1
- package/backend/database/queries/project-queries.ts +50 -63
- package/backend/database/queries/session-queries.ts +28 -56
- package/backend/database/queries/ssh-connection-queries.ts +18 -41
- package/backend/db-client/integrations/projector.ts +0 -5
- package/backend/engine/adapters/claude/message-converter.test.ts +47 -0
- package/backend/engine/adapters/claude/message-converter.ts +25 -2
- package/backend/engine/adapters/cline/message-converter.ts +0 -1
- package/backend/engine/adapters/cline/stream.ts +11 -15
- package/backend/engine/adapters/codex/message-converter.ts +0 -2
- package/backend/engine/adapters/copilot/message-converter.ts +1 -2
- package/backend/engine/adapters/cursor/message-converter.ts +0 -1
- package/backend/engine/adapters/opencode/message-converter.ts +2 -4
- package/backend/engine/adapters/opencode/presets.ts +27 -2
- package/backend/engine/adapters/opencode/server.ts +6 -4
- package/backend/engine/adapters/opencode/stream.ts +11 -0
- package/backend/engine/adapters/parent-scope.test.ts +38 -0
- package/backend/engine/adapters/parent-scope.ts +44 -0
- package/backend/engine/adapters/pi/message-converter.ts +0 -1
- package/backend/engine/adapters/pi/stream.ts +4 -5
- package/backend/engine/adapters/qwen/message-converter.ts +0 -2
- package/backend/engine/bootstrap-default-engine.ts +2 -2
- package/backend/engine/docs/adapter-contract.md +8 -1
- package/backend/engine/install-runner.ts +8 -17
- package/backend/files/file-shares.ts +20 -44
- package/backend/files/file-size-limit.ts +3 -3
- package/backend/files/image-processing.ts +1 -1
- package/backend/files/os-clipboard.ts +2 -2
- package/backend/git/git-executor.ts +25 -5
- package/backend/git/git-service.ts +420 -19
- package/backend/git/identity/credential-helper.test.ts +2 -7
- package/backend/git/identity/import-local.test.ts +11 -16
- package/backend/git/identity/import-local.ts +12 -12
- package/backend/git/identity/index.ts +10 -24
- package/backend/git/identity/resolve.ts +13 -14
- package/backend/git/identity/scope-config.ts +33 -28
- package/backend/git/identity/service.ts +44 -47
- package/backend/git/op-lock.test.ts +111 -0
- package/backend/git/op-lock.ts +180 -0
- package/backend/git/remote-sync.test.ts +249 -0
- package/backend/host/metrics.ts +1 -1
- package/backend/http/bearer-auth.ts +1 -2
- package/backend/http/files-download.test.ts +8 -9
- package/backend/http/files-download.ts +2 -2
- package/backend/http/files-shared.test.ts +62 -89
- package/backend/http/files-shared.ts +2 -2
- package/backend/http/files-upload.test.ts +3 -7
- package/backend/http/files-upload.ts +3 -3
- package/backend/http/notes-images.test.ts +15 -38
- package/backend/http/notes-images.ts +6 -8
- package/backend/http/ssh-sftp.ts +5 -10
- package/backend/index.ts +21 -7
- package/backend/integrations/accounts.ts +61 -3
- package/backend/integrations/index.ts +2 -2
- package/backend/integrations/registry/define.ts +15 -0
- package/backend/integrations/registry/index.ts +2 -0
- package/backend/integrations/registry/providers/telegram.ts +54 -0
- package/backend/integrations/registry/types.ts +21 -1
- package/backend/integrations/webhooks/gateway.ts +7 -6
- package/backend/integrations/webhooks/verify.test.ts +30 -0
- package/backend/integrations/webhooks/verify.ts +4 -0
- package/backend/mcp/external/project.ts +1 -1
- package/backend/mcp/internal/remote-server.test.ts +1 -3
- package/backend/mcp/internal/remote-server.ts +4 -4
- package/backend/mcp/internal/servers/browser-automation/actions/dialogs.ts +67 -0
- package/backend/mcp/internal/servers/browser-automation/actions/index.ts +3 -1
- package/backend/mcp/internal/servers/browser-automation/actions/input.ts +5 -5
- package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +157 -28
- package/backend/mcp/internal/servers/browser-automation/context.ts +1 -0
- package/backend/mcp/internal/servers/browser-automation/description.ts +5 -2
- package/backend/mcp/internal/servers/browser-automation/format.ts +24 -1
- package/backend/mcp/internal/servers/browser-automation/runner.ts +68 -3
- package/backend/memory/redact.ts +1 -1
- package/backend/notes/access.test.ts +28 -29
- package/backend/notes/access.ts +6 -11
- package/backend/permissions/service.ts +1 -1
- package/backend/preview/browser/browser-clipboard.test.ts +46 -0
- package/backend/preview/browser/browser-clipboard.ts +67 -0
- package/backend/preview/browser/browser-dialog-handler.ts +95 -6
- package/backend/preview/browser/browser-host-bridge.ts +9 -0
- package/backend/preview/browser/browser-interaction-handler.ts +316 -86
- package/backend/preview/browser/browser-mcp-control.ts +34 -0
- package/backend/preview/browser/browser-pool.ts +67 -6
- package/backend/preview/browser/browser-preview-service.ts +361 -25
- package/backend/preview/browser/browser-tab-manager.ts +66 -23
- package/backend/preview/browser/browser-video-capture.ts +92 -5
- package/backend/preview/browser/element-locator.ts +190 -17
- package/backend/preview/browser/keyboard-chords.test.ts +68 -0
- package/backend/preview/browser/keyboard-chords.ts +132 -0
- package/backend/preview/browser/paste.ts +81 -0
- package/backend/preview/browser/process-usage.ts +142 -0
- package/backend/preview/browser/profile-lock.ts +209 -0
- package/backend/preview/browser/scripts/host-bridge.ts +59 -0
- package/backend/preview/browser/scripts/video-stream.ts +58 -0
- package/backend/preview/browser/types.ts +40 -2
- package/backend/preview/browser/viewport.test.ts +45 -0
- package/backend/preview/browser/viewport.ts +96 -0
- package/backend/profiles/service.ts +2 -2
- package/backend/project/status-manager.ts +43 -172
- package/backend/projects/home.ts +61 -0
- package/backend/projects/project-cleanup.integration.test.ts +2 -2
- package/backend/projects/project-cleanup.ts +0 -8
- package/backend/skills/service.ts +2 -3
- package/backend/snapshot/helpers.ts +0 -1
- package/backend/snapshot/restore.ts +252 -0
- package/backend/ssh/ptykit.ts +1 -2
- package/backend/terminal/ptykit.ts +5 -8
- package/backend/tunnel/public-origin.ts +31 -20
- package/backend/utils/user-helpers.ts +0 -55
- package/backend/utils/ws.ts +61 -154
- package/backend/worktrees/branching/engine.ts +3 -16
- package/backend/worktrees/branching/index.ts +1 -1
- package/backend/worktrees/branching/projector.ts +1 -1
- package/backend/worktrees/branching/service.ts +13 -25
- package/backend/ws/access.ts +12 -21
- package/backend/ws/artifacts/generate.ts +2 -2
- package/backend/ws/auth/device.ts +16 -71
- package/backend/ws/auth/index.ts +4 -22
- package/backend/ws/auth/login.test.ts +14 -60
- package/backend/ws/auth/login.ts +24 -124
- package/backend/ws/auth/status.ts +0 -1
- package/backend/ws/chat/composer.ts +118 -118
- package/backend/ws/chat/stream.ts +64 -47
- package/backend/ws/chat-apps/index.ts +117 -0
- package/backend/ws/containers/actions.ts +11 -25
- package/backend/ws/containers/index.ts +3 -4
- package/backend/ws/containers/list.ts +10 -36
- package/backend/ws/containers/logs.ts +2 -2
- package/backend/ws/containers/tunnel.ts +1 -2
- package/backend/ws/db-client/access.ts +2 -16
- package/backend/ws/db-client/accounts.ts +5 -15
- package/backend/ws/db-client/connections.ts +17 -25
- package/backend/ws/db-client/context.ts +1 -1
- package/backend/ws/db-client/env.ts +7 -10
- package/backend/ws/db-client/index.ts +2 -2
- package/backend/ws/db-client/io.ts +5 -5
- package/backend/ws/db-client/query-history-retention.test.ts +8 -8
- package/backend/ws/db-client/query.ts +18 -17
- package/backend/ws/db-client/schema.ts +13 -13
- package/backend/ws/db-client/structure.ts +35 -35
- package/backend/ws/db-client/supabase.ts +4 -21
- package/backend/ws/deployments/context.ts +1 -1
- package/backend/ws/deployments/crud.ts +0 -5
- package/backend/ws/engine/access.ts +7 -20
- package/backend/ws/engine/claude/accounts.ts +4 -4
- package/backend/ws/engine/cline/accounts.ts +5 -5
- package/backend/ws/engine/codex/accounts.ts +3 -3
- package/backend/ws/engine/opencode/providers.ts +2 -1
- package/backend/ws/engine/pi/accounts.ts +5 -5
- package/backend/ws/files/clipboard.ts +8 -27
- package/backend/ws/files/image-edit.ts +6 -6
- package/backend/ws/files/index.ts +1 -1
- package/backend/ws/files/path-access.test.ts +32 -131
- package/backend/ws/files/path-access.ts +8 -87
- package/backend/ws/files/read.ts +15 -19
- package/backend/ws/files/reveal.ts +3 -3
- package/backend/ws/files/search.ts +7 -7
- package/backend/ws/files/share.ts +9 -13
- package/backend/ws/files/state.ts +9 -12
- package/backend/ws/files/watch.ts +3 -3
- package/backend/ws/files/write.ts +30 -31
- package/backend/ws/git/branch.ts +80 -59
- package/backend/ws/git/commit.ts +63 -44
- package/backend/ws/git/conflict.ts +16 -18
- package/backend/ws/git/identity-context.ts +8 -17
- package/backend/ws/git/identity.ts +17 -27
- package/backend/ws/git/index.ts +3 -1
- package/backend/ws/git/op-state.ts +139 -0
- package/backend/ws/git/remote.ts +241 -141
- package/backend/ws/git/repo-context.ts +67 -0
- package/backend/ws/git/staging.ts +18 -28
- package/backend/ws/git/status.ts +5 -2
- package/backend/ws/index.ts +5 -1
- package/backend/ws/instructions/crud.ts +1 -1
- package/backend/ws/integrations/crud.ts +1 -3
- package/backend/ws/mcp/crud.ts +3 -5
- package/backend/ws/mcp/tools.ts +1 -1
- package/backend/ws/memory/crud.ts +14 -46
- package/backend/ws/memory/index.ts +2 -2
- package/backend/ws/messages/crud.ts +29 -8
- package/backend/ws/notes/index.ts +33 -39
- package/backend/ws/permissions/crud.ts +3 -4
- package/backend/ws/ports/index.ts +1 -2
- package/backend/ws/ports/kill.ts +5 -10
- package/backend/ws/ports/list.ts +4 -10
- package/backend/ws/preview/access.ts +1 -1
- package/backend/ws/preview/browser/interact.ts +52 -79
- package/backend/ws/preview/browser/native-ui.ts +24 -0
- package/backend/ws/preview/browser/stats.ts +98 -1
- package/backend/ws/preview/browser/tab-info.ts +15 -0
- package/backend/ws/preview/browser/tab.ts +19 -4
- package/backend/ws/preview/index.ts +27 -0
- package/backend/ws/profiles/crud.ts +6 -8
- package/backend/ws/project-artifacts/index.ts +30 -31
- package/backend/ws/projects/crud.ts +33 -35
- package/backend/ws/projects/index.ts +3 -8
- package/backend/ws/projects/info.ts +3 -3
- package/backend/ws/projects/overview.ts +19 -30
- package/backend/ws/projects/status.ts +17 -57
- package/backend/ws/sessions/crud.ts +34 -45
- package/backend/ws/sessions/index.ts +1 -1
- package/backend/ws/settings/crud.ts +1 -1
- package/backend/ws/skills/crud.ts +3 -4
- package/backend/ws/skills/index.ts +1 -1
- package/backend/ws/snapshot/changes.ts +7 -7
- package/backend/ws/snapshot/restore.ts +11 -295
- package/backend/ws/snapshot/timeline.ts +2 -4
- package/backend/ws/ssh/access.ts +6 -21
- package/backend/ws/ssh/connections.ts +21 -31
- package/backend/ws/ssh/forwards.ts +12 -12
- package/backend/ws/ssh/sftp.ts +34 -34
- package/backend/ws/ssh/tunnel.ts +1 -2
- package/backend/ws/stack/install.ts +7 -17
- package/backend/ws/subagents/crud.ts +1 -1
- package/backend/ws/tunnel/share.ts +0 -2
- package/backend/ws/user/crud.ts +1 -59
- package/backend/ws/user/index.ts +1 -1
- package/backend/ws/work/context.ts +1 -1
- package/backend/ws/work/crud.ts +0 -5
- package/backend/ws/workspace/state.ts +10 -13
- package/backend/ws/worktrees/branching.ts +7 -36
- package/backend/ws/worktrees/crud.ts +2 -2
- package/bin/clopen.ts +10 -11
- package/dist/assets/{index-CwuKQelV.js → index-CONlwAXZ.js} +1 -1
- package/dist/assets/{index-BTcR1byF.js → index-DJzwt-hq.js} +1 -1
- package/dist/assets/main-BUiUL3eZ.css +1 -0
- package/dist/assets/main-nBOb9YOA.js +1240 -0
- package/dist/index.html +2 -2
- package/package.json +2 -1
- package/shared/constants/attachments.ts +14 -0
- package/shared/constants/engine-tools.ts +1 -1
- package/shared/constants/preview.test.ts +259 -0
- package/shared/constants/preview.ts +1018 -57
- package/shared/constants/tool-icons.ts +5 -0
- package/shared/types/containers/container.ts +1 -1
- package/shared/types/database/schema.ts +9 -6
- package/shared/types/git-identity.ts +1 -1
- package/shared/types/git.ts +116 -0
- package/shared/types/integrations.ts +7 -0
- package/shared/types/stores/settings.ts +1 -1
- package/shared/types/unified/index.ts +1 -1
- package/shared/types/unified/message.ts +0 -7
- package/shared/types/unified/stream.ts +2 -4
- package/shared/types/unified/tool.ts +15 -1
- package/shared/utils/ask-user-question.test.ts +319 -0
- package/shared/utils/ask-user-question.ts +154 -0
- package/shared/utils/home-project.ts +25 -0
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/ws-server.ts +32 -7
- package/backend/auth/session-invalidation.test.ts +0 -112
- package/backend/auth/session-invalidation.ts +0 -77
- package/backend/project/status-manager.test.ts +0 -32
- package/backend/ws/auth/invites.ts +0 -94
- package/backend/ws/auth/users.ts +0 -112
- package/backend/ws/projects/presence.ts +0 -46
- package/backend/ws/stack/access.ts +0 -31
- package/dist/assets/main-BiDNMWb3.css +0 -1
- package/dist/assets/main-BlhKWz2B.js +0 -1241
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* `GET /api/files/shared?share=<token>` serves exactly the file its token was
|
|
5
5
|
* minted for — no session, no path parameter — so the token binding (not just
|
|
6
|
-
* the status code) is asserted here.
|
|
7
|
-
* too: a path outside the caller's projects must not be shareable.
|
|
6
|
+
* the status code) is asserted here.
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
9
|
import { describe, it, expect, beforeAll, afterAll } from 'bun:test';
|
|
@@ -26,14 +25,13 @@ import {
|
|
|
26
25
|
import { authQueries, fileShareQueries } from '../database/queries';
|
|
27
26
|
import { hashToken } from '../auth/tokens';
|
|
28
27
|
import { projectQueries } from '../database/queries/project-queries';
|
|
29
|
-
import { initializeDatabase, closeDatabase } from '../database';
|
|
28
|
+
import { initializeDatabase, closeDatabase, getDatabase } from '../database';
|
|
30
29
|
|
|
31
30
|
const TEST_DIR = join(import.meta.dir, '.test-shared-integration');
|
|
32
31
|
const TEST_WORKSPACE = join(TEST_DIR, 'workspace');
|
|
33
32
|
const OUTSIDE_DIR = join(TEST_DIR, 'outside');
|
|
34
33
|
|
|
35
34
|
let testUserId: string;
|
|
36
|
-
let otherUserId: string;
|
|
37
35
|
let testProjectId: string;
|
|
38
36
|
|
|
39
37
|
function createMockSharedRequest(share: string | null, headers?: Record<string, string>): Request {
|
|
@@ -63,18 +61,6 @@ beforeAll(async () => {
|
|
|
63
61
|
name: 'Share Test User',
|
|
64
62
|
color: '#000000',
|
|
65
63
|
avatar: 'test',
|
|
66
|
-
role: 'member',
|
|
67
|
-
personal_access_token_hash: null,
|
|
68
|
-
created_at: new Date().toISOString()
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
otherUserId = randomUUID();
|
|
72
|
-
authQueries.createUser({
|
|
73
|
-
id: otherUserId,
|
|
74
|
-
name: 'Other Test User',
|
|
75
|
-
color: '#111111',
|
|
76
|
-
avatar: 'test',
|
|
77
|
-
role: 'member',
|
|
78
64
|
personal_access_token_hash: null,
|
|
79
65
|
created_at: new Date().toISOString()
|
|
80
66
|
});
|
|
@@ -86,14 +72,10 @@ beforeAll(async () => {
|
|
|
86
72
|
last_opened_at: new Date().toISOString()
|
|
87
73
|
});
|
|
88
74
|
testProjectId = project.id;
|
|
89
|
-
projectQueries.addUserProject(testUserId, testProjectId);
|
|
90
75
|
});
|
|
91
76
|
|
|
92
77
|
afterAll(async () => {
|
|
93
|
-
|
|
94
|
-
authQueries.deleteUser(testUserId);
|
|
95
|
-
authQueries.deleteSessionsByUserId(otherUserId);
|
|
96
|
-
authQueries.deleteUser(otherUserId);
|
|
78
|
+
getDatabase().prepare('DELETE FROM users WHERE id = ?').run(testUserId);
|
|
97
79
|
projectQueries.deleteProject(testProjectId);
|
|
98
80
|
closeDatabase();
|
|
99
81
|
await rm(TEST_DIR, { recursive: true, force: true });
|
|
@@ -105,7 +87,7 @@ describe('File share links', () => {
|
|
|
105
87
|
const filePath = join(TEST_WORKSPACE, 'shared notes.txt');
|
|
106
88
|
await writeFile(filePath, content);
|
|
107
89
|
|
|
108
|
-
const { shareToken } = await createFileShareLink(filePath,
|
|
90
|
+
const { shareToken } = await createFileShareLink(filePath, testUserId);
|
|
109
91
|
const response = await filesSharedRoute.handle(createMockSharedRequest(shareToken));
|
|
110
92
|
|
|
111
93
|
expect(response.status).toBe(200);
|
|
@@ -119,7 +101,7 @@ describe('File share links', () => {
|
|
|
119
101
|
it('expires after the first successful open', async () => {
|
|
120
102
|
const filePath = join(TEST_WORKSPACE, 'one-time.txt');
|
|
121
103
|
await writeFile(filePath, 'open me once');
|
|
122
|
-
const { shareToken } = await createFileShareLink(filePath,
|
|
104
|
+
const { shareToken } = await createFileShareLink(filePath, testUserId);
|
|
123
105
|
|
|
124
106
|
const first = await filesSharedRoute.handle(createMockSharedRequest(shareToken));
|
|
125
107
|
expect(first.status).toBe(200);
|
|
@@ -138,7 +120,7 @@ describe('File share links', () => {
|
|
|
138
120
|
const content = '0123456789abcdef';
|
|
139
121
|
const filePath = join(TEST_WORKSPACE, 'clip.mp4');
|
|
140
122
|
await writeFile(filePath, content);
|
|
141
|
-
const { shareToken } = await createFileShareLink(filePath,
|
|
123
|
+
const { shareToken } = await createFileShareLink(filePath, testUserId);
|
|
142
124
|
|
|
143
125
|
const part = await filesSharedRoute.handle(
|
|
144
126
|
createMockSharedRequest(shareToken, { range: 'bytes=0-4' })
|
|
@@ -160,7 +142,7 @@ describe('File share links', () => {
|
|
|
160
142
|
const content = '0123456789abcdef';
|
|
161
143
|
const filePath = join(TEST_WORKSPACE, 'movie.mp4');
|
|
162
144
|
await writeFile(filePath, content);
|
|
163
|
-
const { shareToken } = await createFileShareLink(filePath,
|
|
145
|
+
const { shareToken } = await createFileShareLink(filePath, testUserId);
|
|
164
146
|
|
|
165
147
|
// The one open: full body, token burned.
|
|
166
148
|
const first = await filesSharedRoute.handle(createMockSharedRequest(shareToken));
|
|
@@ -184,7 +166,7 @@ describe('File share links', () => {
|
|
|
184
166
|
const content = '0123456789';
|
|
185
167
|
const filePath = join(TEST_WORKSPACE, 'short.mp4');
|
|
186
168
|
await writeFile(filePath, content);
|
|
187
|
-
const { shareToken } = await createFileShareLink(filePath,
|
|
169
|
+
const { shareToken } = await createFileShareLink(filePath, testUserId);
|
|
188
170
|
|
|
189
171
|
const over = await filesSharedRoute.handle(
|
|
190
172
|
createMockSharedRequest(shareToken, { range: `bytes=${content.length}-` })
|
|
@@ -202,8 +184,8 @@ describe('File share links', () => {
|
|
|
202
184
|
const fileB = join(TEST_WORKSPACE, 'file-b.txt');
|
|
203
185
|
await writeFile(fileA, 'content-a');
|
|
204
186
|
await writeFile(fileB, 'content-b');
|
|
205
|
-
const { shareToken: tokenA } = await createFileShareLink(fileA,
|
|
206
|
-
const { shareToken: tokenB } = await createFileShareLink(fileB,
|
|
187
|
+
const { shareToken: tokenA } = await createFileShareLink(fileA, testUserId);
|
|
188
|
+
const { shareToken: tokenB } = await createFileShareLink(fileB, testUserId);
|
|
207
189
|
|
|
208
190
|
expect((await filesSharedRoute.handle(createMockSharedRequest(tokenA))).status).toBe(200);
|
|
209
191
|
expect((await filesSharedRoute.handle(createMockSharedRequest(tokenA))).status).toBe(410);
|
|
@@ -216,7 +198,7 @@ describe('File share links', () => {
|
|
|
216
198
|
it('resolves to the minted file even when the bytes change on disk', async () => {
|
|
217
199
|
const filePath = join(TEST_WORKSPACE, 'moving.txt');
|
|
218
200
|
await writeFile(filePath, 'v1');
|
|
219
|
-
const { shareToken } = await createFileShareLink(filePath,
|
|
201
|
+
const { shareToken } = await createFileShareLink(filePath, testUserId);
|
|
220
202
|
await writeFile(filePath, 'v2-longer');
|
|
221
203
|
|
|
222
204
|
const response = await filesSharedRoute.handle(createMockSharedRequest(shareToken));
|
|
@@ -238,67 +220,53 @@ describe('File share links', () => {
|
|
|
238
220
|
// The raw token is deliberately NOT passed to revoke: it only ever exists
|
|
239
221
|
// in the browser that minted it, so a revoke keyed on it would be
|
|
240
222
|
// unreachable the moment that view closes.
|
|
241
|
-
const { shareId, shareToken } = await createFileShareLink(filePath,
|
|
223
|
+
const { shareId, shareToken } = await createFileShareLink(filePath, testUserId);
|
|
242
224
|
|
|
243
|
-
expect(revokeFileShareLink(shareId
|
|
225
|
+
expect(revokeFileShareLink(shareId)).toBe(true);
|
|
244
226
|
await expect(peekFileShare(shareToken, consumerFingerprint())).rejects.toThrow();
|
|
245
227
|
|
|
246
228
|
const response = await filesSharedRoute.handle(createMockSharedRequest(shareToken));
|
|
247
229
|
expect(response.status).toBe(410);
|
|
248
230
|
|
|
249
231
|
// Revoking the same id twice is a no-op, not an error.
|
|
250
|
-
expect(revokeFileShareLink(shareId
|
|
232
|
+
expect(revokeFileShareLink(shareId)).toBe(false);
|
|
251
233
|
});
|
|
252
234
|
|
|
253
|
-
it(
|
|
254
|
-
const filePath = join(TEST_WORKSPACE, 'not-yours.txt');
|
|
255
|
-
await writeFile(filePath, 'mine');
|
|
256
|
-
const { shareId } = await createFileShareLink(filePath, 'member', testUserId);
|
|
257
|
-
|
|
258
|
-
expect(() => revokeFileShareLink(shareId, 'member', otherUserId)).toThrow();
|
|
259
|
-
expect(revokeFileShareLink(shareId, 'admin', otherUserId)).toBe(true);
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it('lists live links with no token material, scoped by role', async () => {
|
|
235
|
+
it('lists live links with no token material', async () => {
|
|
263
236
|
const filePath = join(TEST_WORKSPACE, 'listed.txt');
|
|
264
237
|
await writeFile(filePath, 'listed');
|
|
265
|
-
const { shareId } = await createFileShareLink(filePath,
|
|
238
|
+
const { shareId } = await createFileShareLink(filePath, testUserId);
|
|
266
239
|
|
|
267
|
-
const mine = listFileShares(
|
|
240
|
+
const mine = listFileShares();
|
|
268
241
|
const entry = mine.find((s) => s.id === shareId);
|
|
269
242
|
expect(entry).toBeDefined();
|
|
270
243
|
expect(entry?.fileName).toBe('listed.txt');
|
|
271
|
-
expect(entry?.createdByName).toBe('Share Test User');
|
|
272
244
|
expect(entry?.consumedAt).toBeNull();
|
|
273
245
|
// Nothing in the summary can rebuild the URL.
|
|
274
246
|
expect(JSON.stringify(entry)).not.toContain('clp_fsh_');
|
|
275
247
|
|
|
276
|
-
|
|
277
|
-
expect(listFileShares(
|
|
278
|
-
expect(listFileShares('admin', otherUserId).some((s) => s.id === shareId)).toBe(true);
|
|
279
|
-
|
|
280
|
-
revokeFileShareLink(shareId, 'member', testUserId);
|
|
281
|
-
expect(listFileShares('member', testUserId).some((s) => s.id === shareId)).toBe(false);
|
|
248
|
+
revokeFileShareLink(shareId);
|
|
249
|
+
expect(listFileShares().some((s) => s.id === shareId)).toBe(false);
|
|
282
250
|
});
|
|
283
251
|
|
|
284
252
|
it('marks a link as opened in the list instead of hiding it', async () => {
|
|
285
253
|
const filePath = join(TEST_WORKSPACE, 'opened.txt');
|
|
286
254
|
await writeFile(filePath, 'read me');
|
|
287
|
-
const { shareId, shareToken } = await createFileShareLink(filePath,
|
|
255
|
+
const { shareId, shareToken } = await createFileShareLink(filePath, testUserId);
|
|
288
256
|
|
|
289
257
|
expect((await filesSharedRoute.handle(createMockSharedRequest(shareToken))).status).toBe(200);
|
|
290
258
|
|
|
291
259
|
// Still listed, still revocable — the continuation window is live until
|
|
292
260
|
// it is cut, and cutting it is the point of showing the row.
|
|
293
|
-
const entry = listFileShares(
|
|
261
|
+
const entry = listFileShares().find((s) => s.id === shareId);
|
|
294
262
|
expect(entry?.consumedAt).not.toBeNull();
|
|
295
|
-
expect(revokeFileShareLink(shareId
|
|
263
|
+
expect(revokeFileShareLink(shareId)).toBe(true);
|
|
296
264
|
});
|
|
297
265
|
|
|
298
266
|
it('defaults to one-time and a five-minute deadline', async () => {
|
|
299
267
|
const filePath = join(TEST_WORKSPACE, 'ttl.txt');
|
|
300
268
|
await writeFile(filePath, 'tick');
|
|
301
|
-
const { oneTime, expiresAt } = await createFileShareLink(filePath,
|
|
269
|
+
const { oneTime, expiresAt } = await createFileShareLink(filePath, testUserId);
|
|
302
270
|
|
|
303
271
|
expect(DEFAULT_FILE_SHARE_TTL_MINUTES).toBe(5);
|
|
304
272
|
expect(oneTime).toBe(true);
|
|
@@ -311,7 +279,7 @@ describe('File share links', () => {
|
|
|
311
279
|
const content = 'read me twice';
|
|
312
280
|
const filePath = join(TEST_WORKSPACE, 'reusable.txt');
|
|
313
281
|
await writeFile(filePath, content);
|
|
314
|
-
const { shareId, shareToken } = await createFileShareLink(filePath,
|
|
282
|
+
const { shareId, shareToken } = await createFileShareLink(filePath, testUserId, {
|
|
315
283
|
oneTime: false,
|
|
316
284
|
expiresInMinutes: 15
|
|
317
285
|
});
|
|
@@ -325,7 +293,7 @@ describe('File share links', () => {
|
|
|
325
293
|
// Even a stranger — a reusable link is exactly that, on purpose.
|
|
326
294
|
expect((await filesSharedRoute.handle(createStrangerRequest(shareToken))).status).toBe(200);
|
|
327
295
|
|
|
328
|
-
const entry = listFileShares(
|
|
296
|
+
const entry = listFileShares().find((s) => s.id === shareId);
|
|
329
297
|
expect(entry?.oneTime).toBe(false);
|
|
330
298
|
expect(entry?.openCount).toBe(4);
|
|
331
299
|
expect(entry?.lastOpenedAt).not.toBeNull();
|
|
@@ -336,7 +304,7 @@ describe('File share links', () => {
|
|
|
336
304
|
it('does not inflate the open count with range requests', async () => {
|
|
337
305
|
const filePath = join(TEST_WORKSPACE, 'reusable-clip.mp4');
|
|
338
306
|
await writeFile(filePath, '0123456789abcdef');
|
|
339
|
-
const { shareId, shareToken } = await createFileShareLink(filePath,
|
|
307
|
+
const { shareId, shareToken } = await createFileShareLink(filePath, testUserId, {
|
|
340
308
|
oneTime: false,
|
|
341
309
|
expiresInMinutes: 15
|
|
342
310
|
});
|
|
@@ -347,18 +315,18 @@ describe('File share links', () => {
|
|
|
347
315
|
}
|
|
348
316
|
|
|
349
317
|
// One viewing is one open, not four.
|
|
350
|
-
expect(listFileShares(
|
|
318
|
+
expect(listFileShares().find((s) => s.id === shareId)?.openCount).toBe(1);
|
|
351
319
|
});
|
|
352
320
|
|
|
353
321
|
it('keeps a link without a deadline alive, and revoke is the only end', async () => {
|
|
354
322
|
const filePath = join(TEST_WORKSPACE, 'no-deadline.txt');
|
|
355
323
|
await writeFile(filePath, 'forever');
|
|
356
|
-
const { shareId, shareToken } = await createFileShareLink(filePath,
|
|
324
|
+
const { shareId, shareToken } = await createFileShareLink(filePath, testUserId, {
|
|
357
325
|
oneTime: false,
|
|
358
326
|
expiresInMinutes: null
|
|
359
327
|
});
|
|
360
328
|
|
|
361
|
-
const entry = listFileShares(
|
|
329
|
+
const entry = listFileShares().find((s) => s.id === shareId);
|
|
362
330
|
expect(entry?.expiresAt).toBeNull();
|
|
363
331
|
expect((await filesSharedRoute.handle(createMockSharedRequest(shareToken))).status).toBe(200);
|
|
364
332
|
|
|
@@ -366,7 +334,7 @@ describe('File share links', () => {
|
|
|
366
334
|
sweepStaleFileShares();
|
|
367
335
|
expect((await filesSharedRoute.handle(createMockSharedRequest(shareToken))).status).toBe(200);
|
|
368
336
|
|
|
369
|
-
expect(revokeFileShareLink(shareId
|
|
337
|
+
expect(revokeFileShareLink(shareId)).toBe(true);
|
|
370
338
|
expect((await filesSharedRoute.handle(createMockSharedRequest(shareToken))).status).toBe(410);
|
|
371
339
|
});
|
|
372
340
|
|
|
@@ -374,10 +342,10 @@ describe('File share links', () => {
|
|
|
374
342
|
const filePath = join(TEST_WORKSPACE, 'bad-ttl.txt');
|
|
375
343
|
await writeFile(filePath, 'nope');
|
|
376
344
|
await expect(
|
|
377
|
-
createFileShareLink(filePath,
|
|
345
|
+
createFileShareLink(filePath, testUserId, { expiresInMinutes: 0 })
|
|
378
346
|
).rejects.toThrow();
|
|
379
347
|
await expect(
|
|
380
|
-
createFileShareLink(filePath,
|
|
348
|
+
createFileShareLink(filePath, testUserId, { expiresInMinutes: 60 * 24 * 365 })
|
|
381
349
|
).rejects.toThrow();
|
|
382
350
|
});
|
|
383
351
|
|
|
@@ -386,9 +354,9 @@ describe('File share links', () => {
|
|
|
386
354
|
await mkdir(nested, { recursive: true });
|
|
387
355
|
const filePath = join(nested, 'index.ts');
|
|
388
356
|
await writeFile(filePath, 'export {};');
|
|
389
|
-
const { shareId } = await createFileShareLink(filePath,
|
|
357
|
+
const { shareId } = await createFileShareLink(filePath, testUserId);
|
|
390
358
|
|
|
391
|
-
const entry = listFileShares(
|
|
359
|
+
const entry = listFileShares().find((s) => s.id === shareId);
|
|
392
360
|
expect(entry?.projectName).toBe('Share Test Project');
|
|
393
361
|
expect(entry?.relativePath).toBe('src/deep/index.ts');
|
|
394
362
|
expect(entry?.fileName).toBe('index.ts');
|
|
@@ -399,18 +367,21 @@ describe('File share links', () => {
|
|
|
399
367
|
expect(orphan.relativePath).toContain('loose.txt');
|
|
400
368
|
});
|
|
401
369
|
|
|
402
|
-
it('refuses to share a directory
|
|
403
|
-
await expect(createFileShareLink(TEST_WORKSPACE,
|
|
370
|
+
it('refuses to share a directory', async () => {
|
|
371
|
+
await expect(createFileShareLink(TEST_WORKSPACE, testUserId)).rejects.toThrow();
|
|
372
|
+
});
|
|
404
373
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
await
|
|
374
|
+
it('shares a file outside every project', async () => {
|
|
375
|
+
const outside = join(OUTSIDE_DIR, 'loose-share.txt');
|
|
376
|
+
await writeFile(outside, 'anywhere on the machine');
|
|
377
|
+
const { shareToken } = await createFileShareLink(outside, testUserId);
|
|
378
|
+
expect((await filesSharedRoute.handle(createMockSharedRequest(shareToken))).status).toBe(200);
|
|
408
379
|
});
|
|
409
380
|
|
|
410
381
|
it('reports a deleted file as not found without burning the single use', async () => {
|
|
411
382
|
const filePath = join(TEST_WORKSPACE, 'deleted.txt');
|
|
412
383
|
await writeFile(filePath, 'gone soon');
|
|
413
|
-
const { shareToken } = await createFileShareLink(filePath,
|
|
384
|
+
const { shareToken } = await createFileShareLink(filePath, testUserId);
|
|
414
385
|
await rm(filePath);
|
|
415
386
|
|
|
416
387
|
// A failed open never counts as the one use: still 404, never 410.
|
|
@@ -421,7 +392,7 @@ describe('File share links', () => {
|
|
|
421
392
|
it('persists the link outside process memory so a restart does not kill it', async () => {
|
|
422
393
|
const filePath = join(TEST_WORKSPACE, 'durable.txt');
|
|
423
394
|
await writeFile(filePath, 'still here');
|
|
424
|
-
const { shareToken, expiresAt } = await createFileShareLink(filePath,
|
|
395
|
+
const { shareToken, expiresAt } = await createFileShareLink(filePath, testUserId);
|
|
425
396
|
|
|
426
397
|
// The row — not a Map entry — is what a restarted server reads back.
|
|
427
398
|
const row = fileShareQueries.getByHash(hashToken(shareToken));
|
|
@@ -436,7 +407,7 @@ describe('File share links', () => {
|
|
|
436
407
|
const content = '0123456789abcdef';
|
|
437
408
|
const filePath = join(TEST_WORKSPACE, 'bound.mp4');
|
|
438
409
|
await writeFile(filePath, content);
|
|
439
|
-
const { shareToken } = await createFileShareLink(filePath,
|
|
410
|
+
const { shareToken } = await createFileShareLink(filePath, testUserId);
|
|
440
411
|
|
|
441
412
|
// The recipient opens it: token burned, their player may keep seeking.
|
|
442
413
|
expect((await filesSharedRoute.handle(createMockSharedRequest(shareToken))).status).toBe(200);
|
|
@@ -453,28 +424,30 @@ describe('File share links', () => {
|
|
|
453
424
|
expect(await leaked.text()).toContain(FILE_SHARE_GONE_MESSAGE);
|
|
454
425
|
});
|
|
455
426
|
|
|
456
|
-
it('stops serving once the
|
|
457
|
-
const filePath = join(TEST_WORKSPACE, '
|
|
427
|
+
it('stops serving once the account that minted it is gone', async () => {
|
|
428
|
+
const filePath = join(TEST_WORKSPACE, 'reset.txt');
|
|
458
429
|
await writeFile(filePath, 'internal');
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
}
|
|
430
|
+
const creatorId = randomUUID();
|
|
431
|
+
authQueries.createUser({
|
|
432
|
+
id: creatorId,
|
|
433
|
+
name: 'Gone Soon',
|
|
434
|
+
color: '#111111',
|
|
435
|
+
avatar: 'test',
|
|
436
|
+
personal_access_token_hash: null,
|
|
437
|
+
created_at: new Date().toISOString()
|
|
438
|
+
});
|
|
439
|
+
const { shareToken } = await createFileShareLink(filePath, creatorId);
|
|
468
440
|
|
|
469
|
-
|
|
470
|
-
|
|
441
|
+
getDatabase().prepare('DELETE FROM users WHERE id = ?').run(creatorId);
|
|
442
|
+
const response = await filesSharedRoute.handle(createMockSharedRequest(shareToken));
|
|
443
|
+
expect(response.status).toBe(410);
|
|
471
444
|
});
|
|
472
445
|
|
|
473
446
|
it('answers HEAD with metadata only, without spending the single use', async () => {
|
|
474
447
|
const content = 'probe me';
|
|
475
448
|
const filePath = join(TEST_WORKSPACE, 'probed.txt');
|
|
476
449
|
await writeFile(filePath, content);
|
|
477
|
-
const { shareToken } = await createFileShareLink(filePath,
|
|
450
|
+
const { shareToken } = await createFileShareLink(filePath, testUserId);
|
|
478
451
|
|
|
479
452
|
const url = new URL('http://localhost/api/files/shared');
|
|
480
453
|
url.searchParams.set('share', shareToken);
|
|
@@ -496,7 +469,7 @@ describe('File share links', () => {
|
|
|
496
469
|
await mkdir(dottedDir, { recursive: true });
|
|
497
470
|
const filePath = join(dottedDir, 'NOTES');
|
|
498
471
|
await writeFile(filePath, 'no extension here');
|
|
499
|
-
const { shareToken } = await createFileShareLink(filePath,
|
|
472
|
+
const { shareToken } = await createFileShareLink(filePath, testUserId);
|
|
500
473
|
|
|
501
474
|
const response = await filesSharedRoute.handle(createMockSharedRequest(shareToken));
|
|
502
475
|
expect(response.status).toBe(200);
|
|
@@ -108,8 +108,8 @@ function parseByteRange(header: string | null, size: number): ByteRange | 'unsat
|
|
|
108
108
|
* Tell every open management view that the list moved.
|
|
109
109
|
*
|
|
110
110
|
* This route is HTTP, not WebSocket, and the person triggering it is not
|
|
111
|
-
* signed in — so the broadcast goes out globally and each client re-reads
|
|
112
|
-
*
|
|
111
|
+
* signed in — so the broadcast goes out globally and each client re-reads the
|
|
112
|
+
* list. A "something changed" ping carries nothing to leak.
|
|
113
113
|
*/
|
|
114
114
|
function notifyShareChanged(): void {
|
|
115
115
|
try {
|
|
@@ -15,7 +15,7 @@ import { filesUploadRoute } from './files-upload';
|
|
|
15
15
|
import { authQueries } from '../database/queries';
|
|
16
16
|
import { hashToken } from '../auth/tokens';
|
|
17
17
|
import { projectQueries } from '../database/queries/project-queries';
|
|
18
|
-
import { initializeDatabase, closeDatabase } from '../database';
|
|
18
|
+
import { initializeDatabase, closeDatabase, getDatabase } from '../database';
|
|
19
19
|
|
|
20
20
|
const TEST_DIR = join(import.meta.dir, '.test-upload-integration');
|
|
21
21
|
const TEST_WORKSPACE = join(TEST_DIR, 'workspace');
|
|
@@ -61,7 +61,6 @@ beforeAll(async () => {
|
|
|
61
61
|
name: 'Test User',
|
|
62
62
|
color: '#000000',
|
|
63
63
|
avatar: 'test',
|
|
64
|
-
role: 'admin',
|
|
65
64
|
personal_access_token_hash: null,
|
|
66
65
|
created_at: new Date().toISOString()
|
|
67
66
|
});
|
|
@@ -90,15 +89,12 @@ beforeAll(async () => {
|
|
|
90
89
|
last_opened_at: new Date().toISOString()
|
|
91
90
|
});
|
|
92
91
|
testProjectId = project.id;
|
|
93
|
-
|
|
94
|
-
// Link user to project
|
|
95
|
-
projectQueries.addUserProject(testUserId, testProjectId);
|
|
92
|
+
projectQueries.list(testProjectId);
|
|
96
93
|
});
|
|
97
94
|
|
|
98
95
|
afterAll(async () => {
|
|
99
96
|
// Clean up database
|
|
100
|
-
|
|
101
|
-
authQueries.deleteUser(testUserId);
|
|
97
|
+
getDatabase().prepare('DELETE FROM users WHERE id = ?').run(testUserId);
|
|
102
98
|
projectQueries.deleteProject(testProjectId);
|
|
103
99
|
|
|
104
100
|
// Close database
|
|
@@ -20,7 +20,7 @@ import { link, mkdir, stat, unlink } from 'node:fs/promises';
|
|
|
20
20
|
|
|
21
21
|
import { debug } from '$shared/utils/logger';
|
|
22
22
|
import { fileAuditLogQueries } from '../database/queries';
|
|
23
|
-
import { findContainingProjectId,
|
|
23
|
+
import { findContainingProjectId, resolveFilePath } from '../ws/files/path-access';
|
|
24
24
|
import { clientIpFromRequest } from '../utils/client-ip';
|
|
25
25
|
import { validateFileSize } from '../files/file-size-limit';
|
|
26
26
|
import { uploadTempCleanup } from './upload-temp-cleanup';
|
|
@@ -71,9 +71,9 @@ export const filesUploadRoute = new Elysia().post('/api/files/upload', async ({
|
|
|
71
71
|
let resolvedTarget: string;
|
|
72
72
|
let resolvedFinal: string;
|
|
73
73
|
try {
|
|
74
|
-
resolvedTarget = await
|
|
74
|
+
resolvedTarget = await resolveFilePath(targetPathParam);
|
|
75
75
|
const tentativeFinal = join(resolvedTarget, fileNameParam);
|
|
76
|
-
resolvedFinal = await
|
|
76
|
+
resolvedFinal = await resolveFilePath(tentativeFinal);
|
|
77
77
|
} catch (error) {
|
|
78
78
|
const message = error instanceof Error ? error.message : 'Access denied';
|
|
79
79
|
fileAuditLogQueries.logOperation({
|
|
@@ -18,7 +18,7 @@ import { authQueries } from '../database/queries';
|
|
|
18
18
|
import { hashToken } from '../auth/tokens';
|
|
19
19
|
import { projectQueries } from '../database/queries/project-queries';
|
|
20
20
|
import { noteQueries, noteCollectionQueries, noteImageQueries } from '../database/queries/note-queries';
|
|
21
|
-
import { initializeDatabase, closeDatabase } from '../database';
|
|
21
|
+
import { initializeDatabase, closeDatabase, getDatabase } from '../database';
|
|
22
22
|
import { getCollectionNotesDir, resolveNoteImagePath } from '../notes/storage';
|
|
23
23
|
|
|
24
24
|
// Smallest valid GIF89a — `file-type` recognises it from the header alone.
|
|
@@ -55,7 +55,6 @@ beforeAll(async () => {
|
|
|
55
55
|
name: 'Notes Test User',
|
|
56
56
|
color: '#000000',
|
|
57
57
|
avatar: 'test',
|
|
58
|
-
role: 'admin',
|
|
59
58
|
personal_access_token_hash: null,
|
|
60
59
|
created_at: new Date().toISOString()
|
|
61
60
|
});
|
|
@@ -80,7 +79,7 @@ beforeAll(async () => {
|
|
|
80
79
|
last_opened_at: new Date().toISOString()
|
|
81
80
|
});
|
|
82
81
|
projectId = project.id;
|
|
83
|
-
projectQueries.
|
|
82
|
+
projectQueries.list(projectId);
|
|
84
83
|
|
|
85
84
|
collectionId = noteCollectionQueries.create({
|
|
86
85
|
name: 'General',
|
|
@@ -93,8 +92,7 @@ beforeAll(async () => {
|
|
|
93
92
|
|
|
94
93
|
afterAll(async () => {
|
|
95
94
|
await rm(getCollectionNotesDir(collectionId), { recursive: true, force: true });
|
|
96
|
-
|
|
97
|
-
authQueries.deleteUser(userId);
|
|
95
|
+
getDatabase().prepare('DELETE FROM users WHERE id = ?').run(userId);
|
|
98
96
|
projectQueries.deleteProject(projectId);
|
|
99
97
|
closeDatabase();
|
|
100
98
|
});
|
|
@@ -188,41 +186,20 @@ describe('GET /api/notes/images/:id', () => {
|
|
|
188
186
|
expect(res.status).toBe(401);
|
|
189
187
|
});
|
|
190
188
|
|
|
191
|
-
it('denies
|
|
192
|
-
const outsiderId = randomUUID();
|
|
193
|
-
authQueries.createUser({
|
|
194
|
-
id: outsiderId,
|
|
195
|
-
name: 'Outsider',
|
|
196
|
-
color: '#000000',
|
|
197
|
-
avatar: 'test',
|
|
198
|
-
role: 'member',
|
|
199
|
-
personal_access_token_hash: null,
|
|
200
|
-
created_at: new Date().toISOString()
|
|
201
|
-
});
|
|
202
|
-
const outsiderToken = randomUUID();
|
|
203
|
-
authQueries.createSession({
|
|
204
|
-
id: randomUUID(),
|
|
205
|
-
user_id: outsiderId,
|
|
206
|
-
token_hash: hashToken(outsiderToken),
|
|
207
|
-
expires_at: new Date(Date.now() + 86_400_000).toISOString(),
|
|
208
|
-
created_at: new Date().toISOString(),
|
|
209
|
-
last_active_at: new Date().toISOString(),
|
|
210
|
-
user_agent: null,
|
|
211
|
-
ip_address: null,
|
|
212
|
-
source: null
|
|
213
|
-
});
|
|
214
|
-
|
|
189
|
+
it('denies an image whose project was removed from the list', async () => {
|
|
215
190
|
const upload = await notesImagesRoute.handle(uploadRequest(GIF_BYTES, 'private.gif', GIF_BYTES.length));
|
|
216
191
|
const { image } = (await upload.json()) as { image: { id: string } };
|
|
217
192
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
193
|
+
projectQueries.unlist(projectId);
|
|
194
|
+
try {
|
|
195
|
+
const res = await notesImagesRoute.handle(
|
|
196
|
+
new Request(`http://localhost/api/notes/images/${image.id}`, {
|
|
197
|
+
headers: { authorization: `Bearer ${token}` }
|
|
198
|
+
})
|
|
199
|
+
);
|
|
200
|
+
expect(res.status).toBe(403);
|
|
201
|
+
} finally {
|
|
202
|
+
projectQueries.list(projectId);
|
|
203
|
+
}
|
|
227
204
|
});
|
|
228
205
|
});
|
|
@@ -22,7 +22,7 @@ import { join } from 'node:path';
|
|
|
22
22
|
import { fileTypeFromBuffer } from 'file-type';
|
|
23
23
|
|
|
24
24
|
import { debug } from '$shared/utils/logger';
|
|
25
|
-
import { authenticateRequest
|
|
25
|
+
import { authenticateRequest } from './bearer-auth';
|
|
26
26
|
import { noteQueries, noteCollectionQueries, noteImageQueries } from '../database/queries/note-queries';
|
|
27
27
|
import { canAccessCollection } from '../notes/access';
|
|
28
28
|
import {
|
|
@@ -45,9 +45,8 @@ const SNIFF_BYTES = 4100;
|
|
|
45
45
|
|
|
46
46
|
export const notesImagesRoute = new Elysia()
|
|
47
47
|
.post('/api/notes/images/upload', async ({ request, query }) => {
|
|
48
|
-
let identity: AuthIdentity;
|
|
49
48
|
try {
|
|
50
|
-
|
|
49
|
+
authenticateRequest(request);
|
|
51
50
|
} catch (error) {
|
|
52
51
|
const status = (error as { status?: number }).status ?? 401;
|
|
53
52
|
const message = error instanceof Error ? error.message : 'Unauthorized';
|
|
@@ -70,7 +69,7 @@ export const notesImagesRoute = new Elysia()
|
|
|
70
69
|
if (!note) return new Response('Note not found', { status: 404 });
|
|
71
70
|
|
|
72
71
|
const collection = noteCollectionQueries.getById(note.collection_id);
|
|
73
|
-
if (!collection || !canAccessCollection(
|
|
72
|
+
if (!collection || !canAccessCollection(collection)) {
|
|
74
73
|
return new Response('Access denied', { status: 403 });
|
|
75
74
|
}
|
|
76
75
|
|
|
@@ -85,7 +84,7 @@ export const notesImagesRoute = new Elysia()
|
|
|
85
84
|
|
|
86
85
|
// Stream to a temp file with a hard ceiling instead of buffering the body.
|
|
87
86
|
// `fileSize` is a client claim: reading the whole request into memory first
|
|
88
|
-
// would let one
|
|
87
|
+
// would let one request decide how much RAM this process
|
|
89
88
|
// allocates, no matter what the query parameter said.
|
|
90
89
|
const writer = Bun.file(tempPath).writer();
|
|
91
90
|
const header: Uint8Array[] = [];
|
|
@@ -160,9 +159,8 @@ export const notesImagesRoute = new Elysia()
|
|
|
160
159
|
})
|
|
161
160
|
|
|
162
161
|
.get('/api/notes/images/:id', async ({ request, params }) => {
|
|
163
|
-
let identity: AuthIdentity;
|
|
164
162
|
try {
|
|
165
|
-
|
|
163
|
+
authenticateRequest(request);
|
|
166
164
|
} catch (error) {
|
|
167
165
|
const status = (error as { status?: number }).status ?? 401;
|
|
168
166
|
const message = error instanceof Error ? error.message : 'Unauthorized';
|
|
@@ -175,7 +173,7 @@ export const notesImagesRoute = new Elysia()
|
|
|
175
173
|
const collection = noteCollectionQueries.getForNote(img.note_id);
|
|
176
174
|
if (!collection) return new Response('Image not found', { status: 404 });
|
|
177
175
|
|
|
178
|
-
if (!canAccessCollection(
|
|
176
|
+
if (!canAccessCollection(collection)) {
|
|
179
177
|
return new Response('Access denied', { status: 403 });
|
|
180
178
|
}
|
|
181
179
|
|
package/backend/http/ssh-sftp.ts
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* it. Download is here too, so the browser can save a remote file straight to
|
|
7
7
|
* disk without buffering it in JavaScript first.
|
|
8
8
|
*
|
|
9
|
-
* Auth: `Authorization: Bearer <session-token>`, then the
|
|
10
|
-
*
|
|
9
|
+
* Auth: `Authorization: Bearer <session-token>`, then the named SSH connection
|
|
10
|
+
* must exist.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { Elysia } from 'elysia';
|
|
@@ -18,15 +18,10 @@ import { sshConnectionQueries } from '../database/queries';
|
|
|
18
18
|
import { joinRemote, sftpService } from '../ssh/sftp';
|
|
19
19
|
import { authenticateRequest } from './bearer-auth';
|
|
20
20
|
|
|
21
|
-
/** Resolve the caller and confirm
|
|
21
|
+
/** Resolve the caller and confirm the SSH connection they named exists. */
|
|
22
22
|
function authorizeConnection(request: Request, connectionId: string): void {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
connectionId,
|
|
26
|
-
identity.userId,
|
|
27
|
-
identity.role === 'admin'
|
|
28
|
-
);
|
|
29
|
-
if (!connection) {
|
|
23
|
+
authenticateRequest(request);
|
|
24
|
+
if (!sshConnectionQueries.get(connectionId)) {
|
|
30
25
|
throw Object.assign(new Error('ssh connection not found'), { status: 404 });
|
|
31
26
|
}
|
|
32
27
|
}
|