@fuzdev/fuz_app 0.185.0 → 0.187.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/dist/actions/CLAUDE.md +14 -2
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/perform_action.js +36 -5
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +3 -1
- package/dist/auth/CLAUDE.md +17 -6
- package/dist/auth/account_queries.d.ts +60 -44
- package/dist/auth/account_queries.d.ts.map +1 -1
- package/dist/auth/account_queries.js +64 -54
- package/dist/auth/account_routes.d.ts.map +1 -1
- package/dist/auth/account_routes.js +59 -25
- package/dist/auth/admin_actions.d.ts.map +1 -1
- package/dist/auth/admin_actions.js +26 -9
- package/dist/auth/audit_emitter.js +2 -2
- package/dist/auth/audit_log_queries.d.ts +11 -3
- package/dist/auth/audit_log_queries.d.ts.map +1 -1
- package/dist/auth/audit_log_queries.js +4 -4
- package/dist/auth/audit_log_schema.js +1 -1
- package/dist/auth/auth_ddl.d.ts.map +1 -1
- package/dist/auth/auth_ddl.js +4 -0
- package/dist/auth/cleanup.js +1 -1
- package/dist/auth/migrations.d.ts.map +1 -1
- package/dist/auth/migrations.js +35 -0
- package/dist/auth/role_grant_offer_action_specs.d.ts +1 -1
- package/dist/auth/role_grant_offer_action_specs.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_action_specs.js +2 -1
- package/dist/auth/role_grant_offer_actions.d.ts +12 -0
- package/dist/auth/role_grant_offer_actions.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_actions.js +48 -20
- package/dist/auth/role_grant_offer_queries.d.ts +28 -15
- package/dist/auth/role_grant_offer_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_offer_queries.js +35 -16
- package/dist/auth/role_grant_queries.d.ts +118 -20
- package/dist/auth/role_grant_queries.d.ts.map +1 -1
- package/dist/auth/role_grant_queries.js +145 -24
- package/dist/auth/self_service_role_actions.d.ts.map +1 -1
- package/dist/auth/self_service_role_actions.js +15 -0
- package/dist/auth/session_queries.d.ts +24 -0
- package/dist/auth/session_queries.d.ts.map +1 -1
- package/dist/auth/session_queries.js +28 -0
- package/dist/db/CLAUDE.md +3 -3
- package/dist/db/cell_ddl.d.ts +8 -3
- package/dist/db/cell_ddl.d.ts.map +1 -1
- package/dist/db/cell_ddl.js +10 -5
- package/dist/db/migrate.d.ts +46 -22
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +103 -85
- package/dist/http/body_limit.d.ts +4 -4
- package/dist/http/body_limit.js +4 -4
- package/dist/server/app_backend.d.ts.map +1 -1
- package/dist/server/app_backend.js +1 -4
- package/dist/testing/CLAUDE.md +161 -27
- package/dist/testing/app_server.d.ts +5 -7
- package/dist/testing/app_server.d.ts.map +1 -1
- package/dist/testing/app_server.js +5 -7
- package/dist/testing/auth_apps.d.ts +3 -1
- package/dist/testing/auth_apps.d.ts.map +1 -1
- package/dist/testing/auth_apps.js +22 -5
- package/dist/testing/cross_backend/backend_both_live.d.ts +47 -0
- package/dist/testing/cross_backend/backend_both_live.d.ts.map +1 -0
- package/dist/testing/cross_backend/backend_both_live.js +566 -0
- package/dist/testing/cross_backend/backend_config.d.ts +8 -0
- package/dist/testing/cross_backend/backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/backend_log.d.ts +71 -0
- package/dist/testing/cross_backend/backend_log.d.ts.map +1 -0
- package/dist/testing/cross_backend/backend_log.js +134 -0
- package/dist/testing/cross_backend/backend_swap.d.ts +41 -0
- package/dist/testing/cross_backend/backend_swap.d.ts.map +1 -0
- package/dist/testing/cross_backend/backend_swap.js +267 -0
- package/dist/testing/cross_backend/body_size_smuggling.js +3 -3
- package/dist/testing/cross_backend/bootstrap_backend.js +4 -4
- package/dist/testing/cross_backend/conformance_case.d.ts +11 -6
- package/dist/testing/cross_backend/conformance_case.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_case.js +4 -0
- package/dist/testing/cross_backend/conformance_principal.d.ts +2 -2
- package/dist/testing/cross_backend/conformance_principal.d.ts.map +1 -1
- package/dist/testing/cross_backend/conformance_principal.js +27 -10
- package/dist/testing/cross_backend/default_backend_configs.d.ts +38 -5
- package/dist/testing/cross_backend/default_backend_configs.d.ts.map +1 -1
- package/dist/testing/cross_backend/default_backend_configs.js +50 -15
- package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/in_process_setup.js +52 -30
- package/dist/testing/cross_backend/revocation_drivers.d.ts +14 -2
- package/dist/testing/cross_backend/revocation_drivers.d.ts.map +1 -1
- package/dist/testing/cross_backend/revocation_drivers.js +36 -8
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts +7 -0
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.d.ts.map +1 -1
- package/dist/testing/cross_backend/rust_spine_stub_backend_config.js +4 -2
- package/dist/testing/cross_backend/setup.d.ts +44 -43
- package/dist/testing/cross_backend/setup.d.ts.map +1 -1
- package/dist/testing/cross_backend/setup.js +64 -62
- package/dist/testing/cross_backend/shared_database_backends.d.ts +175 -0
- package/dist/testing/cross_backend/shared_database_backends.d.ts.map +1 -0
- package/dist/testing/cross_backend/shared_database_backends.js +298 -0
- package/dist/testing/cross_backend/spawn_backend.d.ts +7 -3
- package/dist/testing/cross_backend/spawn_backend.d.ts.map +1 -1
- package/dist/testing/cross_backend/spawn_backend.js +86 -7
- package/dist/testing/cross_backend/spine_suites.d.ts +1 -1
- package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
- package/dist/testing/cross_backend/spine_suites.js +5 -2
- package/dist/testing/cross_backend/sse_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/sse_round_trip.js +4 -2
- package/dist/testing/cross_backend/testing_reset_actions.d.ts +7 -6
- package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_reset_actions.js +10 -8
- package/dist/testing/cross_backend/testing_server_bun.d.ts.map +1 -1
- package/dist/testing/cross_backend/testing_server_bun.js +7 -31
- package/dist/testing/cross_backend/ws_round_trip.d.ts.map +1 -1
- package/dist/testing/cross_backend/ws_round_trip.js +4 -3
- package/dist/testing/data_exposure.d.ts +4 -1
- package/dist/testing/data_exposure.d.ts.map +1 -1
- package/dist/testing/data_exposure.js +93 -25
- package/dist/testing/db_invariants.d.ts +5 -5
- package/dist/testing/db_invariants.js +5 -5
- package/dist/testing/logged_errors.d.ts +61 -0
- package/dist/testing/logged_errors.d.ts.map +1 -0
- package/dist/testing/logged_errors.js +285 -0
- package/dist/testing/middleware_gate_probes.d.ts.map +1 -1
- package/dist/testing/middleware_gate_probes.js +15 -8
- package/dist/testing/rpc_attack_surface.d.ts.map +1 -1
- package/dist/testing/rpc_attack_surface.js +41 -16
- package/dist/testing/stubs.d.ts +5 -1
- package/dist/testing/stubs.d.ts.map +1 -1
- package/dist/testing/stubs.js +6 -3
- package/dist/testing/test_app.d.ts +40 -11
- package/dist/testing/test_app.d.ts.map +1 -1
- package/dist/testing/test_app.js +66 -9
- package/dist/testing/transports/fetch_transport.d.ts +10 -0
- package/dist/testing/transports/fetch_transport.d.ts.map +1 -1
- package/dist/testing/transports/fetch_transport.js +13 -0
- package/package.json +5 -3
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import '../assert_dev_env.js';
|
|
2
|
+
/**
|
|
3
|
+
* An error line a backend may log, and why. The pattern is a substring, not
|
|
4
|
+
* a `RegExp`: a config crosses to the test workers through vitest's
|
|
5
|
+
* `provide`, which keeps plain data only.
|
|
6
|
+
*/
|
|
7
|
+
export interface BackendLogAllowance {
|
|
8
|
+
readonly pattern: string;
|
|
9
|
+
readonly reason: string;
|
|
10
|
+
}
|
|
11
|
+
/** Where a spawned backend's output goes, and the error lines it may log. */
|
|
12
|
+
export interface BackendLogConfig {
|
|
13
|
+
/** The file the child's stdout and stderr are teed into, interleaved; rewritten per spawn. */
|
|
14
|
+
readonly path: string;
|
|
15
|
+
/** Error lines the backend may log — what its suites provoke on purpose, each with its reason. */
|
|
16
|
+
readonly allow_errors: ReadonlyArray<BackendLogAllowance>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The error lines the shipped cross suites provoke on purpose, each with the
|
|
20
|
+
* suite and why — every family builder allows them
|
|
21
|
+
* (`make_default_ts_backend_config`, `make_default_rust_backend_config`).
|
|
22
|
+
*/
|
|
23
|
+
export declare const SPINE_CROSS_SUITE_BACKEND_ERRORS: ReadonlyArray<BackendLogAllowance>;
|
|
24
|
+
/**
|
|
25
|
+
* `config` with `allow` added to its log's allowances — for a setup that
|
|
26
|
+
* provokes errors of its own (a probe before bootstrap). A config with no
|
|
27
|
+
* `log` is returned as it is.
|
|
28
|
+
*
|
|
29
|
+
* @param config - the backend config
|
|
30
|
+
* @param allow - the further error lines it may log
|
|
31
|
+
*/
|
|
32
|
+
export declare const with_backend_log_allowances: <T extends {
|
|
33
|
+
readonly log?: BackendLogConfig;
|
|
34
|
+
}>(config: T, allow: ReadonlyArray<BackendLogAllowance>) => T;
|
|
35
|
+
/**
|
|
36
|
+
* Whether a backend output line is error-level (§module doc).
|
|
37
|
+
*
|
|
38
|
+
* @param line - one line, ANSI escapes stripped
|
|
39
|
+
*/
|
|
40
|
+
export declare const is_backend_error_line: (line: string) => boolean;
|
|
41
|
+
/**
|
|
42
|
+
* The error-level lines of a backend's output that no allowance matches, in
|
|
43
|
+
* order, ANSI escapes stripped.
|
|
44
|
+
*
|
|
45
|
+
* @param text - the backend's output
|
|
46
|
+
* @param allow - the error lines it may log
|
|
47
|
+
* @returns each unexpected error line
|
|
48
|
+
*/
|
|
49
|
+
export declare const find_unexpected_backend_errors: (text: string, allow: ReadonlyArray<BackendLogAllowance>) => Array<string>;
|
|
50
|
+
/** Whole lines of one output stream, from the chunks it arrives in. */
|
|
51
|
+
export interface LogLineSplitter {
|
|
52
|
+
/** The lines `chunk` completes, each with its `\n`; a partial line waits for the next chunk. */
|
|
53
|
+
readonly push: (chunk: Buffer) => string;
|
|
54
|
+
/** What is left at the stream's end, as one line with its `\n`, or `''`. */
|
|
55
|
+
readonly end: () => string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create a `LogLineSplitter` — how `spawn_backend` writes a stream to the log
|
|
59
|
+
* whole lines at a time, so stdout and stderr interleave without gluing one's
|
|
60
|
+
* partial line onto the other's.
|
|
61
|
+
*/
|
|
62
|
+
export declare const create_log_line_splitter: () => LogLineSplitter;
|
|
63
|
+
/**
|
|
64
|
+
* The teardown failure naming a backend's unexpected error lines.
|
|
65
|
+
*
|
|
66
|
+
* @param name - the backend's name
|
|
67
|
+
* @param path - its log file
|
|
68
|
+
* @param lines - the unexpected lines (`find_unexpected_backend_errors`)
|
|
69
|
+
*/
|
|
70
|
+
export declare const format_unexpected_backend_errors: (name: string, path: string, lines: ReadonlyArray<string>) => string;
|
|
71
|
+
//# sourceMappingURL=backend_log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend_log.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/backend_log.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAsB9B;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACxB;AAED,6EAA6E;AAC7E,MAAM,WAAW,gBAAgB;IAChC,8FAA8F;IAC9F,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,kGAAkG;IAClG,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,mBAAmB,CAAC,CAAC;CAC1D;AAED;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,EAAE,aAAa,CAAC,mBAAmB,CAa/E,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B,GAAI,CAAC,SAAS;IAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,gBAAgB,CAAA;CAAE,EACxF,QAAQ,CAAC,EACT,OAAO,aAAa,CAAC,mBAAmB,CAAC,KACvC,CAGO,CAAC;AAkBX;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAAI,MAAM,MAAM,KAAG,OAG1B,CAAC;AAE5B;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,GAC1C,MAAM,MAAM,EACZ,OAAO,aAAa,CAAC,mBAAmB,CAAC,KACvC,KAAK,CAAC,MAAM,CAQd,CAAC;AAEF,uEAAuE;AACvE,MAAM,WAAW,eAAe;IAC/B,gGAAgG;IAChG,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACzC,4EAA4E;IAC5E,QAAQ,CAAC,GAAG,EAAE,MAAM,MAAM,CAAC;CAC3B;AAED;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,QAAO,eAsB3C,CAAC;AAQF;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC,GAC5C,MAAM,MAAM,EACZ,MAAM,MAAM,EACZ,OAAO,aAAa,CAAC,MAAM,CAAC,KAC1B,MAaF,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import '../assert_dev_env.js';
|
|
2
|
+
/**
|
|
3
|
+
* A spawned backend's log, checked at teardown: `spawn_backend` tees the
|
|
4
|
+
* child's stdout and stderr into `BackendLogConfig.path` and, once the child
|
|
5
|
+
* has exited, fails the teardown on every error-level line no allowance
|
|
6
|
+
* matches. The cross-process twin of the in-process logged-error gate
|
|
7
|
+
* (`testing/logged_errors.ts`), at the grain of a whole run: what a backend
|
|
8
|
+
* logs isn't attributed to the test that provoked it, so an allowance names
|
|
9
|
+
* the error a suite provokes on purpose, with its reason.
|
|
10
|
+
*
|
|
11
|
+
* An error-level line is a fuz_util `Logger` error (`🞩error🞩`, how a TS
|
|
12
|
+
* backend's errors print) or a `tracing` `ERROR` event (`<timestamp> ERROR`,
|
|
13
|
+
* the Rust spine's default format), or a Rust panic's first line
|
|
14
|
+
* (`thread '…' panicked at`), read with ANSI colors stripped. A bare
|
|
15
|
+
* `console.error` carries no level marker and is not seen.
|
|
16
|
+
*
|
|
17
|
+
* @module
|
|
18
|
+
*/
|
|
19
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
20
|
+
/**
|
|
21
|
+
* The error lines the shipped cross suites provoke on purpose, each with the
|
|
22
|
+
* suite and why — every family builder allows them
|
|
23
|
+
* (`make_default_ts_backend_config`, `make_default_rust_backend_config`).
|
|
24
|
+
*/
|
|
25
|
+
export const SPINE_CROSS_SUITE_BACKEND_ERRORS = [
|
|
26
|
+
{
|
|
27
|
+
// TS spine (`serve_fact.ts`)
|
|
28
|
+
pattern: "addresses another fact's file; answering 404",
|
|
29
|
+
reason: "`fact_serving`: a fact whose `external_url` names another fact's file answers the masked 404"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
// Rust spine (`fuz_fact_serving::serve`)
|
|
33
|
+
pattern: 'serve_fact: rejecting an external_url that addresses another fact',
|
|
34
|
+
reason: "`fact_serving`: a fact whose `external_url` names another fact's file answers the masked 404"
|
|
35
|
+
}
|
|
36
|
+
];
|
|
37
|
+
/**
|
|
38
|
+
* `config` with `allow` added to its log's allowances — for a setup that
|
|
39
|
+
* provokes errors of its own (a probe before bootstrap). A config with no
|
|
40
|
+
* `log` is returned as it is.
|
|
41
|
+
*
|
|
42
|
+
* @param config - the backend config
|
|
43
|
+
* @param allow - the further error lines it may log
|
|
44
|
+
*/
|
|
45
|
+
export const with_backend_log_allowances = (config, allow) => config.log
|
|
46
|
+
? { ...config, log: { ...config.log, allow_errors: [...config.log.allow_errors, ...allow] } }
|
|
47
|
+
: config;
|
|
48
|
+
/** The marker fuz_util's `Logger` prints an error with. */
|
|
49
|
+
const LOGGER_ERROR_MARKER = '🞩error🞩';
|
|
50
|
+
/** A `tracing_subscriber` `fmt` event at `ERROR`: an RFC 3339 timestamp, then the level. */
|
|
51
|
+
const TRACING_ERROR_LINE = /^\d{4}-\d{2}-\d{2}T[\d:.]+Z\s+ERROR\s/;
|
|
52
|
+
/**
|
|
53
|
+
* The Rust default panic hook's first line — a panic in a spawned task (a WS
|
|
54
|
+
* session's) prints it to stderr with no `tracing` event; the router's own
|
|
55
|
+
* panics are caught and logged at `ERROR`.
|
|
56
|
+
*/
|
|
57
|
+
const RUST_PANIC_LINE = /^thread '[^']*' panicked at /;
|
|
58
|
+
// eslint-disable-next-line no-control-regex
|
|
59
|
+
const ANSI_ESCAPE = /\x1b\[[0-9;]*m/g;
|
|
60
|
+
/**
|
|
61
|
+
* Whether a backend output line is error-level (§module doc).
|
|
62
|
+
*
|
|
63
|
+
* @param line - one line, ANSI escapes stripped
|
|
64
|
+
*/
|
|
65
|
+
export const is_backend_error_line = (line) => line.startsWith(LOGGER_ERROR_MARKER) ||
|
|
66
|
+
TRACING_ERROR_LINE.test(line) ||
|
|
67
|
+
RUST_PANIC_LINE.test(line);
|
|
68
|
+
/**
|
|
69
|
+
* The error-level lines of a backend's output that no allowance matches, in
|
|
70
|
+
* order, ANSI escapes stripped.
|
|
71
|
+
*
|
|
72
|
+
* @param text - the backend's output
|
|
73
|
+
* @param allow - the error lines it may log
|
|
74
|
+
* @returns each unexpected error line
|
|
75
|
+
*/
|
|
76
|
+
export const find_unexpected_backend_errors = (text, allow) => {
|
|
77
|
+
const unexpected = [];
|
|
78
|
+
for (const raw of text.split('\n')) {
|
|
79
|
+
const line = raw.replace(ANSI_ESCAPE, '').replace(/\r$/, '');
|
|
80
|
+
if (!is_backend_error_line(line))
|
|
81
|
+
continue;
|
|
82
|
+
if (!allow.some(({ pattern }) => line.includes(pattern)))
|
|
83
|
+
unexpected.push(line);
|
|
84
|
+
}
|
|
85
|
+
return unexpected;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Create a `LogLineSplitter` — how `spawn_backend` writes a stream to the log
|
|
89
|
+
* whole lines at a time, so stdout and stderr interleave without gluing one's
|
|
90
|
+
* partial line onto the other's.
|
|
91
|
+
*/
|
|
92
|
+
export const create_log_line_splitter = () => {
|
|
93
|
+
let pending = '';
|
|
94
|
+
// a chunk can end inside a multi-byte character — the `🞩` of a `Logger`
|
|
95
|
+
// error line is four bytes — so decode across chunks, never per chunk
|
|
96
|
+
const decoder = new StringDecoder('utf8');
|
|
97
|
+
return {
|
|
98
|
+
push: (chunk) => {
|
|
99
|
+
const text = pending + decoder.write(chunk);
|
|
100
|
+
const end = text.lastIndexOf('\n');
|
|
101
|
+
if (end === -1) {
|
|
102
|
+
pending = text;
|
|
103
|
+
return '';
|
|
104
|
+
}
|
|
105
|
+
pending = text.slice(end + 1);
|
|
106
|
+
return text.slice(0, end + 1);
|
|
107
|
+
},
|
|
108
|
+
end: () => {
|
|
109
|
+
const rest = pending + decoder.end();
|
|
110
|
+
pending = '';
|
|
111
|
+
return rest === '' ? '' : `${rest}\n`;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
/** How many unexpected lines a teardown failure lists. */
|
|
116
|
+
const REPORTED_LINES_MAX = 20;
|
|
117
|
+
/** How much of a line a teardown failure shows. */
|
|
118
|
+
const REPORTED_LINE_MAX_LENGTH = 400;
|
|
119
|
+
/**
|
|
120
|
+
* The teardown failure naming a backend's unexpected error lines.
|
|
121
|
+
*
|
|
122
|
+
* @param name - the backend's name
|
|
123
|
+
* @param path - its log file
|
|
124
|
+
* @param lines - the unexpected lines (`find_unexpected_backend_errors`)
|
|
125
|
+
*/
|
|
126
|
+
export const format_unexpected_backend_errors = (name, path, lines) => {
|
|
127
|
+
const shown = lines
|
|
128
|
+
.slice(0, REPORTED_LINES_MAX)
|
|
129
|
+
.map((l) => l.length > REPORTED_LINE_MAX_LENGTH ? ` ${l.slice(0, REPORTED_LINE_MAX_LENGTH)}…` : ` ${l}`);
|
|
130
|
+
const more = lines.length > REPORTED_LINES_MAX ? [` … and ${lines.length - REPORTED_LINES_MAX} more`] : [];
|
|
131
|
+
return (`spawn_backend(${name}): the backend logged ${lines.length === 1 ? 'an error' : 'errors'} no allowance names (${path}):\n` +
|
|
132
|
+
[...shown, ...more].join('\n') +
|
|
133
|
+
'\nAllow one a suite provokes on purpose in the config’s `log.allow_errors`, with its reason.');
|
|
134
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import '../assert_dev_env.js';
|
|
2
|
+
import type { BackendConfig } from './backend_config.js';
|
|
3
|
+
/** One order of the swap: `first` mints, `second` honors, `first` checks. */
|
|
4
|
+
export interface BackendSwapOrder {
|
|
5
|
+
/** Names the order's `describe`. */
|
|
6
|
+
readonly label: string;
|
|
7
|
+
readonly first: BackendConfig;
|
|
8
|
+
readonly second: BackendConfig;
|
|
9
|
+
}
|
|
10
|
+
/** Options for `describe_backend_swap_tests`. */
|
|
11
|
+
export interface BackendSwapTestOptions {
|
|
12
|
+
/** The orders to run, one after another over the one database. */
|
|
13
|
+
readonly orders: ReadonlyArray<BackendSwapOrder>;
|
|
14
|
+
/**
|
|
15
|
+
* The `postgres://` database every config runs over, read directly for the
|
|
16
|
+
* snapshots — each config's `DATABASE_URL` env must be this exact string.
|
|
17
|
+
*/
|
|
18
|
+
readonly database_url: string;
|
|
19
|
+
/**
|
|
20
|
+
* The role of the offer the second backend declines — one the keeper may
|
|
21
|
+
* offer, other than `admin` (the offer the second backend accepts; the
|
|
22
|
+
* suite refuses `admin`). Default `SPINE_PARTICIPANT_ROLE`, which the
|
|
23
|
+
* reference spines register.
|
|
24
|
+
*/
|
|
25
|
+
readonly declined_role?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Empty the database — each order calls it before its first spawn, so the
|
|
28
|
+
* keeper bootstrap finds no account. The caller owns the guard on which
|
|
29
|
+
* database it drops (`empty_owned_database`).
|
|
30
|
+
*/
|
|
31
|
+
readonly empty_database: () => Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Describe the backend swap over each order (§module doc): three tests per
|
|
35
|
+
* order, run in turn, each phase spawning and stopping its own backend. A
|
|
36
|
+
* phase whose predecessor failed fails naming it.
|
|
37
|
+
*
|
|
38
|
+
* @param options - the orders, the shared database, and how to empty it
|
|
39
|
+
*/
|
|
40
|
+
export declare const describe_backend_swap_tests: (options: BackendSwapTestOptions) => void;
|
|
41
|
+
//# sourceMappingURL=backend_swap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend_swap.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/backend_swap.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AA2E9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AA4BzD,6EAA6E;AAC7E,MAAM,WAAW,gBAAgB;IAChC,oCAAoC;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;CAC/B;AAED,iDAAiD;AACjD,MAAM,WAAW,sBAAsB;IACtC,kEAAkE;IAClE,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC,gBAAgB,CAAC,CAAC;IACjD;;;OAGG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC;;;;OAIG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C;AAuWD;;;;;;GAMG;AACH,eAAO,MAAM,2BAA2B,GAAI,SAAS,sBAAsB,KAAG,IAmE7E,CAAC"}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import '../assert_dev_env.js';
|
|
2
|
+
/**
|
|
3
|
+
* The backend swap: two spines, one database, one at a time. The first
|
|
4
|
+
* mints credentials and writes rows through its real routes, stops, and the
|
|
5
|
+
* second boots over the database as the first left it and honors every one;
|
|
6
|
+
* then the first boots again and honors what the second wrote. It is what
|
|
7
|
+
* makes the TS and Rust spines twins in deployment, not only on the wire: a
|
|
8
|
+
* consumer swaps one for the other without re-bootstrapping, and every
|
|
9
|
+
* session, token, password, invite and offer carries over.
|
|
10
|
+
*
|
|
11
|
+
* Nothing is seeded behind the spines' backs — no `_testing_reset`, no
|
|
12
|
+
* minted session. Per order, mint on the first, use on the second, check on
|
|
13
|
+
* the first again:
|
|
14
|
+
*
|
|
15
|
+
* - **First** — the keeper bootstrap, a second keeper session and a keeper
|
|
16
|
+
* API token, an invite, the member's signup and login, a member API token,
|
|
17
|
+
* two pending offers to the member — `admin`, and `declined_role` to its
|
|
18
|
+
* actor (one role each: a second offer of a role still pending answers the
|
|
19
|
+
* first); the schema-version rows and a digest of every table's content
|
|
20
|
+
* read over Postgres.
|
|
21
|
+
* - **Second** — before any request, the migrations and every table's
|
|
22
|
+
* content as the first left them (its boot applied no migration and
|
|
23
|
+
* rewrote no row); bootstrap closed on `/status` and refused on
|
|
24
|
+
* `POST /bootstrap`; every cookie and both tokens authenticate; the
|
|
25
|
+
* member's password logs in and a wrong one is refused (an Argon2id hash
|
|
26
|
+
* verified by the other spine's verifier); both offers listed pending, one
|
|
27
|
+
* declined, one accepted, after which the member passes the admin gate;
|
|
28
|
+
* no database invariant broken; then the revocations — the second keeper
|
|
29
|
+
* session logged out and the keeper token revoked, each refused there, and
|
|
30
|
+
* the member's password changed.
|
|
31
|
+
* - **First again** — the migrations unchanged; the logged-out keeper
|
|
32
|
+
* session and the revoked keeper token refused while the first keeper
|
|
33
|
+
* cookie still authenticates (the revocations the second wrote, which
|
|
34
|
+
* nothing else ended); the member's sessions on both spines and its token
|
|
35
|
+
* refused (the password change ends them all); only the new password logs
|
|
36
|
+
* in, and its session passes the admin gate; the accepted offer bound to
|
|
37
|
+
* the grant the second made and the declined offer declined; no invariant
|
|
38
|
+
* broken.
|
|
39
|
+
*
|
|
40
|
+
* Every phase drains the backend's detached writes before its teardown,
|
|
41
|
+
* which holds the backend to exit `0` with no unexpected error in its log
|
|
42
|
+
* (`spawn_backend`).
|
|
43
|
+
*
|
|
44
|
+
* **What the configs must share.** One Postgres database — each config's
|
|
45
|
+
* `DATABASE_URL` env names `database_url`, compared as exact strings, so two
|
|
46
|
+
* spellings of one database are refused — the session cookie name and a
|
|
47
|
+
* `SECRET_FUZ_COOKIE_KEYS` both set: a cookie one spine signs, the other must
|
|
48
|
+
* verify. A backend that resets its database at boot must have it off, or
|
|
49
|
+
* it drops what the other wrote: `FUZ_TESTING_RESET_DB_ON_STARTUP` (the Rust
|
|
50
|
+
* family's `reset_db_on_startup`) unset or a false stringbool, read as the
|
|
51
|
+
* Rust spine reads it (`EnvStringbool`). Both mount `_testing_drain_effects`
|
|
52
|
+
* and `_testing_db_invariants`, and `declined_role` is not `admin`. The
|
|
53
|
+
* suite checks all of it first. Per-process state — rate limiters, socket
|
|
54
|
+
* registries, the daemon token — is not carried over, by design.
|
|
55
|
+
*
|
|
56
|
+
* @module
|
|
57
|
+
*/
|
|
58
|
+
import { afterAll, afterEach, assert, beforeAll, describe, test } from 'vitest';
|
|
59
|
+
import { TokenCreateOutput, TokenRevokeOutput } from '../../auth/account_action_specs.js';
|
|
60
|
+
import { InviteCreateOutput } from '../../auth/admin_action_specs.js';
|
|
61
|
+
import { RoleGrantOfferAcceptOutput, RoleGrantOfferCreateOutput, RoleGrantOfferDeclineOutput, RoleGrantOfferHistoryOutput, RoleGrantOfferListOutput } from '../../auth/role_grant_offer_action_specs.js';
|
|
62
|
+
import { ROLE_ADMIN } from '../../auth/role_schema.js';
|
|
63
|
+
import { create_db } from '../../db/create_db.js';
|
|
64
|
+
import { ERROR_ALREADY_BOOTSTRAPPED, ERROR_INVALID_CREDENTIALS } from '../../http/error_schemas.js';
|
|
65
|
+
import { bootstrap } from '../transports/bootstrap.js';
|
|
66
|
+
import { expect_output } from './cross_rpc.js';
|
|
67
|
+
import { assert_backend_invariants, backend_post_json, backend_rpc, backend_rpc_as, backend_transport, drain_backend_effects, passes_admin_gate, read_shared_database_snapshot, teardown_live_backend, to_shared_database_problems, verified_account_id, with_live_backend } from './shared_database_backends.js';
|
|
68
|
+
import { SPINE_ACCOUNT_LOGIN_PATH, SPINE_ACCOUNT_LOGOUT_PATH, SPINE_ACCOUNT_PASSWORD_PATH, SPINE_ACCOUNT_SIGNUP_PATH, SPINE_ACCOUNT_STATUS_PATH, SPINE_PARTICIPANT_ROLE } from './spine_surface_constants.js';
|
|
69
|
+
/** The member account the first backend signs up. */
|
|
70
|
+
const SWAP_MEMBER_USERNAME = 'swap_member';
|
|
71
|
+
const SWAP_PASSWORD = 'swap-password-before';
|
|
72
|
+
const SWAP_PASSWORD_CHANGED = 'swap-password-after';
|
|
73
|
+
const SWAP_PASSWORD_WRONG = 'swap-password-wrong';
|
|
74
|
+
/** What a phase may take past its backend's startup window (ms). */
|
|
75
|
+
const SWAP_PHASE_WORK_MS = 30_000;
|
|
76
|
+
const login = (config, password) => backend_post_json(backend_transport(config), SPINE_ACCOUNT_LOGIN_PATH, {
|
|
77
|
+
username: SWAP_MEMBER_USERNAME,
|
|
78
|
+
password
|
|
79
|
+
});
|
|
80
|
+
/** The first backend: bootstrap, then everything the second must honor. */
|
|
81
|
+
const mint_swap_credentials = async (handle, db, declined_role) => {
|
|
82
|
+
const { config } = handle;
|
|
83
|
+
const keeper = await bootstrap({ transport: backend_transport(config), config });
|
|
84
|
+
const keeper_spare = await backend_post_json(backend_transport(config), SPINE_ACCOUNT_LOGIN_PATH, {
|
|
85
|
+
username: config.bootstrap.username,
|
|
86
|
+
password: config.bootstrap.password
|
|
87
|
+
});
|
|
88
|
+
assert.strictEqual(keeper_spare.status, 200, 'the keeper logs in again');
|
|
89
|
+
assert.strictEqual(keeper_spare.set_cookies.length, 1, 'a login sets exactly the session cookie');
|
|
90
|
+
const keeper_token = await backend_rpc_as(config, keeper.cookies, 'account_token_create', { scope: { kind: 'full' }, lifetime: { kind: 'eternal' } }, TokenCreateOutput);
|
|
91
|
+
expect_output(await backend_rpc(config, backend_transport(config, keeper.cookies), 'invite_create', {
|
|
92
|
+
username: SWAP_MEMBER_USERNAME
|
|
93
|
+
}), InviteCreateOutput);
|
|
94
|
+
const signup = await backend_post_json(backend_transport(config), SPINE_ACCOUNT_SIGNUP_PATH, {
|
|
95
|
+
username: SWAP_MEMBER_USERNAME,
|
|
96
|
+
password: SWAP_PASSWORD
|
|
97
|
+
});
|
|
98
|
+
assert.strictEqual(signup.status, 200, `signup: ${JSON.stringify(signup.body)}`);
|
|
99
|
+
const member = signup.body;
|
|
100
|
+
const logged_in = await login(config, SWAP_PASSWORD);
|
|
101
|
+
assert.strictEqual(logged_in.status, 200, 'the member logs in');
|
|
102
|
+
assert.strictEqual(logged_in.set_cookies.length, 1, 'a login sets exactly the session cookie');
|
|
103
|
+
const member_cookies = logged_in.set_cookies;
|
|
104
|
+
const token = await backend_rpc_as(config, member_cookies, 'account_token_create', { scope: { kind: 'full' }, lifetime: { kind: 'eternal' } }, TokenCreateOutput);
|
|
105
|
+
const offer = async (params) => (await backend_rpc_as(config, keeper.cookies, 'role_grant_offer_create', { to_account_id: member.account.id, ...params }, RoleGrantOfferCreateOutput)).offer.id;
|
|
106
|
+
const offer_accepted_id = await offer({ role: ROLE_ADMIN });
|
|
107
|
+
const offer_declined_id = await offer({ role: declined_role, to_actor_id: member.actor.id });
|
|
108
|
+
const { offers } = await backend_rpc_as(config, member_cookies, 'role_grant_offer_list', undefined, RoleGrantOfferListOutput);
|
|
109
|
+
assert.sameMembers(offers.map((o) => o.id), [offer_accepted_id, offer_declined_id]);
|
|
110
|
+
await drain_backend_effects(handle);
|
|
111
|
+
return {
|
|
112
|
+
keeper_id: keeper.account.id,
|
|
113
|
+
keeper_cookies: keeper.cookies,
|
|
114
|
+
keeper_spare_cookies: keeper_spare.set_cookies,
|
|
115
|
+
keeper_token: keeper_token.token,
|
|
116
|
+
keeper_token_id: keeper_token.id,
|
|
117
|
+
member_id: member.account.id,
|
|
118
|
+
member_cookies,
|
|
119
|
+
token: token.token,
|
|
120
|
+
token_id: token.id,
|
|
121
|
+
offer_accepted_id,
|
|
122
|
+
offer_declined_id,
|
|
123
|
+
snapshot: await read_shared_database_snapshot(db)
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
/** The second backend: honor everything the first minted, then write over it. */
|
|
127
|
+
const use_swap_credentials = async (handle, db, minted) => {
|
|
128
|
+
const { config } = handle;
|
|
129
|
+
// before any request but the health probe: nothing migrated, nothing written
|
|
130
|
+
assert.deepStrictEqual(await read_shared_database_snapshot(db), minted.snapshot, 'the boot applied no migration and wrote or rewrote no row');
|
|
131
|
+
const status = await backend_transport(config)(SPINE_ACCOUNT_STATUS_PATH, { method: 'GET' });
|
|
132
|
+
const status_body = (await status.json());
|
|
133
|
+
assert.strictEqual(status.status, 401, 'an anonymous status is refused');
|
|
134
|
+
assert.notStrictEqual(status_body.bootstrap_available, true, 'bootstrap is closed');
|
|
135
|
+
const rebootstrap = await backend_post_json(backend_transport(config), config.bootstrap_path, {
|
|
136
|
+
token: config.bootstrap.token,
|
|
137
|
+
username: config.bootstrap.username,
|
|
138
|
+
password: config.bootstrap.password
|
|
139
|
+
});
|
|
140
|
+
assert.strictEqual(rebootstrap.status, 403, 'a second bootstrap is refused');
|
|
141
|
+
assert.strictEqual(rebootstrap.body.error, ERROR_ALREADY_BOOTSTRAPPED);
|
|
142
|
+
assert.strictEqual(await verified_account_id(config, { cookies: minted.keeper_cookies }), minted.keeper_id, "the keeper's cookie authenticates");
|
|
143
|
+
assert.strictEqual(await verified_account_id(config, { cookies: minted.keeper_spare_cookies }), minted.keeper_id, "the keeper's second cookie authenticates");
|
|
144
|
+
assert.strictEqual(await verified_account_id(config, { bearer: minted.keeper_token }), minted.keeper_id, "the keeper's API token authenticates");
|
|
145
|
+
assert.strictEqual(await verified_account_id(config, { cookies: minted.member_cookies }), minted.member_id, "the member's cookie authenticates");
|
|
146
|
+
assert.strictEqual(await verified_account_id(config, { bearer: minted.token }), minted.member_id, "the member's API token authenticates");
|
|
147
|
+
const logged_in = await login(config, SWAP_PASSWORD);
|
|
148
|
+
assert.strictEqual(logged_in.status, 200, "the other spine's password hash verifies");
|
|
149
|
+
const member_cookies = logged_in.set_cookies;
|
|
150
|
+
const wrong = await login(config, SWAP_PASSWORD_WRONG);
|
|
151
|
+
assert.strictEqual(wrong.status, 401, 'a wrong password is refused');
|
|
152
|
+
assert.strictEqual(wrong.body.error, ERROR_INVALID_CREDENTIALS);
|
|
153
|
+
const { offers } = await backend_rpc_as(config, member_cookies, 'role_grant_offer_list', undefined, RoleGrantOfferListOutput);
|
|
154
|
+
assert.sameMembers(offers.filter((o) => o.accepted_at === null && o.declined_at === null).map((o) => o.id), [minted.offer_accepted_id, minted.offer_declined_id], 'both offers are pending');
|
|
155
|
+
assert.isFalse(await passes_admin_gate(config, member_cookies), 'no admin before the accept');
|
|
156
|
+
const declined = await backend_rpc_as(config, member_cookies, 'role_grant_offer_decline', { offer_id: minted.offer_declined_id }, RoleGrantOfferDeclineOutput);
|
|
157
|
+
assert.isNotNull(declined.offer.declined_at);
|
|
158
|
+
const accepted = await backend_rpc_as(config, member_cookies, 'role_grant_offer_accept', { offer_id: minted.offer_accepted_id }, RoleGrantOfferAcceptOutput);
|
|
159
|
+
assert.isTrue(await passes_admin_gate(config, member_cookies), 'the accepted grant confers');
|
|
160
|
+
await assert_backend_invariants(handle);
|
|
161
|
+
// the revocations of what the first spine minted: the keeper's, which
|
|
162
|
+
// nothing else ends, and the member's password change, which ends every
|
|
163
|
+
// session and token of the member's
|
|
164
|
+
const logout = await backend_post_json(backend_transport(config, minted.keeper_spare_cookies), SPINE_ACCOUNT_LOGOUT_PATH, {});
|
|
165
|
+
assert.strictEqual(logout.status, 200, "the first spine's keeper session logs out");
|
|
166
|
+
const revoked = await backend_rpc_as(config, minted.keeper_cookies, 'account_token_revoke', { token_id: minted.keeper_token_id }, TokenRevokeOutput);
|
|
167
|
+
assert.isTrue(revoked.revoked, "the first spine's keeper token is revoked");
|
|
168
|
+
assert.isNull(await verified_account_id(config, { cookies: minted.keeper_spare_cookies }), 'the logged-out keeper session is refused');
|
|
169
|
+
assert.isNull(await verified_account_id(config, { bearer: minted.keeper_token }), 'the revoked keeper token is refused');
|
|
170
|
+
const changed = await backend_post_json(backend_transport(config, member_cookies), SPINE_ACCOUNT_PASSWORD_PATH, { current_password: SWAP_PASSWORD, new_password: SWAP_PASSWORD_CHANGED });
|
|
171
|
+
assert.strictEqual(changed.status, 200, `password change: ${JSON.stringify(changed.body)}`);
|
|
172
|
+
await drain_backend_effects(handle);
|
|
173
|
+
return { member_cookies, role_grant_id: accepted.role_grant_id };
|
|
174
|
+
};
|
|
175
|
+
/** The first backend again: what the second wrote holds. */
|
|
176
|
+
const check_swap_writes = async (handle, db, minted, written) => {
|
|
177
|
+
const { config } = handle;
|
|
178
|
+
assert.deepStrictEqual((await read_shared_database_snapshot(db)).schema_version, minted.snapshot.schema_version, 'the migrations are as the first boot left them');
|
|
179
|
+
// the revocations the second spine wrote, which nothing else ended
|
|
180
|
+
assert.isNull(await verified_account_id(config, { cookies: minted.keeper_spare_cookies }), 'the keeper session the other spine logged out is refused');
|
|
181
|
+
assert.isNull(await verified_account_id(config, { bearer: minted.keeper_token }), 'the keeper token the other spine revoked is refused');
|
|
182
|
+
assert.strictEqual(await verified_account_id(config, { cookies: minted.keeper_cookies }), minted.keeper_id, "the keeper's first cookie still authenticates");
|
|
183
|
+
// the other spine's password change ended every session and token of the member's
|
|
184
|
+
assert.isNull(await verified_account_id(config, { cookies: minted.member_cookies }), "the password change ended the member's session on this spine");
|
|
185
|
+
assert.isNull(await verified_account_id(config, { cookies: written.member_cookies }), "the password change ended the member's session on the other spine");
|
|
186
|
+
assert.isNull(await verified_account_id(config, { bearer: minted.token }), "the password change ended the member's token");
|
|
187
|
+
const old_password = await login(config, SWAP_PASSWORD);
|
|
188
|
+
assert.strictEqual(old_password.status, 401, 'the old password is refused');
|
|
189
|
+
const new_password = await login(config, SWAP_PASSWORD_CHANGED);
|
|
190
|
+
assert.strictEqual(new_password.status, 200, 'the new password logs in');
|
|
191
|
+
assert.isTrue(await passes_admin_gate(config, new_password.set_cookies), 'the grant the other spine made confers');
|
|
192
|
+
const { offers } = await backend_rpc_as(config, minted.keeper_cookies, 'role_grant_offer_history', {}, RoleGrantOfferHistoryOutput);
|
|
193
|
+
const accepted = offers.find((o) => o.id === minted.offer_accepted_id);
|
|
194
|
+
const declined = offers.find((o) => o.id === minted.offer_declined_id);
|
|
195
|
+
assert.ok(accepted && declined, "the keeper's history lists both offers");
|
|
196
|
+
assert.isNotNull(accepted.accepted_at, 'the accepted offer is accepted');
|
|
197
|
+
assert.strictEqual(accepted.resulting_role_grant_id, written.role_grant_id);
|
|
198
|
+
assert.isNotNull(declined.declined_at, 'the declined offer is declined');
|
|
199
|
+
assert.isNull(declined.accepted_at);
|
|
200
|
+
await assert_backend_invariants(handle);
|
|
201
|
+
await drain_backend_effects(handle);
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Throw naming each way `order`'s configs can't swap over `database_url`
|
|
205
|
+
* (`to_shared_database_problems`, and `declined_role` not `admin`).
|
|
206
|
+
*/
|
|
207
|
+
const assert_swappable = (order, database_url, declined_role) => {
|
|
208
|
+
const problems = [];
|
|
209
|
+
if (declined_role === ROLE_ADMIN) {
|
|
210
|
+
problems.push(`declined_role is ${ROLE_ADMIN}, the accepted offer's role — a second offer of a ` +
|
|
211
|
+
'role still pending answers the first, so the two offers would be one');
|
|
212
|
+
}
|
|
213
|
+
problems.push(...to_shared_database_problems([order.first, order.second], database_url));
|
|
214
|
+
if (problems.length > 0) {
|
|
215
|
+
throw new Error(`backend swap '${order.label}': ${problems.join('; ')}`);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Describe the backend swap over each order (§module doc): three tests per
|
|
220
|
+
* order, run in turn, each phase spawning and stopping its own backend. A
|
|
221
|
+
* phase whose predecessor failed fails naming it.
|
|
222
|
+
*
|
|
223
|
+
* @param options - the orders, the shared database, and how to empty it
|
|
224
|
+
*/
|
|
225
|
+
export const describe_backend_swap_tests = (options) => {
|
|
226
|
+
const { orders, database_url, empty_database, declined_role = SPINE_PARTICIPANT_ROLE } = options;
|
|
227
|
+
describe('backend swap', () => {
|
|
228
|
+
let db = null;
|
|
229
|
+
let close_db = null;
|
|
230
|
+
beforeAll(async () => {
|
|
231
|
+
const created = await create_db(database_url);
|
|
232
|
+
db = created.db;
|
|
233
|
+
close_db = created.close;
|
|
234
|
+
});
|
|
235
|
+
afterAll(async () => {
|
|
236
|
+
await close_db?.();
|
|
237
|
+
});
|
|
238
|
+
const get_db = () => {
|
|
239
|
+
assert.ok(db, 'the snapshot connection is open');
|
|
240
|
+
return db;
|
|
241
|
+
};
|
|
242
|
+
for (const order of orders) {
|
|
243
|
+
const { label, first, second } = order;
|
|
244
|
+
const timeout = Math.max(first.startup_timeout_ms, second.startup_timeout_ms) + SWAP_PHASE_WORK_MS;
|
|
245
|
+
const state = {};
|
|
246
|
+
const live = { handle: null };
|
|
247
|
+
describe(label, () => {
|
|
248
|
+
afterEach(() => teardown_live_backend(live));
|
|
249
|
+
test(`${first.name} mints credentials over an empty database`, async () => {
|
|
250
|
+
assert_swappable(order, database_url, declined_role);
|
|
251
|
+
await empty_database();
|
|
252
|
+
state.minted = await with_live_backend(first, live, (handle) => mint_swap_credentials(handle, get_db(), declined_role));
|
|
253
|
+
}, timeout);
|
|
254
|
+
test(`${second.name} boots over them and honors each`, async () => {
|
|
255
|
+
const { minted } = state;
|
|
256
|
+
assert.ok(minted, `${first.name}'s mint phase did not complete`);
|
|
257
|
+
state.written = await with_live_backend(second, live, (handle) => use_swap_credentials(handle, get_db(), minted));
|
|
258
|
+
}, timeout);
|
|
259
|
+
test(`${first.name} boots again and honors what ${second.name} wrote`, async () => {
|
|
260
|
+
const { minted, written } = state;
|
|
261
|
+
assert.ok(minted && written, `${second.name}'s phase did not complete`);
|
|
262
|
+
await with_live_backend(first, live, (handle) => check_swap_writes(handle, get_db(), minted, written));
|
|
263
|
+
}, timeout);
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
};
|
|
@@ -20,9 +20,9 @@ import '../assert_dev_env.js';
|
|
|
20
20
|
* - **Node** closes at once with the body unread — `create_app_server`'s body
|
|
21
21
|
* limit (`http/body_limit.ts`) refuses on the header and answers
|
|
22
22
|
* `Connection: close`, which is what makes `@hono/node-server` close.
|
|
23
|
-
* - **Bun** closes at once too, honouring that header. Bun 1.4.
|
|
24
|
-
* floor:
|
|
25
|
-
* request (correctly framed), which fails this suite.
|
|
23
|
+
* - **Bun** closes at once too, honouring that header. Bun 1.4.4 is the tested
|
|
24
|
+
* floor: a Bun older than 1.4.3 kept the connection after the 413 and served
|
|
25
|
+
* the next request (correctly framed), which fails this suite.
|
|
26
26
|
* - **hyper** (the Rust spine) closes at once.
|
|
27
27
|
*
|
|
28
28
|
* The oversized body is rejected *with* a 413 on every backend — pinned
|
|
@@ -23,12 +23,12 @@ export const bootstrap_backend = async (config, options) => {
|
|
|
23
23
|
return {
|
|
24
24
|
...handle,
|
|
25
25
|
keeper_transport,
|
|
26
|
-
//
|
|
27
|
-
// daemon-token middleware discards the
|
|
28
|
-
// context, so the `_testing_*` daemon-token
|
|
26
|
+
// cookie-free, so a daemon-token call carries that credential alone,
|
|
27
|
+
// and Origin-free — the daemon-token middleware discards the
|
|
28
|
+
// credential in a browser context, so the `_testing_*` daemon-token
|
|
29
|
+
// calls route through this
|
|
29
30
|
keeper_daemon_transport: create_fetch_transport({
|
|
30
31
|
base_url: config.base_url,
|
|
31
|
-
initial_cookies: keeper.cookies,
|
|
32
32
|
origin: null
|
|
33
33
|
}),
|
|
34
34
|
keeper_account: keeper.account,
|
|
@@ -78,8 +78,9 @@ import type { SessionCookieEffect } from './session_cookie_effect.js';
|
|
|
78
78
|
* [SCOPED_TOKEN_ADMITTED_METHOD]}`), non-browser context. Minted through the
|
|
79
79
|
* production `account_token_create` path over the keeper's session, not
|
|
80
80
|
* seeded — `_testing_reset` deliberately seeds a `full` token, and a harness
|
|
81
|
-
* that narrowed the seed would silently re-scope every other bearer case
|
|
82
|
-
*
|
|
81
|
+
* that narrowed the seed would silently re-scope every other bearer case —
|
|
82
|
+
* and proven to authenticate as the keeper on `SCOPED_TOKEN_ADMITTED_METHOD`
|
|
83
|
+
* before any case is sent as it. The scope gate sits between the credential gate and the role gate, so this
|
|
83
84
|
* principal is what distinguishes `token_scope_required` from the
|
|
84
85
|
* credential-type and role denials on either side of it.
|
|
85
86
|
* - `anonymous` — no credential, fresh cookie jar.
|
|
@@ -91,10 +92,6 @@ import type { SessionCookieEffect } from './session_cookie_effect.js';
|
|
|
91
92
|
* - `wrong_role` — a seeded `extra_accounts` principal holding a role
|
|
92
93
|
* other than the one a route requires; named via
|
|
93
94
|
* `ConformanceTableOptions.principals.wrong_role`.
|
|
94
|
-
* - `expired_session` — the keeper account presented via an *expired
|
|
95
|
-
* server-side session* cookie (minted by `fixture.mint_expired_session()`:
|
|
96
|
-
* a backdated `auth_session` row behind a still-valid signed cookie
|
|
97
|
-
* payload, so the authoritative DB-row expiry gate is what refuses it).
|
|
98
95
|
*
|
|
99
96
|
* The dead credentials — each presented alone, on a fresh jar, so the request
|
|
100
97
|
* carries that credential and nothing else; each arrives anonymous, so a row
|
|
@@ -112,6 +109,10 @@ import type { SessionCookieEffect } from './session_cookie_effect.js';
|
|
|
112
109
|
* - `revoked_session` — a session cookie that verifies, whose `auth_session`
|
|
113
110
|
* row has been revoked (`fixture.mint_revoked_session()`). The cookie alone
|
|
114
111
|
* shows nothing wrong, so it is not cleared.
|
|
112
|
+
* - `expired_session` — a session cookie that authenticated and whose
|
|
113
|
+
* `auth_session` row has since expired (`fixture.mint_expired_session()`):
|
|
114
|
+
* the signed cookie payload still verifies, so the authoritative DB-row
|
|
115
|
+
* expiry gate is what refuses it.
|
|
115
116
|
* - `revoked_token` — an API token that was minted and then revoked
|
|
116
117
|
* (`fixture.mint_revoked_token()`), with no `Origin`.
|
|
117
118
|
* - `expired_token` — an API token whose row is past its `expires_at`
|
|
@@ -127,6 +128,10 @@ export type ConformancePrincipal = 'keeper' | 'daemon' | 'invalid_daemon' | 'dae
|
|
|
127
128
|
* credential gate a bearer must pass first, and holds no role gate that could
|
|
128
129
|
* shadow the scope denial — so a case naming any *other* method isolates the
|
|
129
130
|
* scope gate and nothing else.
|
|
131
|
+
*
|
|
132
|
+
* It is also the method the principal's liveness proof sends
|
|
133
|
+
* (`assert_credential_authenticates` calls `account_verify_action_spec`), so
|
|
134
|
+
* the narrowed token can be proven live only while the two are one method.
|
|
130
135
|
*/
|
|
131
136
|
export declare const SCOPED_TOKEN_ADMITTED_METHOD = "account_verify";
|
|
132
137
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conformance_case.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/conformance_case.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE
|
|
1
|
+
{"version":3,"file":"conformance_case.d.ts","sourceRoot":"","sources":["../../../src/lib/testing/cross_backend/conformance_case.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2FG;AACH,MAAM,MAAM,oBAAoB,GAC7B,QAAQ,GACR,QAAQ,GACR,gBAAgB,GAChB,gBAAgB,GAChB,OAAO,GACP,gBAAgB,GAChB,kBAAkB,GAClB,cAAc,GACd,WAAW,GACX,iBAAiB,GACjB,aAAa,GACb,YAAY,GACZ,iBAAiB,GACjB,iBAAiB,GACjB,cAAc,GACd,gBAAgB,GAChB,iBAAiB,GACjB,eAAe,GACf,eAAe,CAAC;AAEnB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,4BAA4B,mBAAmB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,wBAAwB,GAAG,WAAW,GAAG,aAAa,GAAG,cAAc,CAAC;AAEpF,6CAA6C;AAC7C,MAAM,WAAW,sBAAsB;IACtC;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,uDAAuD;IACvD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,oBAAoB,CAAC;IACzB;;;;OAIG;IACH,MAAM,CAAC,EAAE,wBAAwB,CAAC;IAClC,4EAA4E;IAC5E,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CACtB;AAED,8DAA8D;AAC9D,MAAM,WAAW,0BAA0B;IAC1C,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf;;;;;;;;;OASG;IACH,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B;;;;;;;;OAQG;IACH,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC;;;;;;;;;;OAUG;IACH,aAAa,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;IACxC;;;;;;;;;;OAUG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,eAAe;IAC/B,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,sBAAsB,CAAC;IAChC,MAAM,EAAE,0BAA0B,CAAC;IACnC,4DAA4D;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC;CACpB"}
|
|
@@ -8,5 +8,9 @@ import '../assert_dev_env.js';
|
|
|
8
8
|
* credential gate a bearer must pass first, and holds no role gate that could
|
|
9
9
|
* shadow the scope denial — so a case naming any *other* method isolates the
|
|
10
10
|
* scope gate and nothing else.
|
|
11
|
+
*
|
|
12
|
+
* It is also the method the principal's liveness proof sends
|
|
13
|
+
* (`assert_credential_authenticates` calls `account_verify_action_spec`), so
|
|
14
|
+
* the narrowed token can be proven live only while the two are one method.
|
|
11
15
|
*/
|
|
12
16
|
export const SCOPED_TOKEN_ADMITTED_METHOD = 'account_verify';
|
|
@@ -2,7 +2,7 @@ import '../assert_dev_env.js';
|
|
|
2
2
|
import { type resolve_rpc_endpoints_for_setup } from '../rpc_helpers.js';
|
|
3
3
|
import type { FetchTransport } from '../transports/fetch_transport.js';
|
|
4
4
|
import { type ConformancePrincipal } from './conformance_case.js';
|
|
5
|
-
import type
|
|
5
|
+
import { type TestFixture } from './setup.js';
|
|
6
6
|
/**
|
|
7
7
|
* Names a seeded `extra_accounts` username for the `role_holder` /
|
|
8
8
|
* `wrong_role` principals — the only two that aren't backed by an
|
|
@@ -27,7 +27,7 @@ export interface ResolvedConformancePrincipal {
|
|
|
27
27
|
readonly suppress_default_origin?: boolean;
|
|
28
28
|
/**
|
|
29
29
|
* The actor of the account the credential names — what the `principal`
|
|
30
|
-
* acting binding writes. Absent for principals that present no account.
|
|
30
|
+
* acting binding writes. Absent for principals that present no live account.
|
|
31
31
|
*/
|
|
32
32
|
readonly actor_id?: string;
|
|
33
33
|
}
|