Skip to content

Commit de07ba2

Browse files
committed
test(hub): delete tests that pin implementation
1 parent 78e7dcc commit de07ba2

68 files changed

Lines changed: 200 additions & 7787 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/hub/src/auth.test.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from "bun:test";
22
import { authMethods, isEmailAllowed } from "./auth.js";
3-
import { clientIpHeaders, signInSettings, type HubEnv } from "./env.js";
3+
import { signInSettings, type HubEnv } from "./env.js";
44

55
const ALLOWED = ["@corbits.dev", "friend@example.com"];
66

@@ -22,8 +22,3 @@ test("an allowlist requires Google or email, and admits email/password only when
2222
expect(authMethods(signInSettings({ ...google, AUTH_ALLOWED_EMAILS: "@corbits.dev", SMTP_URL: "smtp://mail.test" } as HubEnv), true)).toEqual({ google: true, emailPassword: true, passwordReset: true, verificationEmail: true });
2323
expect(authMethods(signInSettings(google), false)).toEqual({ google: true, emailPassword: true, passwordReset: false, verificationEmail: false });
2424
});
25-
26-
test("the caller's address comes from the header a detected host sets, and none elsewhere", () => {
27-
expect(clientIpHeaders({ RAILWAY_ENVIRONMENT_ID: "env" })).toEqual(["x-real-ip"]);
28-
expect(clientIpHeaders({})).toBeUndefined();
29-
});

‎apps/hub/src/bitbucket-datacenter/hook.test.ts‎

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -109,40 +109,6 @@ describe("POST /api/hooks/bitbucket-datacenter/:tenantId", () => {
109109
expect(h.accepted[0]).toMatchObject({ workflow: "pr-triage", number: 1, headSha: "3e1552b0", event: "opened", record: { name: "TRI/widgets", source: "bitbucket-datacenter" } });
110110
});
111111

112-
test("a policy triage can't read is queued with its reason and no pack, so the run marks the head failed", async () => {
113-
const h = harness({
114-
async readCheckPack() {
115-
return { status: "invalid", reason: "The policy file has unknown checks: max-size.", path: ".corbits-triage.yml", automatic: ["labels"] };
116-
},
117-
});
118-
expect(await (await h.send(hookRequest(prEvent("pr:opened"), "pr:opened"))).json()).toEqual({ status: "queued" });
119-
expect(h.accepted[0]).toMatchObject({ policyUnreadable: "The policy file has unknown checks: max-size.", automatic: ["labels"] });
120-
expect(h.accepted[0]).not.toHaveProperty("pack");
121-
});
122-
123-
test("a failed queue write is 500 and the redelivery is accepted", async () => {
124-
let fail = true;
125-
const h = harness({
126-
coalescer: {
127-
async accept() {
128-
if (fail) throw new Error("db down");
129-
return "queued";
130-
},
131-
},
132-
});
133-
const body = prEvent("pr:from_ref_updated");
134-
expect((await h.send(hookRequest(body, "pr:from_ref_updated"))).status).toBe(500);
135-
fail = false;
136-
expect(await (await h.send(hookRequest(body, "pr:from_ref_updated"))).json()).toEqual({ status: "queued" });
137-
});
138-
139-
test("a default branch update triages every open pull request again, so a broken or fixed policy reaches them", async () => {
140-
const h = harness();
141-
const refs = JSON.stringify({ eventKey: "repo:refs_changed", repository, changes: [{ ref: { id: "refs/heads/main", displayId: "main", type: "BRANCH" }, type: "UPDATE" }] });
142-
expect((await h.send(hookRequest(refs, "repo:refs_changed"))).status).toBe(202);
143-
expect(h.rechecked).toEqual([["bitbucket-datacenter:TRI/widgets", null]]);
144-
});
145-
146112
test("a merge rechecks the other open pull requests and a branch update syncs the policy file", async () => {
147113
const h = harness();
148114
expect((await h.send(hookRequest(prEvent("pr:merged"), "pr:merged"))).status).toBe(202);

‎apps/hub/src/bitbucket-datacenter/integration.postgres.test.ts‎

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { sql } from "drizzle-orm";
66
import { createEnvKeyCredentialCipher } from "@intx/crypto";
77
import { createDB, runMigrations, schema } from "@intx/db";
88
import { credentialAad } from "@intx/types";
9-
import { connectTriage, createAutomation, grantEnabledKinds } from "../github/automation.js";
10-
import { patchCorbitsTriage, repoRecords, triageNs } from "../github/tenant-config.js";
9+
import { connectTriage, createAutomation } from "../github/automation.js";
10+
import { repoRecords, triageNs } from "../github/tenant-config.js";
1111
import { WEBHOOK_EVENTS } from "./client.js";
1212
import { createBitbucketIntegration } from "./integration.js";
1313
import { HOOK_CREDENTIAL, TOKEN_CREDENTIAL } from "./records.js";
@@ -94,49 +94,6 @@ test("PostgreSQL: enabling a Bitbucket repository grants comment, the one enable
9494
});
9595
}, 120_000);
9696

