@sasjs/api 0.18.1 → 0.20.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/build/browser.js +820 -29
- package/build/cjs/admin/service.js +209 -0
- package/build/cjs/authconfig/service.js +139 -0
- package/build/cjs/corpus/admin.js +101 -0
- package/build/cjs/corpus/authconfig.js +47 -0
- package/build/cjs/corpus/directory.js +31 -0
- package/build/cjs/corpus/home.js +51 -0
- package/build/cjs/corpus/runner.js +16 -0
- package/build/cjs/directory/service.js +116 -0
- package/build/cjs/home/service.js +103 -0
- package/build/cjs/host/dispatch.js +67 -8
- package/build/cjs/identity/memory-store.js +4 -1
- package/build/cjs/index.js +25 -12
- package/build/cjs/routes/generated.js +56 -0
- package/build/cjs/routes/overlay.js +97 -15
- package/build/esm/admin/service.d.ts +123 -0
- package/build/esm/admin/service.d.ts.map +1 -0
- package/build/esm/admin/service.js +201 -0
- package/build/esm/authconfig/service.d.ts +92 -0
- package/build/esm/authconfig/service.d.ts.map +1 -0
- package/build/esm/authconfig/service.js +134 -0
- package/build/esm/corpus/admin.d.ts +22 -0
- package/build/esm/corpus/admin.d.ts.map +1 -0
- package/build/esm/corpus/admin.js +98 -0
- package/build/esm/corpus/authconfig.d.ts +31 -0
- package/build/esm/corpus/authconfig.d.ts.map +1 -0
- package/build/esm/corpus/authconfig.js +44 -0
- package/build/esm/corpus/directory.d.ts +20 -0
- package/build/esm/corpus/directory.d.ts.map +1 -0
- package/build/esm/corpus/directory.js +28 -0
- package/build/esm/corpus/home.d.ts +27 -0
- package/build/esm/corpus/home.d.ts.map +1 -0
- package/build/esm/corpus/home.js +48 -0
- package/build/esm/corpus/runner.d.ts.map +1 -1
- package/build/esm/corpus/runner.js +16 -0
- package/build/esm/directory/service.d.ts +71 -0
- package/build/esm/directory/service.d.ts.map +1 -0
- package/build/esm/directory/service.js +112 -0
- package/build/esm/home/service.d.ts +69 -0
- package/build/esm/home/service.d.ts.map +1 -0
- package/build/esm/home/service.js +98 -0
- package/build/esm/host/dispatch.d.ts +37 -0
- package/build/esm/host/dispatch.d.ts.map +1 -1
- package/build/esm/host/dispatch.js +65 -7
- package/build/esm/identity/memory-store.d.ts.map +1 -1
- package/build/esm/identity/memory-store.js +4 -1
- package/build/esm/identity/types.d.ts +5 -0
- package/build/esm/identity/types.d.ts.map +1 -1
- package/build/esm/index.d.ts +6 -0
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js +5 -0
- package/build/esm/routes/generated.d.ts.map +1 -1
- package/build/esm/routes/generated.js +56 -0
- package/build/esm/routes/overlay.d.ts.map +1 -1
- package/build/esm/routes/overlay.js +97 -15
- package/package.json +1 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAdminService = exports.logLines = exports.checkLogFileName = exports.normaliseLogFiles = exports.normaliseDiagnostics = exports.MAX_LOG_LINES = exports.DEFAULT_LOG_LINES = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The three Admin reports: this host's own process, memory, disk and logs.
|
|
6
|
+
*
|
|
7
|
+
* The values are the host's - a pid, a folder walk, the tail of a file - and a
|
|
8
|
+
* browser build has no equivalent, so the reports are supplied through a port.
|
|
9
|
+
* What this file owns is everything a client keys on:
|
|
10
|
+
*
|
|
11
|
+
* - the body's shape, because a diagnostics page that reads
|
|
12
|
+
* `memory.rssBytes` renders `NaN` when a host omits it, and a report that is
|
|
13
|
+
* missing a field is a host bug rather than an empty reading;
|
|
14
|
+
* - the log file name rule: a bare name ending in `.log`, refused with `400`
|
|
15
|
+
* for anything that could resolve outside the log folder (`..`, a
|
|
16
|
+
* separator, an absolute path). The host resolves the name inside its own
|
|
17
|
+
* folder - this is the same rule sasjs/server applies before it touches the
|
|
18
|
+
* filesystem, and doing it here means both hosts refuse a traversal the same
|
|
19
|
+
* way;
|
|
20
|
+
* - `404` for a name that is not there, `200` with a bounded tail otherwise,
|
|
21
|
+
* and the line count clamped to the documented default and maximum so a
|
|
22
|
+
* caller cannot ask a host to read a gigabyte.
|
|
23
|
+
*
|
|
24
|
+
* `GET /admin/diagnostics`, `GET /admin/logs` and `GET /admin/logs/{fileName}`
|
|
25
|
+
* are mounted behind the host's own administrator middleware (sasjs/server puts
|
|
26
|
+
* `authenticateAccessToken` and `verifyAdmin` in front of all three), so the
|
|
27
|
+
* caller's right to read these is the host's decision and is marked
|
|
28
|
+
* `hostResponses` in the overlay.
|
|
29
|
+
*/
|
|
30
|
+
const types_js_1 = require("../types.js");
|
|
31
|
+
/** The documented defaults on the route's `lines` parameter. */
|
|
32
|
+
exports.DEFAULT_LOG_LINES = 200;
|
|
33
|
+
exports.MAX_LOG_LINES = 5000;
|
|
34
|
+
const isObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
35
|
+
const isNumber = (value) => typeof value === 'number' && Number.isFinite(value);
|
|
36
|
+
const isString = (value) => typeof value === 'string';
|
|
37
|
+
const requireString = (holder, key, where) => {
|
|
38
|
+
if (!isString(holder[key]))
|
|
39
|
+
throw new Error(`The ${where} report states \`${key}\` as ${JSON.stringify(holder[key])}; the document states a string, and a client that renders it would print the value as it stands.`);
|
|
40
|
+
};
|
|
41
|
+
const requireNumber = (holder, key, where) => {
|
|
42
|
+
if (!isNumber(holder[key]))
|
|
43
|
+
throw new Error(`The ${where} report states \`${key}\` as ${JSON.stringify(holder[key])}; the document states a number, and a client that renders it would print NaN.`);
|
|
44
|
+
};
|
|
45
|
+
const requireObject = (holder, key, where) => {
|
|
46
|
+
const value = holder[key];
|
|
47
|
+
if (!isObject(value))
|
|
48
|
+
throw new Error(`The ${where} report states \`${key}\` as ${JSON.stringify(value)}; the document states an object.`);
|
|
49
|
+
return value;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The diagnostics body, checked field by field.
|
|
53
|
+
*
|
|
54
|
+
* A host that cannot read its filesystem states `filesystem: null`, which the
|
|
55
|
+
* document allows; a host that cannot read anything at all should refuse the
|
|
56
|
+
* request itself, because an empty object here renders as a page of zeroes.
|
|
57
|
+
*/
|
|
58
|
+
const normaliseDiagnostics = (report) => {
|
|
59
|
+
if (!isObject(report))
|
|
60
|
+
throw new Error('The diagnostics report is not an object.');
|
|
61
|
+
const build = requireObject(report, 'build', 'diagnostics');
|
|
62
|
+
requireString(build, 'version', 'diagnostics build');
|
|
63
|
+
requireString(build, 'gitHash', 'diagnostics build');
|
|
64
|
+
if (!(build.buildDate === null || isString(build.buildDate)))
|
|
65
|
+
throw new Error(`The diagnostics build states \`buildDate\` as ${JSON.stringify(build.buildDate)}; the document states an ISO timestamp or null.`);
|
|
66
|
+
const server = requireObject(report, 'server', 'diagnostics');
|
|
67
|
+
requireString(server, 'mode', 'diagnostics server');
|
|
68
|
+
requireString(server, 'startedAt', 'diagnostics server');
|
|
69
|
+
requireString(server, 'nodeVersion', 'diagnostics server');
|
|
70
|
+
requireString(server, 'platform', 'diagnostics server');
|
|
71
|
+
requireString(server, 'arch', 'diagnostics server');
|
|
72
|
+
requireString(server, 'cpuModel', 'diagnostics server');
|
|
73
|
+
requireString(server, 'sasjsRoot', 'diagnostics server');
|
|
74
|
+
requireNumber(server, 'uptimeSeconds', 'diagnostics server');
|
|
75
|
+
requireNumber(server, 'pid', 'diagnostics server');
|
|
76
|
+
requireNumber(server, 'cpuCount', 'diagnostics server');
|
|
77
|
+
if (!Array.isArray(server.loadAverage) || !server.loadAverage.every(isNumber))
|
|
78
|
+
throw new Error('The diagnostics server report states `loadAverage` as something other than an array of numbers.');
|
|
79
|
+
if (!Array.isArray(server.runTimes) || !server.runTimes.every(isString))
|
|
80
|
+
throw new Error('The diagnostics server report states `runTimes` as something other than an array of strings.');
|
|
81
|
+
const memory = requireObject(report, 'memory', 'diagnostics');
|
|
82
|
+
for (const key of [
|
|
83
|
+
'rssBytes',
|
|
84
|
+
'heapTotalBytes',
|
|
85
|
+
'heapUsedBytes',
|
|
86
|
+
'externalBytes',
|
|
87
|
+
'systemTotalBytes',
|
|
88
|
+
'systemFreeBytes'
|
|
89
|
+
])
|
|
90
|
+
requireNumber(memory, key, 'diagnostics memory');
|
|
91
|
+
const filesystem = report.filesystem;
|
|
92
|
+
if (filesystem !== null) {
|
|
93
|
+
if (!isObject(filesystem))
|
|
94
|
+
throw new Error(`The diagnostics report states \`filesystem\` as ${JSON.stringify(filesystem)}; the document states an object or null.`);
|
|
95
|
+
requireString(filesystem, 'path', 'diagnostics filesystem');
|
|
96
|
+
for (const key of ['totalBytes', 'freeBytes', 'usedBytes', 'usedPercent'])
|
|
97
|
+
requireNumber(filesystem, key, 'diagnostics filesystem');
|
|
98
|
+
}
|
|
99
|
+
if (!Array.isArray(report.folders))
|
|
100
|
+
throw new Error('The diagnostics report states `folders` as something other than an array.');
|
|
101
|
+
for (const folder of report.folders) {
|
|
102
|
+
if (!isObject(folder))
|
|
103
|
+
throw new Error('The diagnostics report carries a folder that is not an object.');
|
|
104
|
+
const entry = folder;
|
|
105
|
+
requireString(entry, 'label', 'diagnostics folder');
|
|
106
|
+
requireString(entry, 'path', 'diagnostics folder');
|
|
107
|
+
requireNumber(entry, 'bytes', 'diagnostics folder');
|
|
108
|
+
requireNumber(entry, 'files', 'diagnostics folder');
|
|
109
|
+
if (typeof entry.exists !== 'boolean' ||
|
|
110
|
+
typeof entry.truncated !== 'boolean')
|
|
111
|
+
throw new Error('The diagnostics folder report states `exists` or `truncated` as something other than a boolean.');
|
|
112
|
+
}
|
|
113
|
+
const logs = requireObject(report, 'logs', 'diagnostics');
|
|
114
|
+
requireString(logs, 'folder', 'diagnostics logs');
|
|
115
|
+
requireNumber(logs, 'fileCount', 'diagnostics logs');
|
|
116
|
+
requireNumber(logs, 'totalBytes', 'diagnostics logs');
|
|
117
|
+
for (const key of ['newestFile', 'newestModified'])
|
|
118
|
+
if (!(logs[key] === null || isString(logs[key])))
|
|
119
|
+
throw new Error(`The diagnostics logs summary states \`${key}\` as ${JSON.stringify(logs[key])}; the document states a string or null.`);
|
|
120
|
+
return report;
|
|
121
|
+
};
|
|
122
|
+
exports.normaliseDiagnostics = normaliseDiagnostics;
|
|
123
|
+
/** The log listing, checked entry by entry. */
|
|
124
|
+
const normaliseLogFiles = (files) => {
|
|
125
|
+
if (!Array.isArray(files))
|
|
126
|
+
throw new Error('The log report is not an array of files.');
|
|
127
|
+
return files.map((file) => {
|
|
128
|
+
if (!isObject(file))
|
|
129
|
+
throw new Error('The log report carries an entry that is not an object.');
|
|
130
|
+
const entry = file;
|
|
131
|
+
requireString(entry, 'name', 'logs');
|
|
132
|
+
requireString(entry, 'modified', 'logs');
|
|
133
|
+
requireNumber(entry, 'sizeBytes', 'logs');
|
|
134
|
+
return file;
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
exports.normaliseLogFiles = normaliseLogFiles;
|
|
138
|
+
/**
|
|
139
|
+
* A log file name the route will hand to a host.
|
|
140
|
+
*
|
|
141
|
+
* The rule is sasjs/server's, applied before the filesystem: a bare name ending
|
|
142
|
+
* in `.log`. `.` and `..` are refused by the basename check, because both have a
|
|
143
|
+
* basename equal to themselves and neither ends in `.log`.
|
|
144
|
+
*/
|
|
145
|
+
const checkLogFileName = (fileName) => {
|
|
146
|
+
if (!fileName ||
|
|
147
|
+
fileName.includes('/') ||
|
|
148
|
+
fileName.includes('\\') ||
|
|
149
|
+
fileName.split(/[\\/]/).pop() !== fileName ||
|
|
150
|
+
!fileName.toLowerCase().endsWith('.log'))
|
|
151
|
+
throw new types_js_1.ApiError(400, 'Invalid log file name.');
|
|
152
|
+
return fileName;
|
|
153
|
+
};
|
|
154
|
+
exports.checkLogFileName = checkLogFileName;
|
|
155
|
+
/**
|
|
156
|
+
* How many trailing lines to return.
|
|
157
|
+
*
|
|
158
|
+
* A caller's `lines` is text on the wire, so an absent or unusable value is the
|
|
159
|
+
* documented default rather than a refusal - the parameter is a preference, not
|
|
160
|
+
* a requirement. The ceiling is the document's maximum, so a host is never asked
|
|
161
|
+
* to read more than it stated it would.
|
|
162
|
+
*/
|
|
163
|
+
const logLines = (lines) => {
|
|
164
|
+
// `?lines=` is absent in every sense that matters: a caller that sent the
|
|
165
|
+
// parameter with no value asked for the default, not for zero lines
|
|
166
|
+
if (lines === undefined || lines === null || lines === '')
|
|
167
|
+
return exports.DEFAULT_LOG_LINES;
|
|
168
|
+
const wanted = Number(lines);
|
|
169
|
+
if (!Number.isFinite(wanted))
|
|
170
|
+
return exports.DEFAULT_LOG_LINES;
|
|
171
|
+
return Math.min(Math.max(Math.trunc(wanted), 1), exports.MAX_LOG_LINES);
|
|
172
|
+
};
|
|
173
|
+
exports.logLines = logLines;
|
|
174
|
+
/** The tail, checked against the shape the document states. */
|
|
175
|
+
const normaliseLogTail = (tail) => {
|
|
176
|
+
if (!isObject(tail))
|
|
177
|
+
throw new Error('The log tail report is not an object.');
|
|
178
|
+
const entry = tail;
|
|
179
|
+
requireString(entry, 'fileName', 'log tail');
|
|
180
|
+
requireString(entry, 'content', 'log tail');
|
|
181
|
+
requireNumber(entry, 'lines', 'log tail');
|
|
182
|
+
requireNumber(entry, 'bytesRead', 'log tail');
|
|
183
|
+
if (typeof entry.truncated !== 'boolean')
|
|
184
|
+
throw new Error('The log tail report states `truncated` as something other than a boolean.');
|
|
185
|
+
return tail;
|
|
186
|
+
};
|
|
187
|
+
/**
|
|
188
|
+
* The admin service, over the host's reports.
|
|
189
|
+
*
|
|
190
|
+
* The name rule and the line clamp run here, before the host is asked for
|
|
191
|
+
* anything: a host that resolves an unchecked name is a host that can be talked
|
|
192
|
+
* into reading outside its log folder.
|
|
193
|
+
*/
|
|
194
|
+
const createAdminService = (reports) => ({
|
|
195
|
+
async diagnostics() {
|
|
196
|
+
return (0, exports.normaliseDiagnostics)(await reports.diagnostics());
|
|
197
|
+
},
|
|
198
|
+
async logs() {
|
|
199
|
+
return (0, exports.normaliseLogFiles)(await reports.logs());
|
|
200
|
+
},
|
|
201
|
+
async logTail(fileName, lines) {
|
|
202
|
+
const name = (0, exports.checkLogFileName)(fileName);
|
|
203
|
+
const tail = await reports.logTail(name, (0, exports.logLines)(lines));
|
|
204
|
+
if (tail === undefined)
|
|
205
|
+
throw new types_js_1.ApiError(404, 'Log file not found.');
|
|
206
|
+
return normaliseLogTail(tail);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
exports.createAdminService = createAdminService;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The provider configuration an administrator is allowed to read.
|
|
4
|
+
*
|
|
5
|
+
* `GET /SASjsApi/authConfig` exists so the administration interface can show
|
|
6
|
+
* which external providers a host was started with. The values are the host's
|
|
7
|
+
* environment; the decision this file owns is what may leave the process:
|
|
8
|
+
*
|
|
9
|
+
* - only providers that are enabled appear, so the interface cannot offer to
|
|
10
|
+
* edit a provider the host does not have;
|
|
11
|
+
* - a secret is never echoed - the answer carries `LDAP_BIND_PASSWORD_SET` and
|
|
12
|
+
* `OIDC_CLIENT_SECRET_SET` (whether one is configured) and not the value.
|
|
13
|
+
* sasjs/server reads the bind password and the client secret from the
|
|
14
|
+
* environment and reports only those booleans, because this response is
|
|
15
|
+
* rendered into the admin page, the browser's state, the cache and any
|
|
16
|
+
* proxy log in the path;
|
|
17
|
+
* - a host that hands this service something shaped like a secret is refused
|
|
18
|
+
* by name rather than served, so a host cannot leak one through the route by
|
|
19
|
+
* naming a field the interface happens to render.
|
|
20
|
+
*
|
|
21
|
+
* The keys are the environment's own names (`LDAP_URL`, `OIDC_CLIENT_SECRET_SET`)
|
|
22
|
+
* because that is what sasjs/server answers and what the admin page reads - a
|
|
23
|
+
* translation here would be a second contract.
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.createAuthConfigService = exports.normaliseAuthConfig = void 0;
|
|
27
|
+
/** The fields each provider block may carry, in the order the interface reads them. */
|
|
28
|
+
const LDAP_FIELDS = [
|
|
29
|
+
'url',
|
|
30
|
+
'bindDn',
|
|
31
|
+
'usersBaseDn',
|
|
32
|
+
'groupsBaseDn',
|
|
33
|
+
'bindPasswordSet'
|
|
34
|
+
];
|
|
35
|
+
const OIDC_FIELDS = [
|
|
36
|
+
'providerName',
|
|
37
|
+
'issuerUrl',
|
|
38
|
+
'clientId',
|
|
39
|
+
'redirectUri',
|
|
40
|
+
'scope',
|
|
41
|
+
'signingAlg',
|
|
42
|
+
'usernameClaim',
|
|
43
|
+
'jitProvision',
|
|
44
|
+
'clientSecretSet'
|
|
45
|
+
];
|
|
46
|
+
/**
|
|
47
|
+
* Anything with one of these words in its name is a secret.
|
|
48
|
+
*
|
|
49
|
+
* The check is on the name rather than the value because the value is what a
|
|
50
|
+
* host would have to hand over, and a host that hands it over has already lost:
|
|
51
|
+
* this route is readable, logged and cached. `*Set` is the documented way to say
|
|
52
|
+
* that one exists.
|
|
53
|
+
*/
|
|
54
|
+
const SECRET = /(password|secret|passwd|token)/i;
|
|
55
|
+
const checkProvider = (name, block, fields, booleans) => {
|
|
56
|
+
if (!block || typeof block !== 'object')
|
|
57
|
+
throw new Error(`The auth configuration states \`${name}\` as ${JSON.stringify(block)}; a provider is an object, or absent when it is not enabled.`);
|
|
58
|
+
for (const key of Object.keys(block)) {
|
|
59
|
+
if (!fields.includes(key))
|
|
60
|
+
throw new Error(SECRET.test(key)
|
|
61
|
+
? `The auth configuration states \`${name}.${key}\`, which looks like a secret. Secrets are never echoed by this route: pass \`${key}Set: true\` instead, so the answer carries whether one is configured and not the value.`
|
|
62
|
+
: `The auth configuration carries \`${name}.${key}\`, which the document's example does not state. Remove it, or add it to the provider's fields here and to the document.`);
|
|
63
|
+
}
|
|
64
|
+
for (const key of fields) {
|
|
65
|
+
if (!(key in block))
|
|
66
|
+
throw new Error(`The auth configuration does not state \`${name}.${key}\`, which the administration interface reads. State the empty string when the host has no value for it.`);
|
|
67
|
+
const value = block[key];
|
|
68
|
+
if (booleans.includes(key)) {
|
|
69
|
+
if (typeof value !== 'boolean')
|
|
70
|
+
throw new Error(`The auth configuration states \`${name}.${key}\` as ${JSON.stringify(value)}; it says whether the secret is configured, so it is a boolean.`);
|
|
71
|
+
}
|
|
72
|
+
else if (typeof value !== 'string')
|
|
73
|
+
throw new Error(`The auth configuration states \`${name}.${key}\` as ${JSON.stringify(value)}; the document states a string.`);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The configuration, checked and rendered in the document's key names.
|
|
78
|
+
*
|
|
79
|
+
* Refusals are `Error` rather than `ApiError`: a host that passes a secret, or a
|
|
80
|
+
* provider block with no fields, is misconfigured rather than answering a bad
|
|
81
|
+
* request, and a `500` carrying its own configuration problem would blame the
|
|
82
|
+
* caller.
|
|
83
|
+
*/
|
|
84
|
+
const normaliseAuthConfig = (config) => {
|
|
85
|
+
if (!config || typeof config !== 'object')
|
|
86
|
+
throw new Error('The auth configuration is not an object.');
|
|
87
|
+
for (const key of Object.keys(config))
|
|
88
|
+
if (key !== 'ldap' && key !== 'oidc')
|
|
89
|
+
throw new Error(SECRET.test(key)
|
|
90
|
+
? `The auth configuration states \`${key}\` at the top level, which looks like a secret. Secrets are never echoed by this route; put the provider under \`ldap\` or \`oidc\` and report whether the secret is set.`
|
|
91
|
+
: `The auth configuration carries \`${key}\`, which is not a provider this API has. The document states \`ldap\` and \`oidc\`.`);
|
|
92
|
+
const answer = {};
|
|
93
|
+
if (config.ldap !== undefined) {
|
|
94
|
+
checkProvider('ldap', config.ldap, LDAP_FIELDS, ['bindPasswordSet']);
|
|
95
|
+
answer.ldap = {
|
|
96
|
+
LDAP_URL: config.ldap.url,
|
|
97
|
+
LDAP_BIND_DN: config.ldap.bindDn,
|
|
98
|
+
LDAP_USERS_BASE_DN: config.ldap.usersBaseDn,
|
|
99
|
+
LDAP_GROUPS_BASE_DN: config.ldap.groupsBaseDn,
|
|
100
|
+
LDAP_BIND_PASSWORD_SET: config.ldap.bindPasswordSet
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
if (config.oidc !== undefined) {
|
|
104
|
+
checkProvider('oidc', config.oidc, OIDC_FIELDS, ['clientSecretSet']);
|
|
105
|
+
answer.oidc = {
|
|
106
|
+
OIDC_PROVIDER_NAME: config.oidc.providerName,
|
|
107
|
+
OIDC_ISSUER_URL: config.oidc.issuerUrl,
|
|
108
|
+
OIDC_CLIENT_ID: config.oidc.clientId,
|
|
109
|
+
OIDC_REDIRECT_URI: config.oidc.redirectUri,
|
|
110
|
+
OIDC_SCOPE: config.oidc.scope,
|
|
111
|
+
OIDC_SIGNING_ALG: config.oidc.signingAlg,
|
|
112
|
+
OIDC_USERNAME_CLAIM: config.oidc.usernameClaim,
|
|
113
|
+
OIDC_JIT_PROVISION: config.oidc.jitProvision,
|
|
114
|
+
OIDC_CLIENT_SECRET_SET: config.oidc.clientSecretSet
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
// an empty object is the documented answer for a host with no external
|
|
118
|
+
// provider, so it is not an error: the login screen then offers only the
|
|
119
|
+
// local form
|
|
120
|
+
return answer;
|
|
121
|
+
};
|
|
122
|
+
exports.normaliseAuthConfig = normaliseAuthConfig;
|
|
123
|
+
/**
|
|
124
|
+
* The auth-config service, over the host's own environment.
|
|
125
|
+
*
|
|
126
|
+
* A getter is accepted because the values are read from the environment and a
|
|
127
|
+
* host can be reconfigured without a restart in some deployments; reading per
|
|
128
|
+
* request keeps the answer true. The values never leave the process - only the
|
|
129
|
+
* two `*_SET` booleans describe the secrets.
|
|
130
|
+
*/
|
|
131
|
+
const createAuthConfigService = (config) => {
|
|
132
|
+
const read = () => (typeof config === 'function' ? config() : config);
|
|
133
|
+
return {
|
|
134
|
+
async authConfig() {
|
|
135
|
+
return (0, exports.normaliseAuthConfig)(read());
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
exports.createAuthConfigService = createAuthConfigService;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ADMIN_CORPUS = exports.CORPUS_DIAGNOSTICS = exports.CORPUS_LOG_TAIL = exports.CORPUS_LOG = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The host reports the corpus answers with.
|
|
6
|
+
*
|
|
7
|
+
* One log file, a diagnostics body with every block the document states, and a
|
|
8
|
+
* tail for that one file. Deterministic, so a case can pin an exact body; a real
|
|
9
|
+
* host's numbers differ, which is why the server's own suite runs the same
|
|
10
|
+
* cases against its API rather than this fixture.
|
|
11
|
+
*/
|
|
12
|
+
exports.CORPUS_LOG = {
|
|
13
|
+
name: '20260101000000.log',
|
|
14
|
+
sizeBytes: 118,
|
|
15
|
+
modified: '2026-01-01T00:00:00.000Z'
|
|
16
|
+
};
|
|
17
|
+
exports.CORPUS_LOG_TAIL = {
|
|
18
|
+
fileName: exports.CORPUS_LOG.name,
|
|
19
|
+
lines: 1,
|
|
20
|
+
bytesRead: 118,
|
|
21
|
+
truncated: false,
|
|
22
|
+
content: 'GET /SASjsApi/info HTTP/1.1 200 118'
|
|
23
|
+
};
|
|
24
|
+
exports.CORPUS_DIAGNOSTICS = {
|
|
25
|
+
build: { version: 'v4.16.2', gitHash: 'cda6114', buildDate: null },
|
|
26
|
+
server: {
|
|
27
|
+
mode: 'desktop',
|
|
28
|
+
uptimeSeconds: 3600,
|
|
29
|
+
startedAt: '2026-01-01T00:00:00.000Z',
|
|
30
|
+
pid: 4242,
|
|
31
|
+
nodeVersion: 'v22.11.0',
|
|
32
|
+
platform: 'linux 5.14.0',
|
|
33
|
+
arch: 'x64',
|
|
34
|
+
cpuCount: 8,
|
|
35
|
+
cpuModel: 'Intel(R) Xeon(R) CPU',
|
|
36
|
+
loadAverage: [0.08, 0.11, 0.15],
|
|
37
|
+
runTimes: ['js'],
|
|
38
|
+
sasjsRoot: '/sasjs_root'
|
|
39
|
+
},
|
|
40
|
+
memory: {
|
|
41
|
+
rssBytes: 1,
|
|
42
|
+
heapTotalBytes: 2,
|
|
43
|
+
heapUsedBytes: 3,
|
|
44
|
+
externalBytes: 4,
|
|
45
|
+
systemTotalBytes: 5,
|
|
46
|
+
systemFreeBytes: 6
|
|
47
|
+
},
|
|
48
|
+
filesystem: null,
|
|
49
|
+
folders: [],
|
|
50
|
+
logs: {
|
|
51
|
+
folder: '/sasjs_root/logs',
|
|
52
|
+
fileCount: 1,
|
|
53
|
+
totalBytes: 118,
|
|
54
|
+
newestFile: exports.CORPUS_LOG.name,
|
|
55
|
+
newestModified: exports.CORPUS_LOG.modified
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* The admin corpus: one case per documented status of each route.
|
|
60
|
+
*
|
|
61
|
+
* `401` and `500` are host-only (the administrator middleware and the host's own
|
|
62
|
+
* failures), so they are not cases; what is pinned is the body, the traversal
|
|
63
|
+
* refusal the package owns, and the `404` for a name the folder does not hold.
|
|
64
|
+
*/
|
|
65
|
+
exports.ADMIN_CORPUS = [
|
|
66
|
+
{
|
|
67
|
+
id: 'admin-diagnostics-answers-the-report',
|
|
68
|
+
route: 'GET /SASjsApi/admin/diagnostics',
|
|
69
|
+
description: 'answers the host diagnostics report field for field',
|
|
70
|
+
request: {},
|
|
71
|
+
expect: { status: 200, body: exports.CORPUS_DIAGNOSTICS }
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: 'admin-logs-lists-the-files',
|
|
75
|
+
route: 'GET /SASjsApi/admin/logs',
|
|
76
|
+
description: 'answers the log files the host holds, newest first',
|
|
77
|
+
request: {},
|
|
78
|
+
expect: { status: 200, body: { files: [exports.CORPUS_LOG] } }
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: 'admin-log-tail-answers-the-tail',
|
|
82
|
+
route: 'GET /SASjsApi/admin/logs/{fileName}',
|
|
83
|
+
description: 'answers the tail of a log the folder holds',
|
|
84
|
+
request: { params: { fileName: exports.CORPUS_LOG.name } },
|
|
85
|
+
expect: { status: 200, body: exports.CORPUS_LOG_TAIL }
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: 'admin-log-tail-refuses-a-traversal',
|
|
89
|
+
route: 'GET /SASjsApi/admin/logs/{fileName}',
|
|
90
|
+
description: 'refuses a name that could resolve outside the log folder, before the host is asked',
|
|
91
|
+
request: { params: { fileName: '../20260101000000.log' } },
|
|
92
|
+
expect: { status: 400, error: 'Invalid log file name.' }
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: 'admin-log-tail-answers-404',
|
|
96
|
+
route: 'GET /SASjsApi/admin/logs/{fileName}',
|
|
97
|
+
description: 'answers 404 for a name the folder does not hold',
|
|
98
|
+
request: { params: { fileName: '20250101000000.log' } },
|
|
99
|
+
expect: { status: 404, error: 'Log file not found.' }
|
|
100
|
+
}
|
|
101
|
+
];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AUTH_CONFIG_CORPUS = exports.CORPUS_AUTH_CONFIG_BODY = exports.CORPUS_AUTH_CONFIG = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The provider configuration the corpus host states.
|
|
6
|
+
*
|
|
7
|
+
* A fixture rather than a value read from anywhere: the case asserts that the
|
|
8
|
+
* route answers what the host holds, with the secrets reported as the two `*Set`
|
|
9
|
+
* booleans and never as values.
|
|
10
|
+
*/
|
|
11
|
+
exports.CORPUS_AUTH_CONFIG = {
|
|
12
|
+
ldap: {
|
|
13
|
+
url: 'ldaps://directory.example:636',
|
|
14
|
+
bindDn: 'cn=admin,dc=example',
|
|
15
|
+
usersBaseDn: 'ou=users,dc=example',
|
|
16
|
+
groupsBaseDn: 'ou=groups,dc=example',
|
|
17
|
+
bindPasswordSet: true
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/** The body that fixture must answer with, environment key names and all. */
|
|
21
|
+
exports.CORPUS_AUTH_CONFIG_BODY = {
|
|
22
|
+
ldap: {
|
|
23
|
+
LDAP_URL: 'ldaps://directory.example:636',
|
|
24
|
+
LDAP_BIND_DN: 'cn=admin,dc=example',
|
|
25
|
+
LDAP_USERS_BASE_DN: 'ou=users,dc=example',
|
|
26
|
+
LDAP_GROUPS_BASE_DN: 'ou=groups,dc=example',
|
|
27
|
+
LDAP_BIND_PASSWORD_SET: true
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The auth-config corpus.
|
|
32
|
+
*
|
|
33
|
+
* The document states one status for this route - `200` - because the
|
|
34
|
+
* administrator check is the host's mount point, and the overlay marks the `401`
|
|
35
|
+
* and `500` it answers as host-only. What is pinned here is the body: the
|
|
36
|
+
* environment's key names, the secret as a boolean, and no provider the host
|
|
37
|
+
* did not enable.
|
|
38
|
+
*/
|
|
39
|
+
exports.AUTH_CONFIG_CORPUS = [
|
|
40
|
+
{
|
|
41
|
+
id: 'authconfig-answers-the-enabled-provider',
|
|
42
|
+
route: 'GET /SASjsApi/authConfig',
|
|
43
|
+
description: 'answers the enabled provider with the secret reported as a boolean, never as a value',
|
|
44
|
+
request: {},
|
|
45
|
+
expect: { status: 200, body: exports.CORPUS_AUTH_CONFIG_BODY }
|
|
46
|
+
}
|
|
47
|
+
];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DIRECTORY_CORPUS = exports.CORPUS_DIRECTORY = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The directory the corpus host answers with.
|
|
6
|
+
*
|
|
7
|
+
* One user and one group that the default identity fixture does not already
|
|
8
|
+
* hold (`admin`/`user2` and `Admins`/`DCGroup` are in it), so the case pins the
|
|
9
|
+
* counts of what an import creates rather than what it found.
|
|
10
|
+
*/
|
|
11
|
+
exports.CORPUS_DIRECTORY = {
|
|
12
|
+
users: async () => [{ username: 'alice', displayName: 'Alice' }],
|
|
13
|
+
groups: async () => [{ name: 'analysts' }]
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The directory corpus.
|
|
17
|
+
*
|
|
18
|
+
* `401` and `500` are host-only - the administrator middleware and the
|
|
19
|
+
* directory's own failures - so the one documented status this package answers
|
|
20
|
+
* is `200`, carrying what it created. The import's own rules (existing accounts
|
|
21
|
+
* untouched, membership, refusals) are pinned in `spec/directory.spec`.
|
|
22
|
+
*/
|
|
23
|
+
exports.DIRECTORY_CORPUS = [
|
|
24
|
+
{
|
|
25
|
+
id: 'directory-imports-the-missing-accounts',
|
|
26
|
+
route: 'POST /SASjsApi/authConfig/synchroniseWithLDAP',
|
|
27
|
+
description: 'imports the users and groups the store does not hold, and counts them',
|
|
28
|
+
request: {},
|
|
29
|
+
expect: { status: 200, body: { userCount: 1, groupCount: 1 } }
|
|
30
|
+
}
|
|
31
|
+
];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HOME_CORPUS = exports.CORPUS_WEB_BODY = exports.CORPUS_WEB_PAGE = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The shell the corpus host serves.
|
|
6
|
+
*
|
|
7
|
+
* A bundle reference the stamping rule must rewrite, a second reference that
|
|
8
|
+
* already carries a query string (left alone, which is what makes the transform
|
|
9
|
+
* idempotent), and the bundle's name in prose (left as prose). The page a real
|
|
10
|
+
* host reads looks like this; the values are a fixture so a case can pin the
|
|
11
|
+
* exact bytes.
|
|
12
|
+
*/
|
|
13
|
+
exports.CORPUS_WEB_PAGE = {
|
|
14
|
+
version: '4a26a3d1b2c3',
|
|
15
|
+
html: [
|
|
16
|
+
'<!doctype html>',
|
|
17
|
+
'<html>',
|
|
18
|
+
'<head>',
|
|
19
|
+
' <script src="./index.bundle.js"></script>',
|
|
20
|
+
' <script src="./vendor.js?v=keepme"></script>',
|
|
21
|
+
' <link rel="stylesheet" href="./index.bundle.css" />',
|
|
22
|
+
'</head>',
|
|
23
|
+
'<body>',
|
|
24
|
+
' <p>The page loads index.bundle.js from the folder beside it.</p>',
|
|
25
|
+
' <div id="root"></div>',
|
|
26
|
+
'</body>',
|
|
27
|
+
'</html>'
|
|
28
|
+
].join('\n')
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* The body that page must answer with: the bundle reference stamped, the
|
|
32
|
+
* already-versioned one and the prose untouched.
|
|
33
|
+
*/
|
|
34
|
+
exports.CORPUS_WEB_BODY = exports.CORPUS_WEB_PAGE.html.replace('./index.bundle.js"', `./index.bundle.js?v=${exports.CORPUS_WEB_PAGE.version}"`);
|
|
35
|
+
/**
|
|
36
|
+
* The home corpus.
|
|
37
|
+
*
|
|
38
|
+
* The document states one status, `200` as `text/html`; what a client cannot see
|
|
39
|
+
* is that the page's bundle reference carries the build's token. That is what the
|
|
40
|
+
* case pins, because a browser holding the previous build is the failure this
|
|
41
|
+
* route exists to prevent.
|
|
42
|
+
*/
|
|
43
|
+
exports.HOME_CORPUS = [
|
|
44
|
+
{
|
|
45
|
+
id: 'home-answers-the-stamped-shell',
|
|
46
|
+
route: 'GET /',
|
|
47
|
+
description: 'answers the shell with its bundle reference stamped, leaving prose and an already-versioned reference alone',
|
|
48
|
+
request: {},
|
|
49
|
+
expect: { status: 200, contents: exports.CORPUS_WEB_BODY }
|
|
50
|
+
}
|
|
51
|
+
];
|
|
@@ -11,6 +11,14 @@ const service_js_3 = require("../session/service.js");
|
|
|
11
11
|
const service_js_4 = require("../runtime/service.js");
|
|
12
12
|
const memory_runner_js_1 = require("../runtime/memory-runner.js");
|
|
13
13
|
const service_js_5 = require("../info/service.js");
|
|
14
|
+
const service_js_6 = require("../authconfig/service.js");
|
|
15
|
+
const service_js_7 = require("../admin/service.js");
|
|
16
|
+
const service_js_8 = require("../directory/service.js");
|
|
17
|
+
const authconfig_js_1 = require("./authconfig.js");
|
|
18
|
+
const admin_js_1 = require("./admin.js");
|
|
19
|
+
const directory_js_1 = require("./directory.js");
|
|
20
|
+
const service_js_9 = require("../home/service.js");
|
|
21
|
+
const home_js_1 = require("./home.js");
|
|
14
22
|
const memory_store_js_2 = require("../identity/memory-store.js");
|
|
15
23
|
const fixture_js_1 = require("../identity/fixture.js");
|
|
16
24
|
const types_js_1 = require("../types.js");
|
|
@@ -39,6 +47,14 @@ const servicesFor = (testCase) => {
|
|
|
39
47
|
? new RefusingDriveStore(testCase.seed || {})
|
|
40
48
|
: new memory_store_js_1.MemoryDriveStore(testCase.seed || {})),
|
|
41
49
|
info: (0, service_js_5.createInfoService)(service_js_5.BROWSER_INFO),
|
|
50
|
+
home: (0, service_js_9.createHomeService)(async () => home_js_1.CORPUS_WEB_PAGE),
|
|
51
|
+
authConfig: (0, service_js_6.createAuthConfigService)(authconfig_js_1.CORPUS_AUTH_CONFIG),
|
|
52
|
+
admin: (0, service_js_7.createAdminService)({
|
|
53
|
+
diagnostics: async () => admin_js_1.CORPUS_DIAGNOSTICS,
|
|
54
|
+
logs: async () => [admin_js_1.CORPUS_LOG],
|
|
55
|
+
logTail: async (fileName) => fileName === admin_js_1.CORPUS_LOG.name ? admin_js_1.CORPUS_LOG_TAIL : undefined
|
|
56
|
+
}),
|
|
57
|
+
directory: (0, service_js_8.createDirectoryService)(identity, directory_js_1.CORPUS_DIRECTORY),
|
|
42
58
|
identity: (0, service_js_2.createIdentityService)(identity),
|
|
43
59
|
records: (0, records_js_1.createRecordService)(identity),
|
|
44
60
|
registry: new registry_js_1.MemoryAppStreamRegistry(),
|