@app-vitals/agent-admin 1.63.0 → 1.65.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/openapi.json +1 -1
- package/openapi.platform.json +1 -1
- package/package.json +2 -2
- package/src/admin-boot.ts +23 -0
- package/src/admin-ui-pages.ts +30 -6
- package/src/admin-ui-pages.unit.test.ts +36 -1
- package/src/admin-ui-settings-layout.ts +11 -0
- package/src/admin-ui-slack-config-token-flows.smoke.test.ts +346 -0
- package/src/admin-ui-slack-config-token-pages.ts +136 -0
- package/src/admin-ui-slack-config-token-pages.unit.test.ts +84 -0
- package/src/admin-ui-slack-config-token.smoke.test.ts +287 -0
- package/src/admin-ui-slack-config-token.ts +251 -0
- package/src/admin-ui.ts +90 -4
- package/src/agent-deletion.ts +39 -5
- package/src/agent-deletion.unit.test.ts +141 -0
- package/src/agents-api.smoke.test.ts +107 -1
- package/src/agents-api.ts +12 -4
- package/src/openapi-schemas.ts +4 -2
- package/src/slack-config-token-resolve.unit.test.ts +108 -0
- package/src/slack-config-token.ts +51 -0
- package/src/slack-provisioning-service.integration.test.ts +189 -1
- package/src/slack-provisioning-service.ts +43 -9
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/admin-ui-slack-config-token-pages.ts
|
|
3
|
+
* Render function for Settings > Slack config token (SCT-3.1).
|
|
4
|
+
* Pure string -> string; routes live in admin-ui-slack-config-token.ts.
|
|
5
|
+
*
|
|
6
|
+
* The page only ever receives metadata (configured, last rotated, last error,
|
|
7
|
+
* team/user): there is no field through which a refresh or access token could
|
|
8
|
+
* reach the markup. The paste input is never pre-filled.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { renderAdminPage } from "./admin-ui-layout.ts";
|
|
12
|
+
import {
|
|
13
|
+
buildSettingsNav,
|
|
14
|
+
renderSettingsLayout,
|
|
15
|
+
type SettingsNav,
|
|
16
|
+
} from "./admin-ui-settings-layout.ts";
|
|
17
|
+
import { escapeHtml } from "./admin-ui-styles.ts";
|
|
18
|
+
|
|
19
|
+
export const ADMIN_SLACK_CONFIG_TOKEN_PATH =
|
|
20
|
+
"/admin/settings/slack-config-token";
|
|
21
|
+
|
|
22
|
+
const BASE = ADMIN_SLACK_CONFIG_TOKEN_PATH;
|
|
23
|
+
|
|
24
|
+
export interface SlackConfigTokenScopeOption {
|
|
25
|
+
value: string;
|
|
26
|
+
label: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Display-only status of the row at the selected scope. */
|
|
30
|
+
export interface SlackConfigTokenStatusView {
|
|
31
|
+
lastRotatedAt: Date | null;
|
|
32
|
+
lastError: string | null;
|
|
33
|
+
slackTeamId: string | null;
|
|
34
|
+
slackUserId: string | null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface SlackConfigTokenPageOpts {
|
|
38
|
+
userEmail: string;
|
|
39
|
+
isAdmin?: boolean;
|
|
40
|
+
nav?: SettingsNav;
|
|
41
|
+
/** Accounts the caller may pick; the deployment-wide option only for admins. */
|
|
42
|
+
accountOptions: SlackConfigTokenScopeOption[];
|
|
43
|
+
/** Selected scope ("" = deployment-wide). */
|
|
44
|
+
accountId: string;
|
|
45
|
+
/** Row at the selected scope, or null when not configured. */
|
|
46
|
+
status: SlackConfigTokenStatusView | null;
|
|
47
|
+
/** SHIPWRIGHT_ENCRYPTION_KEY is set; without it saving is refused. */
|
|
48
|
+
encryptionConfigured: boolean;
|
|
49
|
+
error?: string;
|
|
50
|
+
notice?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function accountPicker(o: SlackConfigTokenPageOpts): string {
|
|
54
|
+
const opts = o.accountOptions
|
|
55
|
+
.map(
|
|
56
|
+
(a) =>
|
|
57
|
+
`<option value="${escapeHtml(a.value)}"${a.value === o.accountId ? " selected" : ""}>${escapeHtml(a.label)}</option>`,
|
|
58
|
+
)
|
|
59
|
+
.join("");
|
|
60
|
+
return `<form method="GET" action="${BASE}" style="display:flex;gap:8px;align-items:end;flex-wrap:wrap">
|
|
61
|
+
<label>Account <select name="accountId" class="form-input">${opts}</select></label>
|
|
62
|
+
<button type="submit" class="btn btn-secondary">Open</button>
|
|
63
|
+
</form>`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function scopeField(o: SlackConfigTokenPageOpts): string {
|
|
67
|
+
return `<input type="hidden" name="accountId" value="${escapeHtml(o.accountId)}" />`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const when = (d: Date | null): string =>
|
|
71
|
+
d ? escapeHtml(d.toISOString()) : "never";
|
|
72
|
+
|
|
73
|
+
function statusCard(o: SlackConfigTokenPageOpts): string {
|
|
74
|
+
const s = o.status;
|
|
75
|
+
if (!s) {
|
|
76
|
+
return `<p class="help-text">Not configured for this scope.</p>`;
|
|
77
|
+
}
|
|
78
|
+
const team =
|
|
79
|
+
s.slackTeamId || s.slackUserId
|
|
80
|
+
? `${escapeHtml(s.slackTeamId ?? "?")} / ${escapeHtml(s.slackUserId ?? "?")}`
|
|
81
|
+
: "unknown";
|
|
82
|
+
return `<table class="data-table"><tbody>
|
|
83
|
+
<tr><th>Configured</th><td>Yes</td></tr>
|
|
84
|
+
<tr><th>Last rotated</th><td>${when(s.lastRotatedAt)}</td></tr>
|
|
85
|
+
<tr><th>Last error</th><td>${s.lastError ? escapeHtml(s.lastError) : "none"}</td></tr>
|
|
86
|
+
<tr><th>Team / user</th><td>${team}</td></tr>
|
|
87
|
+
</tbody></table>
|
|
88
|
+
<div style="display:flex;gap:8px;margin-top:12px">
|
|
89
|
+
<form method="POST" action="${BASE}/rotate">${scopeField(o)}<button type="submit" class="btn btn-secondary">Rotate now</button></form>
|
|
90
|
+
<form method="POST" action="${BASE}/clear">${scopeField(o)}<button type="submit" class="btn btn-danger">Clear token</button></form>
|
|
91
|
+
</div>`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function renderSlackConfigTokenPage(
|
|
95
|
+
o: SlackConfigTokenPageOpts,
|
|
96
|
+
): string {
|
|
97
|
+
const error = o.error
|
|
98
|
+
? `<div class="alert alert-error">${escapeHtml(o.error)}</div>`
|
|
99
|
+
: "";
|
|
100
|
+
const notice = o.notice
|
|
101
|
+
? `<div class="alert alert-success">${escapeHtml(o.notice)}</div>`
|
|
102
|
+
: "";
|
|
103
|
+
const encryptionWarning = o.encryptionConfigured
|
|
104
|
+
? ""
|
|
105
|
+
: `<div class="alert alert-error">SHIPWRIGHT_ENCRYPTION_KEY is not configured, so a Slack config token cannot be saved. Set it to a 64-character hex string (openssl rand -hex 32) and restart.</div>`;
|
|
106
|
+
return renderAdminPage({
|
|
107
|
+
title: "Slack config token — Settings — Shipwright Admin",
|
|
108
|
+
body: renderSettingsLayout({
|
|
109
|
+
userName: o.userEmail,
|
|
110
|
+
title: "Slack config token",
|
|
111
|
+
nav:
|
|
112
|
+
o.nav ??
|
|
113
|
+
buildSettingsNav({ githubEnterprise: true, slackConfigToken: true }),
|
|
114
|
+
active: BASE,
|
|
115
|
+
isAdmin: o.isAdmin ?? false,
|
|
116
|
+
body: `${error}${notice}${encryptionWarning}
|
|
117
|
+
<div class="card">
|
|
118
|
+
<p class="help-text">The Slack App Configuration token used to create and update agent Slack apps. A deployment-wide token is the default; an account's own token overrides it. Tokens are stored encrypted and never shown.</p>
|
|
119
|
+
${accountPicker(o)}
|
|
120
|
+
</div>
|
|
121
|
+
<div class="card">
|
|
122
|
+
<div class="card-title">Status</div>
|
|
123
|
+
${statusCard(o)}
|
|
124
|
+
</div>
|
|
125
|
+
<div class="card">
|
|
126
|
+
<div class="card-title">${o.status ? "Replace refresh token" : "Add refresh token"}</div>
|
|
127
|
+
<form method="POST" action="${BASE}/save" style="display:grid;gap:8px;max-width:480px">
|
|
128
|
+
${scopeField(o)}
|
|
129
|
+
<label>Refresh token (xoxe-1-...) <input type="password" name="refreshToken" class="form-input" autocomplete="off" required placeholder="xoxe-1-..." /></label>
|
|
130
|
+
<p class="help-text">Generate it at api.slack.com/apps under Your App Configuration Tokens. It is validated by rotating it once; the rotated pair is stored.</p>
|
|
131
|
+
<div><button type="submit" class="btn btn-primary"${o.encryptionConfigured ? "" : " disabled"}>Validate and save</button></div>
|
|
132
|
+
</form>
|
|
133
|
+
</div>`,
|
|
134
|
+
}),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/admin-ui-slack-config-token-pages.unit.test.ts
|
|
3
|
+
* Unit tests for renderSlackConfigTokenPage (SCT-3.1).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, expect, it } from "bun:test";
|
|
7
|
+
import {
|
|
8
|
+
renderSlackConfigTokenPage,
|
|
9
|
+
type SlackConfigTokenPageOpts,
|
|
10
|
+
} from "./admin-ui-slack-config-token-pages.ts";
|
|
11
|
+
|
|
12
|
+
const base: SlackConfigTokenPageOpts = {
|
|
13
|
+
userEmail: "a@x.com",
|
|
14
|
+
isAdmin: true,
|
|
15
|
+
accountOptions: [{ value: "", label: "Deployment-wide" }],
|
|
16
|
+
accountId: "",
|
|
17
|
+
status: null,
|
|
18
|
+
encryptionConfigured: true,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
describe("renderSlackConfigTokenPage", () => {
|
|
22
|
+
it("shows the unconfigured state without rotate/clear actions", () => {
|
|
23
|
+
const html = renderSlackConfigTokenPage(base);
|
|
24
|
+
expect(html).toContain("Not configured for this scope");
|
|
25
|
+
expect(html).toContain("Add refresh token");
|
|
26
|
+
expect(html).not.toContain("Rotate now");
|
|
27
|
+
expect(html).not.toContain("Clear token");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("shows status metadata and actions when configured", () => {
|
|
31
|
+
const html = renderSlackConfigTokenPage({
|
|
32
|
+
...base,
|
|
33
|
+
status: {
|
|
34
|
+
lastRotatedAt: new Date("2026-11-16T00:00:00Z"),
|
|
35
|
+
lastError: "invalid_refresh_token",
|
|
36
|
+
slackTeamId: "T123",
|
|
37
|
+
slackUserId: "U456",
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
expect(html).toContain("2026-11-16T00:00:00.000Z");
|
|
41
|
+
expect(html).toContain("invalid_refresh_token");
|
|
42
|
+
expect(html).toContain("T123 / U456");
|
|
43
|
+
expect(html).toContain("Rotate now");
|
|
44
|
+
expect(html).toContain("Clear token");
|
|
45
|
+
expect(html).toContain("Replace refresh token");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("warns and disables save when the encryption key is missing", () => {
|
|
49
|
+
const html = renderSlackConfigTokenPage({
|
|
50
|
+
...base,
|
|
51
|
+
encryptionConfigured: false,
|
|
52
|
+
});
|
|
53
|
+
expect(html).toContain("SHIPWRIGHT_ENCRYPTION_KEY is not configured");
|
|
54
|
+
expect(html).toContain(" disabled");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("escapes error, notice and scope labels and marks the selected scope", () => {
|
|
58
|
+
const html = renderSlackConfigTokenPage({
|
|
59
|
+
...base,
|
|
60
|
+
accountOptions: [{ value: "a1", label: "<b>Acme</b>" }],
|
|
61
|
+
accountId: "a1",
|
|
62
|
+
error: "<script>x</script>",
|
|
63
|
+
notice: "<i>n</i>",
|
|
64
|
+
});
|
|
65
|
+
expect(html).toContain("<b>Acme</b>");
|
|
66
|
+
expect(html).toContain('<option value="a1" selected>');
|
|
67
|
+
expect(html).toContain("<script>x</script>");
|
|
68
|
+
expect(html).toContain("<i>n</i>");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("never pre-fills the token input", () => {
|
|
72
|
+
const html = renderSlackConfigTokenPage({
|
|
73
|
+
...base,
|
|
74
|
+
status: {
|
|
75
|
+
lastRotatedAt: null,
|
|
76
|
+
lastError: null,
|
|
77
|
+
slackTeamId: null,
|
|
78
|
+
slackUserId: null,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
expect(html).toMatch(/name="refreshToken"[^>]*type|type="password"/);
|
|
82
|
+
expect(html).not.toMatch(/name="refreshToken"[^>]*value=/);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/admin-ui-slack-config-token.smoke.test.ts
|
|
3
|
+
* Smoke tests for /admin/settings/slack-config-token (SCT-3.1) via
|
|
4
|
+
* app.request(), over an in-memory token service and a fake rotate client.
|
|
5
|
+
* No DB, no network.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, expect, it } from "bun:test";
|
|
9
|
+
import type { MiddlewareHandler } from "hono";
|
|
10
|
+
import { Hono } from "hono";
|
|
11
|
+
import type { AdminUIEnv } from "./admin-ui.ts";
|
|
12
|
+
import { registerAdminSlackConfigTokenRoutes } from "./admin-ui-slack-config-token.ts";
|
|
13
|
+
import type { CallerScope } from "./caller-scope.ts";
|
|
14
|
+
import type { SlackConfigTokenMetadata } from "./slack-config-token.ts";
|
|
15
|
+
import { SlackConfigTokenError } from "./slack-provisioning-client.ts";
|
|
16
|
+
|
|
17
|
+
const PASTED = "xoxe-1-PASTED-REFRESH-SECRET";
|
|
18
|
+
const NEW_REFRESH = "xoxe-1-ROTATED-REFRESH-SECRET";
|
|
19
|
+
const NEW_ACCESS = "xoxe-ROTATED-ACCESS-SECRET";
|
|
20
|
+
const SECRETS = [PASTED, NEW_REFRESH, NEW_ACCESS];
|
|
21
|
+
const now = new Date("2026-11-16T00:00:00Z");
|
|
22
|
+
|
|
23
|
+
interface Opts {
|
|
24
|
+
isAdmin?: boolean;
|
|
25
|
+
scope?: CallerScope;
|
|
26
|
+
role?: "owner" | "member";
|
|
27
|
+
encryption?: boolean;
|
|
28
|
+
rotateFails?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function setup(opts: Opts = {}) {
|
|
32
|
+
const rows = new Map<string | null, SlackConfigTokenMetadata>();
|
|
33
|
+
const saved: { accountId: string | null; refreshToken: string }[] = [];
|
|
34
|
+
const rotateCalls: string[] = [];
|
|
35
|
+
const forced: (string | null)[] = [];
|
|
36
|
+
const meta = (accountId: string | null): SlackConfigTokenMetadata => ({
|
|
37
|
+
id: `id-${accountId}`,
|
|
38
|
+
accountId,
|
|
39
|
+
refreshTokenSet: true,
|
|
40
|
+
accessTokenSet: true,
|
|
41
|
+
accessTokenExpiresAt: null,
|
|
42
|
+
slackTeamId: "T1",
|
|
43
|
+
slackUserId: "U1",
|
|
44
|
+
lastRotatedAt: now,
|
|
45
|
+
lastError: null,
|
|
46
|
+
createdAt: now,
|
|
47
|
+
updatedAt: now,
|
|
48
|
+
});
|
|
49
|
+
const app = new Hono<AdminUIEnv>();
|
|
50
|
+
const requireAuth = (async (c, next) => {
|
|
51
|
+
c.set("userEmail", "u@x.com");
|
|
52
|
+
c.set("isAdmin", opts.isAdmin ?? true);
|
|
53
|
+
await next();
|
|
54
|
+
}) as MiddlewareHandler<AdminUIEnv>;
|
|
55
|
+
registerAdminSlackConfigTokenRoutes(app, {
|
|
56
|
+
requireAuth,
|
|
57
|
+
tokens: {
|
|
58
|
+
get: async (id) => rows.get(id) ?? null,
|
|
59
|
+
save: async (id, input) => {
|
|
60
|
+
saved.push({ accountId: id, refreshToken: input.refreshToken });
|
|
61
|
+
rows.set(id, meta(id));
|
|
62
|
+
return meta(id);
|
|
63
|
+
},
|
|
64
|
+
clear: async (id) => {
|
|
65
|
+
rows.delete(id);
|
|
66
|
+
},
|
|
67
|
+
getAccessToken: async (id) => {
|
|
68
|
+
forced.push(id);
|
|
69
|
+
return NEW_ACCESS;
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
rotateClient: {
|
|
73
|
+
rotateConfigToken: async (t) => {
|
|
74
|
+
rotateCalls.push(t);
|
|
75
|
+
if (opts.rotateFails) {
|
|
76
|
+
throw new SlackConfigTokenError(opts.rotateFails, `bad ${t}`);
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
accessToken: NEW_ACCESS,
|
|
80
|
+
refreshToken: NEW_REFRESH,
|
|
81
|
+
teamId: "T1",
|
|
82
|
+
userId: "U1",
|
|
83
|
+
iat: 1,
|
|
84
|
+
exp: 2,
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
encryptionConfigured: () => opts.encryption ?? true,
|
|
89
|
+
callerScopeResolver: async () =>
|
|
90
|
+
opts.scope ?? { kind: "scoped", accountId: null, agentIds: [] },
|
|
91
|
+
members: {
|
|
92
|
+
getByEmail: async () =>
|
|
93
|
+
({
|
|
94
|
+
accountId: "acct-1",
|
|
95
|
+
role: opts.role ?? "owner",
|
|
96
|
+
}) as never,
|
|
97
|
+
},
|
|
98
|
+
accounts: {
|
|
99
|
+
listWithCounts: async () =>
|
|
100
|
+
[
|
|
101
|
+
{ id: "acct-1", name: "Acme" },
|
|
102
|
+
{ id: "acct-2", name: "Globex" },
|
|
103
|
+
] as never,
|
|
104
|
+
getWithCounts: async (id: string) => ({ id, name: "Acme" }) as never,
|
|
105
|
+
},
|
|
106
|
+
html: (content, o) =>
|
|
107
|
+
new Response(content, {
|
|
108
|
+
status: o?.status ?? 200,
|
|
109
|
+
headers: { "Content-Type": "text/html" },
|
|
110
|
+
}),
|
|
111
|
+
});
|
|
112
|
+
return { app, rows, saved, rotateCalls, forced };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const BASE = "/admin/settings/slack-config-token";
|
|
116
|
+
const form = (fields: Record<string, string>) => ({
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
119
|
+
body: new URLSearchParams(fields).toString(),
|
|
120
|
+
});
|
|
121
|
+
const owner: CallerScope = {
|
|
122
|
+
kind: "scoped",
|
|
123
|
+
accountId: "acct-1",
|
|
124
|
+
agentIds: [],
|
|
125
|
+
};
|
|
126
|
+
const expectNoSecrets = (s: string) => {
|
|
127
|
+
for (const secret of SECRETS) expect(s).not.toContain(secret);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
describe("/admin/settings/slack-config-token smoke", () => {
|
|
131
|
+
it("renders the page with the scope picker for an admin", async () => {
|
|
132
|
+
const { app } = setup();
|
|
133
|
+
const res = await app.request(BASE);
|
|
134
|
+
expect(res.status).toBe(200);
|
|
135
|
+
const html = await res.text();
|
|
136
|
+
expect(html).toContain("Deployment-wide");
|
|
137
|
+
expect(html).toContain("Acme");
|
|
138
|
+
expect(html).toContain("Not configured");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("admin saves the default row: validates by rotating, stores the rotated pair, no secrets in redirect or page", async () => {
|
|
142
|
+
const { app, saved, rotateCalls } = setup();
|
|
143
|
+
const res = await app.request(
|
|
144
|
+
`${BASE}/save`,
|
|
145
|
+
form({ accountId: "", refreshToken: PASTED }),
|
|
146
|
+
);
|
|
147
|
+
expect(res.status).toBe(302);
|
|
148
|
+
const loc = res.headers.get("location") as string;
|
|
149
|
+
expectNoSecrets(loc);
|
|
150
|
+
expect(rotateCalls).toEqual([PASTED]);
|
|
151
|
+
expect(saved).toEqual([{ accountId: null, refreshToken: NEW_REFRESH }]);
|
|
152
|
+
const html = await (await app.request(loc)).text();
|
|
153
|
+
expectNoSecrets(html);
|
|
154
|
+
expect(html).toContain("validated and saved");
|
|
155
|
+
expect(html).toContain("T1 / U1");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("admin can save another account's row", async () => {
|
|
159
|
+
const { app, saved } = setup();
|
|
160
|
+
const res = await app.request(
|
|
161
|
+
`${BASE}/save`,
|
|
162
|
+
form({ accountId: "acct-2", refreshToken: PASTED }),
|
|
163
|
+
);
|
|
164
|
+
expect(res.status).toBe(302);
|
|
165
|
+
expect(res.headers.get("location")).toContain("accountId=acct-2");
|
|
166
|
+
expect(saved[0]?.accountId).toBe("acct-2");
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("invalid paste shows an error and stores nothing", async () => {
|
|
170
|
+
const { app, saved, rotateCalls } = setup({
|
|
171
|
+
rotateFails: "invalid_refresh_token",
|
|
172
|
+
});
|
|
173
|
+
const res = await app.request(
|
|
174
|
+
`${BASE}/save`,
|
|
175
|
+
form({ accountId: "", refreshToken: PASTED }),
|
|
176
|
+
);
|
|
177
|
+
expect(res.status).toBe(422);
|
|
178
|
+
const html = await res.text();
|
|
179
|
+
expect(html).toContain("invalid_refresh_token");
|
|
180
|
+
expectNoSecrets(html);
|
|
181
|
+
expect(saved).toHaveLength(0);
|
|
182
|
+
expect(rotateCalls).toHaveLength(1);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("a paste without the xoxe-1- prefix is refused before any Slack call", async () => {
|
|
186
|
+
const { app, saved, rotateCalls } = setup();
|
|
187
|
+
const res = await app.request(
|
|
188
|
+
`${BASE}/save`,
|
|
189
|
+
form({ accountId: "", refreshToken: "xoxb-not-a-config-token" }),
|
|
190
|
+
);
|
|
191
|
+
expect(res.status).toBe(422);
|
|
192
|
+
expect(await res.text()).toContain("xoxe-1-");
|
|
193
|
+
expect(saved).toHaveLength(0);
|
|
194
|
+
expect(rotateCalls).toHaveLength(0);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("refuses save with a clear message when the encryption key is unset", async () => {
|
|
198
|
+
const { app, saved, rotateCalls } = setup({ encryption: false });
|
|
199
|
+
const res = await app.request(
|
|
200
|
+
`${BASE}/save`,
|
|
201
|
+
form({ accountId: "", refreshToken: PASTED }),
|
|
202
|
+
);
|
|
203
|
+
expect(res.status).toBe(422);
|
|
204
|
+
expect(await res.text()).toContain("SHIPWRIGHT_ENCRYPTION_KEY");
|
|
205
|
+
expect(saved).toHaveLength(0);
|
|
206
|
+
expect(rotateCalls).toHaveLength(0);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("clear removes the row", async () => {
|
|
210
|
+
const { app, rows } = setup();
|
|
211
|
+
await app.request(
|
|
212
|
+
`${BASE}/save`,
|
|
213
|
+
form({ accountId: "", refreshToken: PASTED }),
|
|
214
|
+
);
|
|
215
|
+
expect(rows.has(null)).toBe(true);
|
|
216
|
+
const res = await app.request(`${BASE}/clear`, form({ accountId: "" }));
|
|
217
|
+
expect(res.status).toBe(302);
|
|
218
|
+
expect(rows.has(null)).toBe(false);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("rotate now forces a rotation and never exposes the access token", async () => {
|
|
222
|
+
const { app, forced } = setup();
|
|
223
|
+
const res = await app.request(
|
|
224
|
+
`${BASE}/rotate`,
|
|
225
|
+
form({ accountId: "acct-2" }),
|
|
226
|
+
);
|
|
227
|
+
expect(res.status).toBe(302);
|
|
228
|
+
expect(forced).toEqual(["acct-2"]);
|
|
229
|
+
expectNoSecrets(res.headers.get("location") as string);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("account owner manages only their own account's row", async () => {
|
|
233
|
+
const { app, saved } = setup({ isAdmin: false, scope: owner });
|
|
234
|
+
const page = await app.request(BASE);
|
|
235
|
+
expect(page.status).toBe(200);
|
|
236
|
+
const html = await page.text();
|
|
237
|
+
expect(html).toContain("Acme");
|
|
238
|
+
expect(html).not.toContain("Deployment-wide");
|
|
239
|
+
const own = await app.request(
|
|
240
|
+
`${BASE}/save`,
|
|
241
|
+
form({ refreshToken: PASTED }),
|
|
242
|
+
);
|
|
243
|
+
expect(own.status).toBe(302);
|
|
244
|
+
expect(saved[0]?.accountId).toBe("acct-1");
|
|
245
|
+
const ownExplicit = await app.request(
|
|
246
|
+
`${BASE}/save`,
|
|
247
|
+
form({ accountId: "acct-1", refreshToken: PASTED }),
|
|
248
|
+
);
|
|
249
|
+
expect(ownExplicit.status).toBe(302);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it("owner gets 403 for another account and the deployment-wide row", async () => {
|
|
253
|
+
const { app, saved, rotateCalls } = setup({ isAdmin: false, scope: owner });
|
|
254
|
+
expect((await app.request(`${BASE}?accountId=acct-2`)).status).toBe(403);
|
|
255
|
+
for (const path of ["save", "clear", "rotate"]) {
|
|
256
|
+
const res = await app.request(
|
|
257
|
+
`${BASE}/${path}`,
|
|
258
|
+
form({ accountId: "acct-2", refreshToken: PASTED }),
|
|
259
|
+
);
|
|
260
|
+
expect(res.status).toBe(403);
|
|
261
|
+
}
|
|
262
|
+
expect(saved).toHaveLength(0);
|
|
263
|
+
expect(rotateCalls).toHaveLength(0);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("plain account members get 403 on GET and every action", async () => {
|
|
267
|
+
const { app, saved } = setup({
|
|
268
|
+
isAdmin: false,
|
|
269
|
+
scope: owner,
|
|
270
|
+
role: "member",
|
|
271
|
+
});
|
|
272
|
+
expect((await app.request(BASE)).status).toBe(403);
|
|
273
|
+
for (const path of ["save", "clear", "rotate"]) {
|
|
274
|
+
const res = await app.request(
|
|
275
|
+
`${BASE}/${path}`,
|
|
276
|
+
form({ accountId: "acct-1", refreshToken: PASTED }),
|
|
277
|
+
);
|
|
278
|
+
expect(res.status).toBe(403);
|
|
279
|
+
}
|
|
280
|
+
expect(saved).toHaveLength(0);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it("callers without an account get 403", async () => {
|
|
284
|
+
const { app } = setup({ isAdmin: false });
|
|
285
|
+
expect((await app.request(BASE)).status).toBe(403);
|
|
286
|
+
});
|
|
287
|
+
});
|