@sasjs/api 0.40.2 → 0.42.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 +1207 -996
- package/build/cjs/corpus/admin.js +40 -8
- package/build/cjs/corpus/drive.js +29 -0
- package/build/cjs/corpus/runner.js +9 -3
- package/build/cjs/corpus/runtime.js +24 -0
- package/build/cjs/drive/deploymentFile.js +110 -0
- package/build/cjs/host/dispatch.js +99 -15
- package/build/cjs/identity/records.js +70 -29
- package/build/cjs/index.js +8 -3
- package/build/cjs/routes/generated.js +12 -2
- package/build/cjs/routes/overlay.js +15 -7
- package/build/esm/corpus/admin.d.ts +4 -3
- package/build/esm/corpus/admin.d.ts.map +1 -1
- package/build/esm/corpus/admin.js +40 -8
- package/build/esm/corpus/drive.d.ts.map +1 -1
- package/build/esm/corpus/drive.js +29 -0
- package/build/esm/corpus/runner.d.ts.map +1 -1
- package/build/esm/corpus/runner.js +9 -3
- package/build/esm/corpus/runtime.d.ts.map +1 -1
- package/build/esm/corpus/runtime.js +24 -0
- package/build/esm/drive/deploymentFile.d.ts +43 -0
- package/build/esm/drive/deploymentFile.d.ts.map +1 -0
- package/build/esm/drive/deploymentFile.js +105 -0
- package/build/esm/host/dispatch.d.ts +16 -1
- package/build/esm/host/dispatch.d.ts.map +1 -1
- package/build/esm/host/dispatch.js +99 -15
- package/build/esm/identity/records.d.ts +35 -0
- package/build/esm/identity/records.d.ts.map +1 -1
- package/build/esm/identity/records.js +70 -29
- package/build/esm/index.d.ts +2 -0
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js +1 -0
- package/build/esm/routes/generated.d.ts.map +1 -1
- package/build/esm/routes/generated.js +12 -2
- package/build/esm/routes/overlay.d.ts.map +1 -1
- package/build/esm/routes/overlay.js +15 -7
- package/build/esm/types.d.ts +1 -1
- package/build/esm/types.d.ts.map +1 -1
- package/package.json +3 -2
|
@@ -55,47 +55,79 @@ exports.CORPUS_DIAGNOSTICS = {
|
|
|
55
55
|
newestModified: exports.CORPUS_LOG.modified
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
|
+
/** The fixture's administrator, and the account the rules do not admit. */
|
|
59
|
+
const ADMIN = { userId: 'user-admin', clientId: 'web_app' };
|
|
60
|
+
const RESTRICTED = { userId: 'user-restricted', clientId: 'web_app' };
|
|
58
61
|
/**
|
|
59
62
|
* The admin corpus: one case per documented status of each route.
|
|
60
63
|
*
|
|
61
|
-
* `401`
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
+
* The `401` is the package's now - the same `mayAdminister` the record routes
|
|
65
|
+
* refuse with - so both halves are cases here, with the administrator's `200`
|
|
66
|
+
* between them. The host's own `500` stays out, as it cannot be produced from a
|
|
67
|
+
* fixture.
|
|
64
68
|
*/
|
|
65
69
|
exports.ADMIN_CORPUS = [
|
|
66
70
|
{
|
|
67
71
|
id: 'admin-diagnostics-answers-the-report',
|
|
68
72
|
route: 'GET /SASjsApi/admin/diagnostics',
|
|
69
73
|
description: 'answers the host diagnostics report field for field',
|
|
70
|
-
request: {},
|
|
74
|
+
request: { subject: ADMIN },
|
|
71
75
|
expect: { status: 200, body: exports.CORPUS_DIAGNOSTICS }
|
|
72
76
|
},
|
|
73
77
|
{
|
|
74
78
|
id: 'admin-logs-lists-the-files',
|
|
75
79
|
route: 'GET /SASjsApi/admin/logs',
|
|
76
80
|
description: 'answers the log files the host holds, newest first',
|
|
77
|
-
request: {},
|
|
81
|
+
request: { subject: ADMIN },
|
|
78
82
|
expect: { status: 200, body: { files: [exports.CORPUS_LOG] } }
|
|
79
83
|
},
|
|
80
84
|
{
|
|
81
85
|
id: 'admin-log-tail-answers-the-tail',
|
|
82
86
|
route: 'GET /SASjsApi/admin/logs/{fileName}',
|
|
83
87
|
description: 'answers the tail of a log the folder holds',
|
|
84
|
-
request: { params: { fileName: exports.CORPUS_LOG.name } },
|
|
88
|
+
request: { subject: ADMIN, params: { fileName: exports.CORPUS_LOG.name } },
|
|
85
89
|
expect: { status: 200, body: exports.CORPUS_LOG_TAIL }
|
|
86
90
|
},
|
|
87
91
|
{
|
|
88
92
|
id: 'admin-log-tail-refuses-a-traversal',
|
|
89
93
|
route: 'GET /SASjsApi/admin/logs/{fileName}',
|
|
90
94
|
description: 'refuses a name that could resolve outside the log folder, before the host is asked',
|
|
91
|
-
request: { params: { fileName: '../20260101000000.log' } },
|
|
95
|
+
request: { subject: ADMIN, params: { fileName: '../20260101000000.log' } },
|
|
92
96
|
expect: { status: 400, error: 'Invalid log file name.' }
|
|
93
97
|
},
|
|
94
98
|
{
|
|
95
99
|
id: 'admin-log-tail-answers-404',
|
|
96
100
|
route: 'GET /SASjsApi/admin/logs/{fileName}',
|
|
97
101
|
description: 'answers 404 for a name the folder does not hold',
|
|
98
|
-
request: { params: { fileName: '20250101000000.log' } },
|
|
102
|
+
request: { subject: ADMIN, params: { fileName: '20250101000000.log' } },
|
|
99
103
|
expect: { status: 404, error: 'Log file not found.' }
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: 'admin-diagnostics-refused-to-a-restricted-account',
|
|
107
|
+
route: 'GET /SASjsApi/admin/diagnostics',
|
|
108
|
+
description: 'refuses a signed-in account that is not an administrator, in the wording verifyAdmin uses',
|
|
109
|
+
request: { subject: RESTRICTED },
|
|
110
|
+
expect: { status: 401, error: 'Admin account required' }
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
id: 'admin-logs-refused-to-a-restricted-account',
|
|
114
|
+
route: 'GET /SASjsApi/admin/logs',
|
|
115
|
+
description: 'refuses the log inventory to a restricted account',
|
|
116
|
+
request: { subject: RESTRICTED },
|
|
117
|
+
expect: { status: 401, error: 'Admin account required' }
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: 'admin-log-tail-refused-to-a-restricted-account',
|
|
121
|
+
route: 'GET /SASjsApi/admin/logs/{fileName}',
|
|
122
|
+
description: 'refuses a log tail to a restricted account',
|
|
123
|
+
request: { subject: RESTRICTED, params: { fileName: exports.CORPUS_LOG.name } },
|
|
124
|
+
expect: { status: 401, error: 'Admin account required' }
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: 'admin-logs-refused-with-no-caller',
|
|
128
|
+
route: 'GET /SASjsApi/admin/logs',
|
|
129
|
+
description: 'refuses a request that carries no caller at all',
|
|
130
|
+
request: {},
|
|
131
|
+
expect: { status: 401, error: 'Unauthorized' }
|
|
100
132
|
}
|
|
101
133
|
];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DRIVE_CORPUS = void 0;
|
|
4
|
+
const deploymentFile_js_1 = require("../drive/deploymentFile.js");
|
|
4
5
|
const success = { status: 'success' };
|
|
5
6
|
/**
|
|
6
7
|
* Bytes without an encoding API: the package builds with `lib: ES2020` and no
|
|
@@ -133,6 +134,34 @@ exports.DRIVE_CORPUS = [
|
|
|
133
134
|
request: { query: { _filePath: '/../escape.csv' } },
|
|
134
135
|
expect: { status: 400, error: "Can't get file outside drive." }
|
|
135
136
|
},
|
|
137
|
+
{
|
|
138
|
+
id: 'read-file-names-both',
|
|
139
|
+
route: 'GET /SASjsApi/drive/file',
|
|
140
|
+
description: 'refuses a request that names the file twice, in two readings',
|
|
141
|
+
seed: { '/data/keep.csv': 'a' },
|
|
142
|
+
request: {
|
|
143
|
+
query: { _filePath: '/data/keep.csv', _FILE: '/data/keep.csv' }
|
|
144
|
+
},
|
|
145
|
+
expect: {
|
|
146
|
+
status: 400,
|
|
147
|
+
error: 'Exactly one of "_filePath" and "_FILE" may be given.'
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
id: 'read-streamed-file',
|
|
152
|
+
route: 'GET /SASjsApi/drive/file',
|
|
153
|
+
description: 'reads a deployment file by the name a streamed page links to',
|
|
154
|
+
seed: { '/Public/app/services/web/main.js': 'console.log(1)' },
|
|
155
|
+
request: { query: { _FILE: '/Public/app/services/web/main.js' } },
|
|
156
|
+
expect: { status: 200, contents: 'console.log(1)' }
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
id: 'read-streamed-file-missing',
|
|
160
|
+
route: 'GET /SASjsApi/drive/file',
|
|
161
|
+
description: 'answers a missing deployment file the way the estate does, not as a 404',
|
|
162
|
+
request: { query: { _FILE: '/Public/app/services/web/gone.js' } },
|
|
163
|
+
expect: { status: 202, contents: deploymentFile_js_1.DEPLOYMENT_FILE_ERROR }
|
|
164
|
+
},
|
|
136
165
|
{
|
|
137
166
|
id: 'delete-file',
|
|
138
167
|
route: 'DELETE /SASjsApi/drive/file',
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.runCase = exports.servicesFor = exports.CORPUS_APP = void 0;
|
|
4
4
|
const dispatch_js_1 = require("../host/dispatch.js");
|
|
5
5
|
const service_js_1 = require("../drive/service.js");
|
|
6
|
+
const deploymentFile_js_1 = require("../drive/deploymentFile.js");
|
|
6
7
|
const memory_store_js_1 = require("../drive/memory-store.js");
|
|
7
8
|
const service_js_2 = require("../appstream/service.js");
|
|
8
9
|
const service_js_3 = require("../identity/service.js");
|
|
@@ -55,10 +56,15 @@ const servicesFor = (testCase) => {
|
|
|
55
56
|
? { [programOf(testCase)]: testCase.runOutput }
|
|
56
57
|
: undefined
|
|
57
58
|
});
|
|
59
|
+
// one store, shared by the drive and the streamed-file read: a file the drive
|
|
60
|
+
// writes has to be the file a streamed page can fetch, or the corpus would be
|
|
61
|
+
// asserting two different drives
|
|
62
|
+
const driveStore = testCase.unwritable
|
|
63
|
+
? new RefusingDriveStore(testCase.seed || {})
|
|
64
|
+
: new memory_store_js_1.MemoryDriveStore(testCase.seed || {});
|
|
58
65
|
return {
|
|
59
|
-
drive: (0, service_js_1.createDriveService)(
|
|
60
|
-
|
|
61
|
-
: new memory_store_js_1.MemoryDriveStore(testCase.seed || {})),
|
|
66
|
+
drive: (0, service_js_1.createDriveService)(driveStore),
|
|
67
|
+
deploymentFile: (0, deploymentFile_js_1.createDeploymentFileService)(driveStore),
|
|
62
68
|
info: (0, service_js_6.createInfoService)(service_js_6.BROWSER_INFO),
|
|
63
69
|
home: (0, service_js_10.createHomeService)(async () => home_js_1.CORPUS_WEB_PAGE),
|
|
64
70
|
authConfig: (0, service_js_7.createAuthConfigService)(authconfig_js_1.CORPUS_AUTH_CONFIG),
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RUNTIME_CORPUS = void 0;
|
|
4
4
|
const ADMIN = { userId: 'user-admin', clientId: 'web_app' };
|
|
5
|
+
/** The fixture's restricted account: granted `stp/execute`, denied `code/execute`. */
|
|
6
|
+
const RESTRICTED = { userId: 'user-restricted', clientId: 'web_app' };
|
|
5
7
|
const PROGRAM = '/Public/apps/demo/run.sas';
|
|
6
8
|
const CODE = 'data _null_;\n put "hello";\nrun;';
|
|
7
9
|
const UNAUTHORIZED = 'Unauthorized';
|
|
@@ -195,6 +197,28 @@ exports.RUNTIME_CORPUS = [
|
|
|
195
197
|
request: { body: {} },
|
|
196
198
|
expect: { status: 401, error: UNAUTHORIZED }
|
|
197
199
|
},
|
|
200
|
+
{
|
|
201
|
+
// The fixture denies this account `/SASjsApi/code/execute` with a user rule,
|
|
202
|
+
// and a denied rule refuses the call rather than only the menu entry beside
|
|
203
|
+
// it. On a server that is `authorize`; here it is the decision
|
|
204
|
+
// `myAuthorizedRoutes` reports from, asked of the same store.
|
|
205
|
+
id: 'code-execute-denied-by-a-rule',
|
|
206
|
+
route: 'POST /SASjsApi/code/execute',
|
|
207
|
+
description: 'refuses a caller the rules do not grant, with the 401 a missing token earns',
|
|
208
|
+
request: { subject: RESTRICTED, body: { code: CODE, runTime: 'sas' } },
|
|
209
|
+
expect: { status: 401, error: UNAUTHORIZED }
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
// The positive control for the case above: the same account is granted
|
|
213
|
+
// `stp/execute` by a group rule, so the refusal there is the rule and not a
|
|
214
|
+
// blanket refusal of everything a restricted account asks for.
|
|
215
|
+
id: 'stp-execute-granted-by-a-group-rule',
|
|
216
|
+
route: 'POST /SASjsApi/stp/execute',
|
|
217
|
+
description: 'admits a restricted account the rules grant',
|
|
218
|
+
request: { subject: RESTRICTED, body: { _program: PROGRAM } },
|
|
219
|
+
runOutput: { contents: 'granted run' },
|
|
220
|
+
expect: { status: 200, contents: 'granted run' }
|
|
221
|
+
},
|
|
198
222
|
// ----------------------------------------------- POST /code/trigger
|
|
199
223
|
{
|
|
200
224
|
id: 'code-trigger-answers-session',
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDeploymentFileService = exports.assertOneFileName = exports.ONE_NAME_ONLY = exports.DEPLOYMENT_FILE_ERROR = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The read a streamed deployment links to: one file out of the drive, by path.
|
|
6
|
+
*
|
|
7
|
+
* A build made with `streamWeb` rewrites every asset link in the entry page to
|
|
8
|
+
* name the file it fetches - `?path=/Public/app/services/web/main.4f3a9c1d.js`,
|
|
9
|
+
* the `_FILE=` spelling the estate answers - so the host has to read one file
|
|
10
|
+
* back and hand it to a browser as itself. Serve it as bytes and the page
|
|
11
|
+
* renders nothing: the difference between a working app and a blank one is the
|
|
12
|
+
* Content-Type.
|
|
13
|
+
*
|
|
14
|
+
* So the typing, the caching and the refusal live here rather than in each
|
|
15
|
+
* host, the same way the drive's own rules do. Every platform has one web tier
|
|
16
|
+
* a browser fetches a program or a file from - `/SASStoredProcess` on SAS 9,
|
|
17
|
+
* `/SASJobExecution` on Viya, `/StoredProgram` on SASjs server - and each of
|
|
18
|
+
* those spellings is meant to resolve to this read.
|
|
19
|
+
*
|
|
20
|
+
* Conditional, because the hosts are what adopt it: the browser build already
|
|
21
|
+
* answers two of them (a mock site holds the drive), while sasjs/server answers
|
|
22
|
+
* `/StoredProgram` and `/SASJobExecution` by handing the request to `GET
|
|
23
|
+
* /SASjsApi/drive/file?_FILE=` only once sasjs/server#736 merges. Until then a
|
|
24
|
+
* consumer's own default branch has no such route, and a sentence here that
|
|
25
|
+
* forgot it would send a reader looking for one.
|
|
26
|
+
*
|
|
27
|
+
* A file that is not there answers the way the estate answers - `202` with a
|
|
28
|
+
* two-line message, not a `404`. A streamed app whose asset is missing has to
|
|
29
|
+
* fail the same way in both places, or a fault reproduced locally is a
|
|
30
|
+
* different fault from the one being chased.
|
|
31
|
+
*/
|
|
32
|
+
const types_js_1 = require("../types.js");
|
|
33
|
+
const web_js_1 = require("../appstream/web.js");
|
|
34
|
+
const paths_js_1 = require("./paths.js");
|
|
35
|
+
/** What SAS Viya's job execution route answers for a file it cannot read. */
|
|
36
|
+
exports.DEPLOYMENT_FILE_ERROR = 'Parameter Error\nFile error';
|
|
37
|
+
/** The words a request that names the file twice earns. */
|
|
38
|
+
exports.ONE_NAME_ONLY = 'Exactly one of "_filePath" and "_FILE" may be given.';
|
|
39
|
+
/**
|
|
40
|
+
* Refuses a request that names one file two ways.
|
|
41
|
+
*
|
|
42
|
+
* Both names exist because they answer differently - `_FILE=` is typed and
|
|
43
|
+
* answers a missing file the way the estate does, `_filePath=` is bytes - so a
|
|
44
|
+
* request carrying both is a caller disagreeing with itself. Resolving it would
|
|
45
|
+
* mean picking an answer nobody asked for, and picking the same way in every
|
|
46
|
+
* host. The rule lives here, with the message, so a host that answers the read
|
|
47
|
+
* through its own route (sasjs/server does) refuses it identically instead of
|
|
48
|
+
* re-deciding.
|
|
49
|
+
*/
|
|
50
|
+
const assertOneFileName = (query) => {
|
|
51
|
+
if (query._filePath !== undefined && query._FILE !== undefined)
|
|
52
|
+
throw new types_js_1.ApiError(400, exports.ONE_NAME_ONLY);
|
|
53
|
+
};
|
|
54
|
+
exports.assertOneFileName = assertOneFileName;
|
|
55
|
+
/**
|
|
56
|
+
* Whether a store refused because there is nothing at the path.
|
|
57
|
+
*
|
|
58
|
+
* Two spellings reach this code and both mean the same thing: the package's
|
|
59
|
+
* stores throw `ApiError(404, "File doesn't exist.")`, and a host's store over a
|
|
60
|
+
* filesystem (sasjs/server's) lets `fs` throw `ENOENT`. Anything else - a
|
|
61
|
+
* permission failure, a broken link - is a real error and travels on.
|
|
62
|
+
*/
|
|
63
|
+
const notFound = (error) => ((0, types_js_1.isApiError)(error) && error.status === 404) ||
|
|
64
|
+
// a structural read, not `NodeJS.ErrnoException`: this module is in the
|
|
65
|
+
// browser build, which has no node types at all
|
|
66
|
+
error?.code === 'ENOENT';
|
|
67
|
+
/** The answer for a file that is not there, in the estate's words. */
|
|
68
|
+
const notThere = () => ({
|
|
69
|
+
status: 202,
|
|
70
|
+
contentType: 'text/plain; charset=utf-8',
|
|
71
|
+
body: exports.DEPLOYMENT_FILE_ERROR
|
|
72
|
+
});
|
|
73
|
+
const createDeploymentFileService = (store) => ({
|
|
74
|
+
async read(input) {
|
|
75
|
+
// the drive's containment and extension rules decide first: a streamed page
|
|
76
|
+
// is caller-supplied content, and this read must not be a way round them
|
|
77
|
+
const checked = (0, paths_js_1.checkFilePath)(input);
|
|
78
|
+
if ('reason' in checked)
|
|
79
|
+
throw checked.reason === 'extension'
|
|
80
|
+
? new types_js_1.ApiError(400, 'Invalid file extension')
|
|
81
|
+
: new types_js_1.ApiError(400, `Can't get file outside drive.`);
|
|
82
|
+
if ((0, paths_js_1.isRoot)(checked.path))
|
|
83
|
+
throw new types_js_1.ApiError(400, `Can't get file outside drive.`);
|
|
84
|
+
const path = checked.path;
|
|
85
|
+
// The stat and the read are one attempt, not a check followed by an action:
|
|
86
|
+
// a file can be removed or replaced between them, and the fault this route
|
|
87
|
+
// exists to reproduce is a missing asset - which has to answer `202` in the
|
|
88
|
+
// estate's words, not whatever the store threw at that instant. A folder is
|
|
89
|
+
// refused the same way: there is no file to send.
|
|
90
|
+
try {
|
|
91
|
+
if ((await store.stat(path)).directory)
|
|
92
|
+
return notThere();
|
|
93
|
+
return {
|
|
94
|
+
status: 200,
|
|
95
|
+
contentType: (0, web_js_1.contentTypeFor)(path),
|
|
96
|
+
// lower case, matching the app stream's own answer (src/appstream/web.ts):
|
|
97
|
+
// the names are case-insensitive in HTTP but not in a plain object, and a
|
|
98
|
+
// host copying one into the other would lose a policy that mattered
|
|
99
|
+
headers: { 'cache-control': (0, web_js_1.cacheControlFor)(path) },
|
|
100
|
+
body: await store.read(path)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (notFound(error))
|
|
105
|
+
return notThere();
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
exports.createDeploymentFileService = createDeploymentFileService;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HANDLED_ROUTES = exports.noHandler = exports.dispatch = void 0;
|
|
4
4
|
const index_js_1 = require("../routes/index.js");
|
|
5
|
+
const deploymentFile_js_1 = require("../drive/deploymentFile.js");
|
|
5
6
|
const service_js_1 = require("../appstream/service.js");
|
|
6
7
|
const web_js_1 = require("../appstream/web.js");
|
|
7
8
|
const bundle_js_1 = require("../appstream/bundle.js");
|
|
@@ -25,6 +26,29 @@ const RUN_ROUTES = [
|
|
|
25
26
|
'POST /SASjsApi/code/execute',
|
|
26
27
|
'POST /SASjsApi/code/trigger'
|
|
27
28
|
];
|
|
29
|
+
/**
|
|
30
|
+
* The run routes a permission rule addresses.
|
|
31
|
+
*
|
|
32
|
+
* The triggers are not in the inventory - the server's rules do not reach them -
|
|
33
|
+
* so they are gated on the caller alone, exactly as they are there.
|
|
34
|
+
*/
|
|
35
|
+
const GRANTED_RUN_ROUTES = [
|
|
36
|
+
'GET /SASjsApi/stp/execute',
|
|
37
|
+
'POST /SASjsApi/stp/execute',
|
|
38
|
+
'POST /SASjsApi/code/execute'
|
|
39
|
+
];
|
|
40
|
+
/**
|
|
41
|
+
* The host's own reports, which the server mounts `verifyAdmin` in front of.
|
|
42
|
+
*
|
|
43
|
+
* The check belongs to the package for the same reason the record routes' does:
|
|
44
|
+
* the mock is a host too, and a browser build that published the host log to a
|
|
45
|
+
* restricted account would be a leak with a fixture in front of it.
|
|
46
|
+
*/
|
|
47
|
+
const ADMIN_ROUTES = [
|
|
48
|
+
'GET /SASjsApi/admin/diagnostics',
|
|
49
|
+
'GET /SASjsApi/admin/logs',
|
|
50
|
+
'GET /SASjsApi/admin/logs/{fileName}'
|
|
51
|
+
];
|
|
28
52
|
/** A payload value, when the caller actually stated one. */
|
|
29
53
|
const given = (value) => typeof value === 'string' && value !== '' ? value : undefined;
|
|
30
54
|
/**
|
|
@@ -113,10 +137,42 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
113
137
|
// told which capability it is missing rather than sent round a login loop, so
|
|
114
138
|
// the gate is tested on the service that serves the route.
|
|
115
139
|
const runtimeScoped = RUN_ROUTES.includes(routeId);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
140
|
+
// The two checks the server mounts ahead of these routes: `verifyAdmin` in
|
|
141
|
+
// front of the host's own reports, and `authorize` on the run routes the
|
|
142
|
+
// permission rules address. Asked of the record service, so the answer a
|
|
143
|
+
// request meets is the one `myAuthorizedRoutes` reported for the same caller.
|
|
144
|
+
const adminScoped = ADMIN_ROUTES.includes(routeId) && Boolean(services.admin);
|
|
145
|
+
const grantScoped = Boolean(records) && GRANTED_RUN_ROUTES.includes(routeId);
|
|
146
|
+
// The administrator routes need the record service to answer the question the
|
|
147
|
+
// host's middleware answers on a server. A host that supplies the reports
|
|
148
|
+
// without one is told which capability it is missing, rather than serving its
|
|
149
|
+
// own log to every caller - which is what a gate that simply skipped them did.
|
|
150
|
+
if (adminScoped && !records)
|
|
151
|
+
throw new types_js_1.ApiError(501, `This host has no record service, so it cannot answer ${routeId}.`);
|
|
152
|
+
/**
|
|
153
|
+
* The caller, from the request's own subject or the token it carried.
|
|
154
|
+
*
|
|
155
|
+
* Resolved once per request: the token is looked up in the store, and every
|
|
156
|
+
* gate below asks the same question - re-reading it for each would be a
|
|
157
|
+
* second lookup for one answer.
|
|
158
|
+
*/
|
|
159
|
+
let subject = request.subject;
|
|
160
|
+
let subjectResolved = Boolean(request.subject);
|
|
161
|
+
const caller = async () => {
|
|
162
|
+
if (!subjectResolved) {
|
|
163
|
+
subject = identity
|
|
164
|
+
? await identity.authenticate(request.token)
|
|
165
|
+
: undefined;
|
|
166
|
+
subjectResolved = true;
|
|
167
|
+
}
|
|
168
|
+
return subject;
|
|
169
|
+
};
|
|
170
|
+
if ((identityScoped && records) ||
|
|
171
|
+
(runtimeScoped && services.runtime) ||
|
|
172
|
+
adminScoped ||
|
|
173
|
+
grantScoped) {
|
|
174
|
+
const callerSubject = await caller();
|
|
175
|
+
if (!callerSubject) {
|
|
120
176
|
// A host may serve records without a sign-in flow - it resolves the caller
|
|
121
177
|
// itself and passes `subject`. Without one it cannot authenticate at all,
|
|
122
178
|
// and a 401 would send every request round the login loop for ever, so it
|
|
@@ -125,6 +181,20 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
125
181
|
throw new types_js_1.ApiError(501, `This host has no identity service, so it cannot answer ${routeId}.`);
|
|
126
182
|
throw new types_js_1.ApiError(401, 'Unauthorized');
|
|
127
183
|
}
|
|
184
|
+
// `verifyAdmin`, in the wording a caller sees on a server - except for a
|
|
185
|
+
// caller the server refuses before that middleware runs, which meets the
|
|
186
|
+
// token refusal instead
|
|
187
|
+
if (adminScoped && !(await records.mayAdminister(callerSubject))) {
|
|
188
|
+
// a caller the server refuses before this middleware runs meets the token
|
|
189
|
+
// refusal, not the admin wording
|
|
190
|
+
if (!(await records.mayAct(callerSubject)))
|
|
191
|
+
throw new types_js_1.ApiError(401, 'Unauthorized');
|
|
192
|
+
throw new types_js_1.ApiError(401, 'Admin account required');
|
|
193
|
+
}
|
|
194
|
+
// `authorize`: the rules this host's interface reads decide the call, not
|
|
195
|
+
// only the menu entry beside it
|
|
196
|
+
if (grantScoped && !(await records.mayUseRoute(callerSubject, route.path)))
|
|
197
|
+
throw new types_js_1.ApiError(401, 'Unauthorized');
|
|
128
198
|
}
|
|
129
199
|
validate(route, request);
|
|
130
200
|
const query = request.query || {};
|
|
@@ -175,12 +245,6 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
175
245
|
throw new types_js_1.ApiError(501, `This host has no record service, so it cannot answer ${routeId}.`);
|
|
176
246
|
return records;
|
|
177
247
|
};
|
|
178
|
-
/** The caller, from the request's own subject or the token it carried. */
|
|
179
|
-
const caller = async () => {
|
|
180
|
-
if (request.subject)
|
|
181
|
-
return request.subject;
|
|
182
|
-
return identity?.authenticate(request.token);
|
|
183
|
-
};
|
|
184
248
|
if (routeId.startsWith('POST /SASjsApi/auth/') ||
|
|
185
249
|
routeId.startsWith('POST /SASLogon/') ||
|
|
186
250
|
routeId === 'GET /SASLogon/logout' ||
|
|
@@ -240,10 +304,11 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
240
304
|
}
|
|
241
305
|
// ------------------------------------------------- a host's own reports
|
|
242
306
|
//
|
|
243
|
-
// The administrator
|
|
244
|
-
//
|
|
245
|
-
//
|
|
246
|
-
//
|
|
307
|
+
// The administrator check is the package's, from the caller the transport
|
|
308
|
+
// resolved: `mayAdminister` is the decision `verifyAdmin` makes on a server,
|
|
309
|
+
// asked here so a browser host that supplies these reports cannot serve them
|
|
310
|
+
// to anyone who asks. What stays the host's is the body, and for a log tail
|
|
311
|
+
// the refusals that belong to the name rule.
|
|
247
312
|
case 'GET /SASjsApi/admin/diagnostics': {
|
|
248
313
|
if (!services.admin)
|
|
249
314
|
throw new types_js_1.ApiError(501, `This host has no admin service, so it cannot answer ${routeId}.`);
|
|
@@ -273,7 +338,26 @@ const dispatch = async (services, routeId, request = {}) => {
|
|
|
273
338
|
return { status: 200, body: await services.directory.synchronise() };
|
|
274
339
|
}
|
|
275
340
|
case 'GET /SASjsApi/drive/file': {
|
|
276
|
-
|
|
341
|
+
// two names for one read that answer differently; a request carrying both
|
|
342
|
+
// is refused by the package rather than resolved here, so a host answering
|
|
343
|
+
// through its own route refuses it with the same words
|
|
344
|
+
(0, deploymentFile_js_1.assertOneFileName)(query);
|
|
345
|
+
if (query._FILE !== undefined) {
|
|
346
|
+
if (!services.deploymentFile)
|
|
347
|
+
throw new types_js_1.ApiError(501, `This host has no deployment-file service, so it cannot answer ${routeId}.`);
|
|
348
|
+
const page = await services.deploymentFile.read(String(query._FILE));
|
|
349
|
+
return {
|
|
350
|
+
status: page.status,
|
|
351
|
+
contents: page.body,
|
|
352
|
+
contentType: page.contentType,
|
|
353
|
+
headers: page.headers
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
// one of the two names the file; the table allows either, so a request
|
|
357
|
+
// with neither is the same `400` a missing `_filePath` always was
|
|
358
|
+
if (query._filePath === undefined)
|
|
359
|
+
throw new types_js_1.ApiError(400, '"_filePath" is required');
|
|
360
|
+
const file = await drive.read(String(query._filePath));
|
|
277
361
|
return { status: 200, contents: file.contents };
|
|
278
362
|
}
|
|
279
363
|
case 'POST /SASjsApi/drive/file':
|
|
@@ -23,6 +23,20 @@ const ALL_USERS_GROUP = 'all-users';
|
|
|
23
23
|
/** The group whose membership the API refuses to change. */
|
|
24
24
|
const PUBLIC_GROUP = 'public';
|
|
25
25
|
const unauthorized = () => new types_js_1.ApiError(401, 'Unauthorized');
|
|
26
|
+
/**
|
|
27
|
+
* The account behind a caller, while it may still act, or undefined.
|
|
28
|
+
*
|
|
29
|
+
* The reads every administration route makes: the server re-reads the user on
|
|
30
|
+
* every request and refuses a deactivated account, so a token that outlived the
|
|
31
|
+
* account must not administer anything. The gate asks this rather than
|
|
32
|
+
* `requireCaller` when a refusal is the caller's answer rather than an error.
|
|
33
|
+
*/
|
|
34
|
+
const readerOf = async (store, caller) => {
|
|
35
|
+
if (!caller)
|
|
36
|
+
return undefined;
|
|
37
|
+
const user = await store.userById(caller.userId);
|
|
38
|
+
return user && user.isActive ? user : undefined;
|
|
39
|
+
};
|
|
26
40
|
/**
|
|
27
41
|
* The caller, while the account behind it may still act.
|
|
28
42
|
*
|
|
@@ -31,10 +45,8 @@ const unauthorized = () => new types_js_1.ApiError(401, 'Unauthorized');
|
|
|
31
45
|
* token or session that outlived the account must not administer anything.
|
|
32
46
|
*/
|
|
33
47
|
const requireCaller = async (store, caller) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const user = await store.userById(caller.userId);
|
|
37
|
-
if (!user || !user.isActive)
|
|
48
|
+
const user = await readerOf(store, caller);
|
|
49
|
+
if (!user)
|
|
38
50
|
throw unauthorized();
|
|
39
51
|
return user;
|
|
40
52
|
};
|
|
@@ -86,6 +98,37 @@ const asGroup = (group) => ({
|
|
|
86
98
|
});
|
|
87
99
|
const createRecordService = (store, options = {}) => {
|
|
88
100
|
const grantableRoutes = options.grantableRoutes || routeAccess_js_1.DEFAULT_GRANTABLE_ROUTES;
|
|
101
|
+
/**
|
|
102
|
+
* The routes this reader is granted. One pass over the rules per call, and no
|
|
103
|
+
* read of the groups table unless some rule names a group - the transport
|
|
104
|
+
* gate runs on every request, so the cheap path is the common one.
|
|
105
|
+
*/
|
|
106
|
+
const grantedRoutesFor = async (reader) => {
|
|
107
|
+
if (reader.isAdmin)
|
|
108
|
+
return new Set(grantableRoutes);
|
|
109
|
+
const rules = await store.permissions();
|
|
110
|
+
const mine = {
|
|
111
|
+
user: rules
|
|
112
|
+
.filter((rule) => rule.user === reader.uid)
|
|
113
|
+
.map((rule) => ({ path: rule.path, setting: rule.setting })),
|
|
114
|
+
group: rules
|
|
115
|
+
.filter((rule) => rule.group !== undefined && reader.groups.includes(rule.group))
|
|
116
|
+
.map((rule) => ({ path: rule.path, setting: rule.setting }))
|
|
117
|
+
};
|
|
118
|
+
// a grant on the reserved public group admits any caller, and it is checked
|
|
119
|
+
// before the rules so no user or group rule can take it away
|
|
120
|
+
const publicGroup = rules.some((rule) => rule.group !== undefined)
|
|
121
|
+
? (await store.groups()).find((group) => group.name === PUBLIC_GROUP)
|
|
122
|
+
: undefined;
|
|
123
|
+
const publicGrants = publicGroup
|
|
124
|
+
? rules
|
|
125
|
+
.filter((rule) => rule.group === publicGroup.uid && rule.setting === 'Grant')
|
|
126
|
+
.map((rule) => rule.path)
|
|
127
|
+
: [];
|
|
128
|
+
return new Set(grantableRoutes.filter((path) => routeAccess_js_1.ALWAYS_VISIBLE_ROUTES.includes(path) ||
|
|
129
|
+
publicGrants.includes(path) ||
|
|
130
|
+
(0, routeAccess_js_1.isRouteGranted)(mine, path, (0, routeAccess_js_1.topLevelRouteFor)(path))));
|
|
131
|
+
};
|
|
89
132
|
const groupDetails = async (group) => {
|
|
90
133
|
const members = [];
|
|
91
134
|
for (const uid of group.users) {
|
|
@@ -300,32 +343,30 @@ const createRecordService = (store, options = {}) => {
|
|
|
300
343
|
},
|
|
301
344
|
async myAuthorizedRoutes(caller) {
|
|
302
345
|
const reader = await requireCaller(store, caller);
|
|
303
|
-
|
|
304
|
-
|
|
346
|
+
const granted = await grantedRoutesFor(reader);
|
|
347
|
+
return { paths: grantableRoutes.filter((path) => granted.has(path)) };
|
|
348
|
+
},
|
|
349
|
+
async mayAdminister(caller) {
|
|
350
|
+
const reader = await readerOf(store, caller);
|
|
351
|
+
return Boolean(reader?.isAdmin);
|
|
352
|
+
},
|
|
353
|
+
async mayAct(caller) {
|
|
354
|
+
return Boolean(await readerOf(store, caller));
|
|
355
|
+
},
|
|
356
|
+
async mayUseRoute(caller, path) {
|
|
357
|
+
const reader = await readerOf(store, caller);
|
|
358
|
+
if (!reader)
|
|
359
|
+
return false;
|
|
360
|
+
// an administrator holds every route, listed or not: the question is
|
|
361
|
+
// whether the rules admit the caller, and the inventory is only what the
|
|
362
|
+
// rules can address - a host may gate a route the inventory has not caught
|
|
363
|
+
// up with, and refusing an administrator there would be the wrong answer
|
|
305
364
|
if (reader.isAdmin)
|
|
306
|
-
return
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
.map((rule) => ({ path: rule.path, setting: rule.setting })),
|
|
312
|
-
group: rules
|
|
313
|
-
.filter((rule) => rule.group !== undefined && reader.groups.includes(rule.group))
|
|
314
|
-
.map((rule) => ({ path: rule.path, setting: rule.setting }))
|
|
315
|
-
};
|
|
316
|
-
// a grant on the reserved public group admits any caller, and it is
|
|
317
|
-
// checked before the rules so no user or group rule can take it away
|
|
318
|
-
const publicGroup = (await store.groups()).find((group) => group.name === 'public');
|
|
319
|
-
const publicGrants = publicGroup
|
|
320
|
-
? rules
|
|
321
|
-
.filter((rule) => rule.group === publicGroup.uid && rule.setting === 'Grant')
|
|
322
|
-
.map((rule) => rule.path)
|
|
323
|
-
: [];
|
|
324
|
-
return {
|
|
325
|
-
paths: grantableRoutes.filter((path) => routeAccess_js_1.ALWAYS_VISIBLE_ROUTES.includes(path) ||
|
|
326
|
-
publicGrants.includes(path) ||
|
|
327
|
-
(0, routeAccess_js_1.isRouteGranted)(mine, path, (0, routeAccess_js_1.topLevelRouteFor)(path)))
|
|
328
|
-
};
|
|
365
|
+
return true;
|
|
366
|
+
// otherwise the answer is exactly the one `myAuthorizedRoutes` reports, so
|
|
367
|
+
// a menu entry and the call behind it cannot disagree
|
|
368
|
+
const granted = await grantedRoutesFor(reader);
|
|
369
|
+
return granted.has(path);
|
|
329
370
|
},
|
|
330
371
|
async listPermissions(caller) {
|
|
331
372
|
const reader = await requireCaller(store, caller);
|
package/build/cjs/index.js
CHANGED
|
@@ -14,9 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
18
|
-
exports.
|
|
19
|
-
exports.normaliseAppLoc = exports.newAppId = exports.isAppId = exports.escapeHtml = exports.createAppStreamWebService = exports.contentTypeFor = exports.cacheControlFor = exports.appRootOf = exports.NO_SUCH_APP = exports.DEFAULT_APP_PATH = exports.createDriveAppStreamStore = exports.APP_STREAM_INDEX = exports.splitAppBundle = void 0;
|
|
17
|
+
exports.BUNDLE_NAME = exports.HOME_CORPUS = exports.DIRECTORY_CORPUS = exports.AUTH_CONFIG_CORPUS = exports.ADMIN_CORPUS = exports.INFO_CORPUS = exports.CODE_CORPUS = exports.sanitiseDisplayName = exports.createRecordService = exports.createIdentityService = exports.HANDLED_ROUTES = exports.dispatch = exports.VIYA_CORPUS = exports.VIYA_HANDLERS = exports.VIYA_OVERLAY = exports.findViyaOperation = exports.dispatchViya = exports.emulatedHeaders = exports.VIYA_TARGET_VERSION = exports.VIYA_CAPTURED_AT = exports.EMULATED_HEADER_VALUE = exports.EMULATED_HEADER = exports.UNRECORDED = exports.VIYA_TABLE = exports.SURFACE_ADAPTER_VERSION = exports.SURFACE = exports.TAG_CAPABILITIES = exports.OVERLAY = exports.findRoute = exports.routeById = exports.ROUTES = exports.MemoryDriveStore = exports.measureDeployTree = exports.isDeployTree = exports.deployTree = exports.decodeBase64 = exports.checkDeployTree = exports.DEPLOY_SUCCESS = exports.DEPLOY_PAYLOAD_BYTES = exports.DEPLOY_LIMITS = exports.ONE_NAME_ONLY = exports.DEPLOYMENT_FILE_ERROR = exports.createDeploymentFileService = exports.assertOneFileName = exports.createDriveService = exports.isRoot = exports.basename = exports.dirname = exports.hasBlockedExtension = exports.normaliseDrivePath = void 0;
|
|
18
|
+
exports.APP_MANIFEST = exports.MemoryAppStreamStore = exports.hasFrontendRoot = exports.frontendFolderOf = exports.defaultAppName = exports.createAppStreamService = exports.checkPublishRequest = exports.appSummary = exports.APP_FOLDERS_ROOT = exports.servicesFor = exports.runCase = exports.PROVIDER_MANAGED = exports.ADMIN_SIGNED_IN = exports.RECORD_CORPUS = exports.RUNTIME_CORPUS = exports.MemorySessionRunner = exports.runTimeOfPath = exports.resolveProgram = exports.programNotFound = exports.DOCUMENTED_RUN_TIMES = exports.createRuntimeService = exports.CODE_DEBUG = exports.MemorySessionHost = exports.DEFAULT_SESSIONS = exports.createSessionService = exports.SESSION_CORPUS = exports.APP_CORPUS = exports.DEPLOY_CORPUS = exports.IDENTITY_CORPUS = exports.DRIVE_CORPUS = exports.parseIdentity = exports.IDENTITY_FORMAT = exports.DEFAULT_IDENTITY = exports.MemoryIdentityStore = exports.createDirectoryService = exports.normaliseLogFiles = exports.normaliseDiagnostics = exports.logLines = exports.createAdminService = exports.checkLogFileName = exports.MAX_LOG_LINES = exports.DEFAULT_LOG_LINES = exports.normaliseAuthConfig = exports.createAuthConfigService = exports.normaliseInfo = exports.createInfoService = exports.BROWSER_INFO = exports.withBundleVersion = exports.createHomeService = exports.NO_WEB_BUILD = void 0;
|
|
19
|
+
exports.normaliseAppLoc = exports.newAppId = exports.isAppId = exports.escapeHtml = exports.createAppStreamWebService = exports.contentTypeFor = exports.cacheControlFor = exports.appRootOf = exports.NO_SUCH_APP = exports.DEFAULT_APP_PATH = exports.createDriveAppStreamStore = exports.APP_STREAM_INDEX = exports.splitAppBundle = exports.publishRequestFor = exports.parseAppManifest = exports.FRONTEND_FOLDER = exports.BACKEND_FOLDER = void 0;
|
|
20
20
|
/**
|
|
21
21
|
* `@sasjs/api` - the SASjs Server API described once.
|
|
22
22
|
*
|
|
@@ -41,6 +41,11 @@ Object.defineProperty(exports, "basename", { enumerable: true, get: function ()
|
|
|
41
41
|
Object.defineProperty(exports, "isRoot", { enumerable: true, get: function () { return paths_js_1.isRoot; } });
|
|
42
42
|
var service_js_1 = require("./drive/service.js");
|
|
43
43
|
Object.defineProperty(exports, "createDriveService", { enumerable: true, get: function () { return service_js_1.createDriveService; } });
|
|
44
|
+
var deploymentFile_js_1 = require("./drive/deploymentFile.js");
|
|
45
|
+
Object.defineProperty(exports, "assertOneFileName", { enumerable: true, get: function () { return deploymentFile_js_1.assertOneFileName; } });
|
|
46
|
+
Object.defineProperty(exports, "createDeploymentFileService", { enumerable: true, get: function () { return deploymentFile_js_1.createDeploymentFileService; } });
|
|
47
|
+
Object.defineProperty(exports, "DEPLOYMENT_FILE_ERROR", { enumerable: true, get: function () { return deploymentFile_js_1.DEPLOYMENT_FILE_ERROR; } });
|
|
48
|
+
Object.defineProperty(exports, "ONE_NAME_ONLY", { enumerable: true, get: function () { return deploymentFile_js_1.ONE_NAME_ONLY; } });
|
|
44
49
|
var deploy_js_1 = require("./drive/deploy.js");
|
|
45
50
|
Object.defineProperty(exports, "DEPLOY_LIMITS", { enumerable: true, get: function () { return deploy_js_1.DEPLOY_LIMITS; } });
|
|
46
51
|
Object.defineProperty(exports, "DEPLOY_PAYLOAD_BYTES", { enumerable: true, get: function () { return deploy_js_1.DEPLOY_PAYLOAD_BYTES; } });
|