@app-vitals/agent-admin 1.23.0 → 1.25.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/package.json +2 -2
- package/src/admin-ui-github-enterprise-pages.ts +47 -13
- package/src/admin-ui-github-enterprise-pages.unit.test.ts +40 -1
- package/src/admin-ui-github-enterprise.smoke.test.ts +73 -0
- package/src/admin-ui-github-enterprise.ts +5 -2
- package/src/fixtures/github-enterprise-cassette.json +879 -0
- package/src/github-enterprise-api.integration.test.ts +53 -0
- package/src/github-enterprise-client.integration.test.ts +176 -4
- package/src/github-enterprise-client.ts +136 -2
- package/src/github-enterprise-client.unit.test.ts +55 -0
- package/src/github-enterprise-isolation.unit.test.ts +24 -0
- package/src/github-enterprise-pem-upload.ts +47 -0
- package/src/github-enterprise-pem-upload.unit.test.ts +106 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/github-enterprise-pem-upload.unit.test.ts
|
|
3
|
+
* Unit tests for the paste-or-upload private key parsing (GHE-1.12).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, expect, it } from "bun:test";
|
|
7
|
+
import { generateKeyPairSync } from "node:crypto";
|
|
8
|
+
import {
|
|
9
|
+
MAX_PEM_BYTES,
|
|
10
|
+
readPrivateKeyField,
|
|
11
|
+
} from "./github-enterprise-pem-upload.ts";
|
|
12
|
+
|
|
13
|
+
const { privateKey: PEM } = generateKeyPairSync("rsa", {
|
|
14
|
+
modulusLength: 2048,
|
|
15
|
+
privateKeyEncoding: { type: "pkcs8", format: "pem" },
|
|
16
|
+
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const formWith = (entries: Record<string, string | File>) => {
|
|
20
|
+
const f = new FormData();
|
|
21
|
+
for (const [k, v] of Object.entries(entries)) f.set(k, v);
|
|
22
|
+
return f;
|
|
23
|
+
};
|
|
24
|
+
const pemFile = (body: string) =>
|
|
25
|
+
new File([body], "app.private-key.pem", { type: "application/x-pem-file" });
|
|
26
|
+
|
|
27
|
+
describe("readPrivateKeyField", () => {
|
|
28
|
+
it("returns an uploaded valid PEM unchanged", async () => {
|
|
29
|
+
const r = await readPrivateKeyField(
|
|
30
|
+
formWith({ privateKeyFile: pemFile(PEM) }),
|
|
31
|
+
);
|
|
32
|
+
expect(r).toEqual({ ok: true, pem: PEM });
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("accepts RSA and EC private key headers", async () => {
|
|
36
|
+
for (const kind of ["RSA ", "EC ", ""]) {
|
|
37
|
+
const body = `-----BEGIN ${kind}PRIVATE KEY-----\nQUJD\n-----END ${kind}PRIVATE KEY-----`;
|
|
38
|
+
const r = await readPrivateKeyField(
|
|
39
|
+
formWith({ privateKeyFile: pemFile(body) }),
|
|
40
|
+
);
|
|
41
|
+
expect(r.ok).toBe(true);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("prefers the file over pasted text", async () => {
|
|
46
|
+
const r = await readPrivateKeyField(
|
|
47
|
+
formWith({ privateKeyFile: pemFile(PEM), privateKey: "pasted" }),
|
|
48
|
+
);
|
|
49
|
+
expect(r).toEqual({ ok: true, pem: PEM });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("passes pasted text through unchanged when no file is chosen", async () => {
|
|
53
|
+
const r = await readPrivateKeyField(
|
|
54
|
+
formWith({ privateKey: PEM, privateKeyFile: new File([], "") }),
|
|
55
|
+
);
|
|
56
|
+
expect(r).toEqual({ ok: true, pem: PEM });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("stores CRLF uploads and pastes identically (LF)", async () => {
|
|
60
|
+
const crlf = PEM.replace(/\n/g, "\r\n");
|
|
61
|
+
const up = await readPrivateKeyField(
|
|
62
|
+
formWith({ privateKeyFile: pemFile(crlf) }),
|
|
63
|
+
);
|
|
64
|
+
const paste = await readPrivateKeyField(formWith({ privateKey: crlf }));
|
|
65
|
+
expect(up).toEqual({ ok: true, pem: PEM });
|
|
66
|
+
expect(paste).toEqual(up);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("rejects a non-PEM file without echoing its content", async () => {
|
|
70
|
+
const r = await readPrivateKeyField(
|
|
71
|
+
formWith({ privateKeyFile: pemFile("hunter2-SECRET not a key") }),
|
|
72
|
+
);
|
|
73
|
+
expect(r.ok).toBe(false);
|
|
74
|
+
if (!r.ok) {
|
|
75
|
+
expect(r.error).toContain("not a PEM private key");
|
|
76
|
+
expect(r.error).not.toContain("hunter2");
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("rejects a public key or certificate PEM", async () => {
|
|
81
|
+
for (const kind of ["PUBLIC KEY", "CERTIFICATE"]) {
|
|
82
|
+
const r = await readPrivateKeyField(
|
|
83
|
+
formWith({
|
|
84
|
+
privateKeyFile: pemFile(
|
|
85
|
+
`-----BEGIN ${kind}-----\nQUJD\n-----END ${kind}-----`,
|
|
86
|
+
),
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
expect(r.ok).toBe(false);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("rejects an oversized file", async () => {
|
|
94
|
+
const big = `${PEM}${"A".repeat(MAX_PEM_BYTES)}`;
|
|
95
|
+
const r = await readPrivateKeyField(
|
|
96
|
+
formWith({ privateKeyFile: pemFile(big) }),
|
|
97
|
+
);
|
|
98
|
+
expect(r.ok).toBe(false);
|
|
99
|
+
if (!r.ok) expect(r.error).toContain("too large");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("rejects when neither a file nor text is provided", async () => {
|
|
103
|
+
const r = await readPrivateKeyField(formWith({ privateKey: " " }));
|
|
104
|
+
expect(r.ok).toBe(false);
|
|
105
|
+
});
|
|
106
|
+
});
|