-
Notifications
You must be signed in to change notification settings - Fork 3
feat(federation): env-gated unsigned DuckDB extensions (+ Firebird proposal) #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2374605
feat(federation): allow env-gated unsigned DuckDB extension installs
3d29def
docs(openspec): add Firebird connection type proposal
3f2de1a
chore(openspec): archive add-duckdb-federation-console
af7aafd
feat(connections): add env-gated Firebird connection type
e4e89c6
test(connections): cover Firebird env gates, attach DSN, and API gate
0a37651
fix(connections): harden Firebird gate and honor custom extension sou…
5013925
chore(openspec): archive update-admin-password-reset-on-startup
4fdce8e
fix(firebird): attach via ATTACH options and gate unsigned via Firebi…
dc5a205
fix(connections): gate Firebird connection test behind capability flag
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
131 changes: 131 additions & 0 deletions
131
apps/api/src/routes/connections-firebird.integration.test.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
|
|
||
| const mocks = vi.hoisted(() => ({ | ||
| connectDB: vi.fn(), | ||
| customFirebirdEnabled: vi.fn(() => false), | ||
| projectFindById: vi.fn(), | ||
| connectionFindOne: vi.fn(), | ||
| connectionCreate: vi.fn(), | ||
| connectionFindOneAndUpdate: vi.fn(), | ||
| testSingleConnection: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("@archmax/core/infra/db", () => ({ connectDB: mocks.connectDB })); | ||
| vi.mock("@archmax/core/config/env", () => ({ | ||
| getEnv: vi.fn(() => ({ ENCRYPTION_KEY: "" })), | ||
| customFirebirdEnabled: mocks.customFirebirdEnabled, | ||
| })); | ||
| vi.mock("@archmax/core/models/index", () => ({ | ||
| Connection: { | ||
| findOne: mocks.connectionFindOne, | ||
| create: mocks.connectionCreate, | ||
| findOneAndUpdate: mocks.connectionFindOneAndUpdate, | ||
| }, | ||
| Project: { findById: mocks.projectFindById }, | ||
| CONNECTION_TYPES: ["postgres", "mysql", "mssql", "sqlite", "duckdb", "iceberg", "firebird"], | ||
| SLUG_PATTERN: /^[a-zA-Z_][a-zA-Z0-9_]*$/, | ||
| slugifyConnectionName: (s: string) => s.toLowerCase(), | ||
| })); | ||
| vi.mock("@archmax/core/services/duckdb", () => ({ | ||
| deleteProjectDuckdbFile: vi.fn(), | ||
| disposeProjectInstance: vi.fn(), | ||
| getProjectInstance: vi.fn(), | ||
| testSingleConnection: mocks.testSingleConnection, | ||
| withQueryTimeout: vi.fn(async (_db: unknown, op: () => Promise<unknown>) => op()), | ||
| })); | ||
|
|
||
| import { createTestApp, jsonBody } from "../test-utils/api-client"; | ||
| import connectionsRoute from "./connections"; | ||
|
|
||
| const app = createTestApp("/api/projects/:projectId/connections", connectionsRoute); | ||
| const BASE = "/api/projects/proj1/connections"; | ||
|
|
||
| function postFirebird(charset?: string) { | ||
| return app.request(BASE, { | ||
| method: "POST", | ||
| headers: { "content-type": "application/json" }, | ||
| body: JSON.stringify({ | ||
| name: "fb", | ||
| type: "firebird", | ||
| connectionConfig: { host: "h", database: "d", user: "u", password: "p", ...(charset ? { charset } : {}) }, | ||
| }), | ||
| }); | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| mocks.customFirebirdEnabled.mockReturnValue(false); | ||
| mocks.projectFindById.mockReturnValue({ lean: vi.fn().mockResolvedValue({ _id: "proj1" }) }); | ||
| }); | ||
|
|
||
| describe("connections route — firebird gate", () => { | ||
| it("rejects creating a firebird connection with 400 when disabled", async () => { | ||
| const res = await postFirebird(); | ||
| expect(res.status).toBe(400); | ||
| const body = await jsonBody<{ error: string }>(res); | ||
| expect(body.error).toMatch(/not enabled/i); | ||
| expect(mocks.connectionCreate).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("accepts creating a firebird connection (incl. charset) when enabled", async () => { | ||
| mocks.customFirebirdEnabled.mockReturnValue(true); | ||
| mocks.connectionCreate.mockResolvedValue({ | ||
| toObject: () => ({ _id: "c1", name: "fb", type: "firebird", connectionConfig: { charset: "WIN1252" } }), | ||
| }); | ||
| const res = await postFirebird("WIN1252"); | ||
| expect(res.status).toBe(201); | ||
| expect(mocks.connectionCreate).toHaveBeenCalledTimes(1); | ||
| const created = mocks.connectionCreate.mock.calls[0][0] as { connectionConfig: { charset?: string } }; | ||
| expect(created.connectionConfig.charset).toBe("WIN1252"); | ||
| }); | ||
|
|
||
| it("rejects updating a connection to firebird with 400 when disabled", async () => { | ||
| mocks.connectionFindOne.mockReturnValue({ | ||
| lean: vi.fn().mockResolvedValue({ _id: "c1", project: "proj1", connectionConfig: {} }), | ||
| }); | ||
| const res = await app.request(`${BASE}/c1`, { | ||
| method: "PUT", | ||
| headers: { "content-type": "application/json" }, | ||
| body: JSON.stringify({ type: "firebird" }), | ||
| }); | ||
| expect(res.status).toBe(400); | ||
| expect(mocks.connectionFindOneAndUpdate).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("rejects a partial PUT (no type) on an existing firebird connection when disabled", async () => { | ||
| // `updateSchema` is partial, so a PUT can omit `type`. The gate must | ||
| // still fire based on the stored connection's type. | ||
| mocks.connectionFindOne.mockReturnValue({ | ||
| lean: vi.fn().mockResolvedValue({ _id: "c1", project: "proj1", type: "firebird", connectionConfig: {} }), | ||
| }); | ||
| const res = await app.request(`${BASE}/c1`, { | ||
| method: "PUT", | ||
| headers: { "content-type": "application/json" }, | ||
| body: JSON.stringify({ description: "tweaked" }), | ||
| }); | ||
| expect(res.status).toBe(400); | ||
| expect(mocks.connectionFindOneAndUpdate).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("rejects testing a stored firebird connection with 400 when disabled", async () => { | ||
| // `POST /:id/test` must not run the firebird install/attach branch (which | ||
| // loads the unsigned extension) while the capability is off. | ||
| mocks.connectionFindOne.mockResolvedValue({ _id: "c1", project: "proj1", type: "firebird" }); | ||
| const res = await app.request(`${BASE}/c1/test`, { method: "POST" }); | ||
| expect(res.status).toBe(400); | ||
| const body = await jsonBody<{ error: string }>(res); | ||
| expect(body.error).toMatch(/not enabled/i); | ||
| expect(mocks.testSingleConnection).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("tests a stored firebird connection when enabled", async () => { | ||
| mocks.customFirebirdEnabled.mockReturnValue(true); | ||
| mocks.connectionFindOne.mockResolvedValue({ _id: "c1", project: "proj1", type: "firebird" }); | ||
| mocks.testSingleConnection.mockResolvedValue({ | ||
| connect: vi.fn().mockResolvedValue({ run: vi.fn(), disconnectSync: vi.fn() }), | ||
| }); | ||
| const res = await app.request(`${BASE}/c1/test`, { method: "POST" }); | ||
| expect(res.status).toBe(200); | ||
| expect(mocks.testSingleConnection).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.