97-
test("PostgreSQL: a Bitbucket repository named as a GitHub one, in any case, is enabled and the GitHub labels grant stays", async () => {
98-
await withDatabase(async function sameName(db, cipher) {
99-
const integration = createBitbucketIntegration({
100-
db, cipher, onKeyMoved: noKeyPush, async authorize() { return true; },
101-
async stockFetch() { return new Response(null, { status: 500 }); },
102-
publicOrigin: "https://hub.test", fetchImpl: instanceFetch(201), lookup: lookupBitbucket,
103-
onEnabled() {}, async onConnectionChanged() {}, onCredentialsReplaced() {}, now: () => new Date(), log() {},
104-
});
105-
const automation = createAutomation({ db });
106-
await patchCorbitsTriage(db, TENANT, async (ns, tx) => {
107-
await grantEnabledKinds(tx, TENANT, "tri/Widgets", "github", new Date());
108-
return { ...ns, repos: [{ name: "tri/Widgets", connected: true, installationId: 1 }] };
109-
});
110-
const res = await integration.enable(MEMBER, "TRI", "widgets");
111-
expect(res.status).toBe(200);
112-
expect(await automation.automaticKinds(TENANT, "TRI/widgets", "bitbucket-datacenter")).toEqual(["comment"]);
113-
expect(await automation.automaticKinds(TENANT, "tri/Widgets", "github")).toContain("labels");
114-
});
115-
}, 120_000);
116-
117-
test("PostgreSQL: enabling and disabling a Bitbucket repository returns its own row when a GitHub repository has the same name", async () => {
118-
await withDatabase(async function exactName(db, cipher) {
119-
const integration = createBitbucketIntegration({
120-
db, cipher, onKeyMoved: noKeyPush, async authorize() { return true; },
121-
async stockFetch() { return new Response(null, { status: 500 }); },
122-
publicOrigin: "https://hub.test", fetchImpl: instanceFetch(201), lookup: lookupBitbucket,
123-
onEnabled() {}, async onConnectionChanged() {}, onCredentialsReplaced() {}, now: () => new Date(), log() {},
124-
});
125-
const automation = createAutomation({ db });
126-
await patchCorbitsTriage(db, TENANT, async (ns, tx) => {
127-
await grantEnabledKinds(tx, TENANT, "TRI/widgets", "github", new Date());
128-
return { ...ns, repos: [{ name: "TRI/widgets", connected: true, installationId: 1 }] };
129-
});
130-
const enabled = await integration.enable(MEMBER, "TRI", "widgets");
131-
expect(enabled.status).toBe(200);
132-
expect(await enabled.json()).toMatchObject({ repository: { source: "bitbucket-datacenter", enabled: true } });
133-
expect(await automation.automaticKinds(TENANT, "TRI/widgets", "github")).toContain("labels");
134-
const disabled = await integration.disable(MEMBER, "TRI", "widgets");
135-
expect(disabled.status).toBe(200);
136-
expect(await disabled.json()).toMatchObject({ repository: { source: "bitbucket-datacenter" } });
137-
});
138-
}, 120_000);
139-
14097
test("PostgreSQL: a hand-made webhook needs use on the hook credential, its setup stays readable while triage is on, and not once it is off", async () => {
14198
await withDatabase(async function manualWebhook(db, cipher) {
14299
let hookUse = false;

‎apps/hub/src/bitbucket-datacenter/integration.test.ts‎

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ import { createBitbucketIntegration } from "./integration.js";
77
async function noKeyPush(): Promise<void> {}
88

99
const MEMBER = { tenantId: "tnt_bitbucket", principalId: "prn_user" };
10-
const BODY = { baseUrl: "http://git.internal:7990", token: "token" };
1110
const CONNECTED = { config: { corbitsTriage: { bitbucketDatacenter: { baseUrl: "http://git.internal:7990", user: "triage" } } } };
1211

1312
function unreachable(name: string): never {
1413
throw new Error(`${name} should not be called`);
1514
}
1615

17-
function integration(address: string, options: { allowlist?: readonly string[]; tenant?: unknown; fetched?: string[] } = {}) {
16+
function integration(address: string) {
1817
return createBitbucketIntegration({
1918
db: {
2019
query: {
21-
tenant: { async findFirst() { return options.tenant; } },
20+
tenant: { async findFirst() { return CONNECTED; } },
2221
credential: { async findFirst() { return { id: "crd_bb", tenantId: MEMBER.tenantId, status: "active", principalId: null }; } },
2322
},
2423
} as unknown as DB["db"],
@@ -27,39 +26,19 @@ function integration(address: string, options: { allowlist?: readonly string[];
2726
async authorize() { return true; },
2827
stockFetch: () => unreachable("stock"),
2928
publicOrigin: "https://hub.test",
30-
fetchImpl: async function fetched(input: string | URL | Request) {
31-
if (!options.fetched) unreachable("fetch");
32-
options.fetched.push(String(input));
33-
throw new TypeError("unreachable");
34-
} as unknown as typeof fetch,
29+
fetchImpl: (() => unreachable("fetch")) as unknown as typeof fetch,
3530
onEnabled() {},
3631
async onConnectionChanged() {},
3732
onCredentialsReplaced() {},
3833
now: () => new Date(),
3934
log() {},
40-
egressAllowlist: options.allowlist ?? [],
35+
egressAllowlist: [],
4136
async lookup() { return [{ address, family: 4 }]; },
4237
});
4338
}
4439

45-
test("connect refuses a host that resolves to loopback or a private address before the token is tried", async () => {
46-
for (const address of ["127.0.0.1", "10.0.0.5"]) {
47-
const res = await integration(address).connect(BODY, MEMBER, new Request("https://hub.test/connection"));
48-
expect(res.status).toBe(400);
49-
const body = await res.json() as { error: { code: string; message: string } };
50-
expect(body.error.code).toBe("invalid_request");
51-
expect(body.error.message).toContain("allowlist it");
52-
}
53-
});
54-
55-
test("connect tries the token at the checked address of a listed host that resolves only to a private address", async () => {
56-
const fetched: string[] = [];
57-
await integration("10.0.0.5", { allowlist: ["git.internal"], fetched }).connect(BODY, MEMBER, new Request("https://hub.test/connection"));
58-
expect(fetched).toEqual(["http://10.0.0.5:7990/rest/api/1.0/application-properties"]);
59-
});
60-
6140
test("a stored host that now resolves to a private address is refused when the token would be sent, and still shown", async () => {
62-
const refused = integration("10.0.0.5", { tenant: CONNECTED });
41+
const refused = integration("10.0.0.5");
6342
const res = await refused.repositories(MEMBER);
6443
expect(res.status).toBe(409);
6544
expect(((await res.json()) as { error: { code: string } }).error.code).toBe("bitbucket_datacenter_host_refused");

‎apps/hub/src/bitbucket-datacenter/normalize.test.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,4 @@ describe("normalizeBitbucket", () => {
4141
if (intake?.kind !== "pr") throw new Error(`${eventKey} gave ${JSON.stringify(intake)}`);
4242
expect(triageEventOf(intake.mail)).toBe(expected);
4343
});
44-
45-
test("an edit of a comment's text wakes nothing", () => {
46-
expect(normalizeBitbucket("pr:comment:edited", "d", prEvent("pr:comment:edited", { comment: { id: 4, text: "Rename it, please." }, previousComment: "Rename it." }))).toBeNull();
47-
});
48-
49-
test("triage's own comments and comments on a pull request no longer open are ignored", () => {
50-
expect(normalizeBitbucket("pr:comment:added", "d", prEvent("pr:comment:added", { comment: { text: "[corbits-triage]: #%7B%7D\nTriage: looks fine." } }))).toBeNull();
51-
expect(normalizeBitbucket("pr:comment:added", "d", prEvent("pr:comment:added", { comment: { text: "[corbits-action]: #e1\nHello" } }))).toBeNull();
52-
expect(normalizeBitbucket("pr:comment:added", "d", prEvent("pr:comment:added", { pullRequest: pullRequest({ state: "MERGED" }), comment: { text: "late" } }))).toBeNull();
53-
});
5444
});

0 commit comments

Comments
 (0)