feat(lake-lamp): publish canonical code route guard
This commit is contained in:
parent
e80ee6d966
commit
e3cc40ecd3
3 changed files with 109 additions and 0 deletions
|
|
@ -0,0 +1,42 @@
|
|||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import {
|
||||
currentCodeChannelRepositories,
|
||||
normalizeCodeChannelRepository,
|
||||
publishLeaseResource,
|
||||
} from "./code-channel-policy.mjs";
|
||||
|
||||
test("HTTPS, .git and repo forms resolve to one repository identity", () => {
|
||||
const expected =
|
||||
"repo://guanghulab.com/code/bingshuo/guanghu-ice-heart";
|
||||
assert.equal(
|
||||
normalizeCodeChannelRepository(
|
||||
"https://guanghulab.com/code/bingshuo/guanghu-ice-heart.git",
|
||||
),
|
||||
expected,
|
||||
);
|
||||
assert.equal(normalizeCodeChannelRepository(expected), expected);
|
||||
assert.equal(publishLeaseResource(expected), `${expected}#main`);
|
||||
});
|
||||
|
||||
test("only the two current repositories are allowed", () => {
|
||||
assert.equal(currentCodeChannelRepositories.length, 2);
|
||||
for (const invalid of [
|
||||
"https://guanghulab.com/fifth-domain/bingshuo/fifth-domain.git",
|
||||
"https://guanghubingshuo.com/code/bingshuo/guanghulab.git",
|
||||
"repo://guanghulab.com/code/bingshuo/unknown",
|
||||
]) {
|
||||
assert.throws(() => normalizeCodeChannelRepository(invalid));
|
||||
}
|
||||
});
|
||||
|
||||
test("credential-bearing remotes are rejected", () => {
|
||||
assert.throws(
|
||||
() =>
|
||||
normalizeCodeChannelRepository(
|
||||
"https://user:secret@guanghulab.com/code/bingshuo/guanghu-ice-heart.git",
|
||||
),
|
||||
/CREDENTIALS_FORBIDDEN/u,
|
||||
);
|
||||
});
|
||||
|
||||
Loading…
Reference in a new issue