feat: release 2.7.1
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { describe, expect, spyOn, test } from "bun:test";
|
||||
import { runCommand } from "citty";
|
||||
import { listAuditEvents } from "../../command/audit";
|
||||
import { main } from "../../command/main";
|
||||
import { getOperation, listOperations } from "../../command/operations";
|
||||
@@ -15,6 +16,7 @@ import {
|
||||
users,
|
||||
} from "../../command/users";
|
||||
import type { ApiRequestInit } from "../../lib/api";
|
||||
import * as api from "../../lib/api";
|
||||
|
||||
type Call = { path: string; init?: ApiRequestInit };
|
||||
|
||||
@@ -298,15 +300,24 @@ describe("user administration commands", () => {
|
||||
"kubernetes:read,kubernetes:write",
|
||||
);
|
||||
expect(create.args?.["expires-days"]?.description).toContain("none");
|
||||
expect(create.args?.workspace?.alias).toBe("w");
|
||||
expect(create.args?.["expires-days"]?.alias).toBe("e");
|
||||
expect(create.meta?.description).toContain("--expireDays=none");
|
||||
expect(ls.meta?.description).toContain("optional positional username");
|
||||
await expect(
|
||||
create.run?.({
|
||||
args: { username: "alice", capabilities: "invalid", "expires-days": "90" },
|
||||
args: {
|
||||
_: [],
|
||||
username: "alice",
|
||||
capabilities: "invalid",
|
||||
"expires-days": "90",
|
||||
},
|
||||
} as never),
|
||||
).rejects.toThrow("kubernetes:read,kubernetes:write");
|
||||
await expect(
|
||||
create.run?.({
|
||||
args: {
|
||||
_: [],
|
||||
username: "alice",
|
||||
capabilities: "kubernetes:read",
|
||||
"expires-days": "NaN",
|
||||
@@ -314,6 +325,124 @@ describe("user administration commands", () => {
|
||||
} as never),
|
||||
).rejects.toThrow("1 to 365, or none");
|
||||
});
|
||||
|
||||
test("parses both API key creation forms and retains username position", async () => {
|
||||
const calls: Call[] = [];
|
||||
const request = spyOn(api, "apiRequest").mockImplementation((async <T>(
|
||||
path: string,
|
||||
init?: ApiRequestInit,
|
||||
) => {
|
||||
calls.push({ path, init });
|
||||
return (
|
||||
init
|
||||
? {
|
||||
id: "fake-key-id-123456",
|
||||
username: "dmgnr",
|
||||
capabilities:
|
||||
init.json &&
|
||||
(init.json as { capabilities: string[] }).capabilities,
|
||||
workspace: "kuber-server",
|
||||
token: "fake-token-never-real",
|
||||
disabled: false,
|
||||
}
|
||||
: { username: "dmgnr", roles: ["admin"], disabled: false }
|
||||
) as T;
|
||||
}) as typeof api.apiRequest);
|
||||
const log = spyOn(console, "log").mockImplementation(() => {});
|
||||
const keyCommand = (users.subCommands as Record<string, any>).keys;
|
||||
const create = keyCommand.subCommands.create;
|
||||
try {
|
||||
await runCommand(users, {
|
||||
rawArgs: [
|
||||
"keys",
|
||||
"create",
|
||||
"--capabilities",
|
||||
"kubernetes:write",
|
||||
"--workspace",
|
||||
"kuber-server",
|
||||
"--expires-days",
|
||||
"none",
|
||||
"dmgnr",
|
||||
],
|
||||
});
|
||||
expect(calls[1]?.path).toBe("/users/dmgnr/keys");
|
||||
expect(calls[1]?.init?.json).toEqual({
|
||||
capabilities: ["kubernetes:write"],
|
||||
workspace: "kuber-server",
|
||||
});
|
||||
calls.length = 0;
|
||||
await runCommand(users, {
|
||||
rawArgs: [
|
||||
"keys",
|
||||
"create",
|
||||
"--capabilities",
|
||||
"kubernetes:read",
|
||||
"--expires-days",
|
||||
"30",
|
||||
"dmgnr",
|
||||
],
|
||||
});
|
||||
expect(
|
||||
(calls[1]?.init?.json as { expiresAt: string }).expiresAt,
|
||||
).toBeString();
|
||||
calls.length = 0;
|
||||
await runCommand(users, {
|
||||
rawArgs: [
|
||||
"keys",
|
||||
"create",
|
||||
"-w",
|
||||
"kuber-server",
|
||||
"-e",
|
||||
"none",
|
||||
"dmgnr",
|
||||
"kubernetes:write,kubernetes:read",
|
||||
],
|
||||
});
|
||||
expect(calls[1]?.path).toBe("/users/dmgnr/keys");
|
||||
expect(calls[1]?.init?.json).toEqual({
|
||||
capabilities: ["kubernetes:write", "kubernetes:read"],
|
||||
workspace: "kuber-server",
|
||||
});
|
||||
|
||||
await expect(
|
||||
create.run?.({ args: { username: "dmgnr" } } as never),
|
||||
).rejects.toThrow("Provide capabilities");
|
||||
await expect(
|
||||
create.run?.({
|
||||
args: {
|
||||
username: "dmgnr",
|
||||
capabilities: "kubernetes:read",
|
||||
_: ["dmgnr", "kubernetes:write"],
|
||||
},
|
||||
} as never),
|
||||
).rejects.toThrow("not both");
|
||||
await expect(
|
||||
create.run?.({
|
||||
args: {
|
||||
username: "dmgnr",
|
||||
capabilities: "kubernetes:read",
|
||||
"expires-days": "0",
|
||||
},
|
||||
} as never),
|
||||
).rejects.toThrow("1 to 365, or none");
|
||||
calls.length = 0;
|
||||
await runCommand(users, {
|
||||
rawArgs: [
|
||||
"keys",
|
||||
"create",
|
||||
"dmgnr",
|
||||
"--capabilities",
|
||||
"kubernetes:read",
|
||||
],
|
||||
});
|
||||
expect(
|
||||
(calls[1]?.init?.json as { expiresAt: string }).expiresAt,
|
||||
).toBeString();
|
||||
} finally {
|
||||
request.mockRestore();
|
||||
log.mockRestore();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const operation = {
|
||||
|
||||
Reference in New Issue
Block a user