@sasjs/api 0.41.0 → 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.
@@ -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` 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
+ * 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
  ];
@@ -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',
@@ -26,6 +26,29 @@ const RUN_ROUTES = [
26
26
  'POST /SASjsApi/code/execute',
27
27
  'POST /SASjsApi/code/trigger'
28
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
+ ];
29
52
  /** A payload value, when the caller actually stated one. */
30
53
  const given = (value) => typeof value === 'string' && value !== '' ? value : undefined;
31
54
  /**
@@ -114,10 +137,42 @@ const dispatch = async (services, routeId, request = {}) => {
114
137
  // told which capability it is missing rather than sent round a login loop, so
115
138
  // the gate is tested on the service that serves the route.
116
139
  const runtimeScoped = RUN_ROUTES.includes(routeId);
117
- if ((identityScoped && records) || (runtimeScoped && services.runtime)) {
118
- const subject = request.subject ??
119
- (identity ? await identity.authenticate(request.token) : undefined);
120
- if (!subject) {
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) {
121
176
  // A host may serve records without a sign-in flow - it resolves the caller
122
177
  // itself and passes `subject`. Without one it cannot authenticate at all,
123
178
  // and a 401 would send every request round the login loop for ever, so it
@@ -126,6 +181,20 @@ const dispatch = async (services, routeId, request = {}) => {
126
181
  throw new types_js_1.ApiError(501, `This host has no identity service, so it cannot answer ${routeId}.`);
127
182
  throw new types_js_1.ApiError(401, 'Unauthorized');
128
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');
129
198
  }
130
199
  validate(route, request);
131
200
  const query = request.query || {};
@@ -176,12 +245,6 @@ const dispatch = async (services, routeId, request = {}) => {
176
245
  throw new types_js_1.ApiError(501, `This host has no record service, so it cannot answer ${routeId}.`);
177
246
  return records;
178
247
  };
179
- /** The caller, from the request's own subject or the token it carried. */
180
- const caller = async () => {
181
- if (request.subject)
182
- return request.subject;
183
- return identity?.authenticate(request.token);
184
- };
185
248
  if (routeId.startsWith('POST /SASjsApi/auth/') ||
186
249
  routeId.startsWith('POST /SASLogon/') ||
187
250
  routeId === 'GET /SASLogon/logout' ||
@@ -241,10 +304,11 @@ const dispatch = async (services, routeId, request = {}) => {
241
304
  }
242
305
  // ------------------------------------------------- a host's own reports
243
306
  //
244
- // The administrator middleware is the host's (sasjs/server mounts
245
- // authenticateAccessToken and verifyAdmin ahead of all of these), which is
246
- // why their 401 is marked host-only in the overlay. The package answers a
247
- // body, and for a log tail the refusals that belong to the name rule.
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.
248
312
  case 'GET /SASjsApi/admin/diagnostics': {
249
313
  if (!services.admin)
250
314
  throw new types_js_1.ApiError(501, `This host has no admin service, so it cannot answer ${routeId}.`);
@@ -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
- if (!caller)
35
- throw unauthorized();
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
- // an administrator holds every route, and the always-visible ones are
304
- // visible whatever the rules say
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 { paths: [...grantableRoutes] };
307
- const rules = await store.permissions();
308
- const mine = {
309
- user: rules
310
- .filter((rule) => rule.user === reader.uid)
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);
@@ -66,12 +66,11 @@ exports.OVERLAY = {
66
66
  responses: { 200: 'OK!' }
67
67
  },
68
68
  // Admin - the host's own process and files, over the reports it supplies.
69
- // The administrator check is the host's mount point (sasjs/server puts
70
- // authenticateAccessToken and verifyAdmin in front of all three), so its 401
71
- // - and the 500 a genuine failure answers - are host-only statuses.
69
+ // The administrator check is the package's, so its 401 is a case like any
70
+ // other; the 500 a genuine failure answers stays the host's.
72
71
  'GET /SASjsApi/admin/diagnostics': {
73
72
  implemented: true,
74
- hostResponses: [401, 500],
73
+ hostResponses: [500],
75
74
  responses: {
76
75
  200: {
77
76
  build: { version: '', gitHash: '', buildDate: null },
@@ -111,14 +110,14 @@ exports.OVERLAY = {
111
110
  },
112
111
  'GET /SASjsApi/admin/logs': {
113
112
  implemented: true,
114
- hostResponses: [401, 500],
113
+ hostResponses: [500],
115
114
  responses: { 200: { files: [] } }
116
115
  },
117
116
  'GET /SASjsApi/admin/logs/{fileName}': {
118
117
  implemented: true,
119
118
  // 400 and 404 are the name rule's, and this package answers them before the
120
119
  // host is asked for anything
121
- hostResponses: [401, 500],
120
+ hostResponses: [500],
122
121
  responses: {
123
122
  200: {
124
123
  fileName: '',
@@ -14,9 +14,10 @@ export declare const CORPUS_DIAGNOSTICS: DiagnosticsResponse;
14
14
  /**
15
15
  * The admin corpus: one case per documented status of each route.
16
16
  *
17
- * `401` and `500` are host-only (the administrator middleware and the host's own
18
- * failures), so they are not cases; what is pinned is the body, the traversal
19
- * refusal the package owns, and the `404` for a name the folder does not hold.
17
+ * The `401` is the package's now - the same `mayAdminister` the record routes
18
+ * refuse with - so both halves are cases here, with the administrator's `200`
19
+ * between them. The host's own `500` stays out, as it cannot be produced from a
20
+ * fixture.
20
21
  */
21
22
  export declare const ADMIN_CORPUS: CorpusCase[];
22
23
  //# sourceMappingURL=admin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../../src/corpus/admin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,KAAK,EACV,mBAAmB,EACnB,WAAW,EACX,OAAO,EACR,MAAM,qBAAqB,CAAA;AAE5B;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,EAAE,WAIxB,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,OAM7B,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,mBAiChC,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,EAAE,UAAU,EAqCpC,CAAA"}
1
+ {"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../../src/corpus/admin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,KAAK,EACV,mBAAmB,EACnB,WAAW,EACX,OAAO,EACR,MAAM,qBAAqB,CAAA;AAE5B;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,EAAE,WAIxB,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,OAM7B,CAAA;AAED,eAAO,MAAM,kBAAkB,EAAE,mBAiChC,CAAA;AAMD;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,EAAE,UAAU,EAkEpC,CAAA"}
@@ -52,47 +52,79 @@ export const CORPUS_DIAGNOSTICS = {
52
52
  newestModified: CORPUS_LOG.modified
53
53
  }
54
54
  };
55
+ /** The fixture's administrator, and the account the rules do not admit. */
56
+ const ADMIN = { userId: 'user-admin', clientId: 'web_app' };
57
+ const RESTRICTED = { userId: 'user-restricted', clientId: 'web_app' };
55
58
  /**
56
59
  * The admin corpus: one case per documented status of each route.
57
60
  *
58
- * `401` and `500` are host-only (the administrator middleware and the host's own
59
- * failures), so they are not cases; what is pinned is the body, the traversal
60
- * refusal the package owns, and the `404` for a name the folder does not hold.
61
+ * The `401` is the package's now - the same `mayAdminister` the record routes
62
+ * refuse with - so both halves are cases here, with the administrator's `200`
63
+ * between them. The host's own `500` stays out, as it cannot be produced from a
64
+ * fixture.
61
65
  */
62
66
  export const ADMIN_CORPUS = [
63
67
  {
64
68
  id: 'admin-diagnostics-answers-the-report',
65
69
  route: 'GET /SASjsApi/admin/diagnostics',
66
70
  description: 'answers the host diagnostics report field for field',
67
- request: {},
71
+ request: { subject: ADMIN },
68
72
  expect: { status: 200, body: CORPUS_DIAGNOSTICS }
69
73
  },
70
74
  {
71
75
  id: 'admin-logs-lists-the-files',
72
76
  route: 'GET /SASjsApi/admin/logs',
73
77
  description: 'answers the log files the host holds, newest first',
74
- request: {},
78
+ request: { subject: ADMIN },
75
79
  expect: { status: 200, body: { files: [CORPUS_LOG] } }
76
80
  },
77
81
  {
78
82
  id: 'admin-log-tail-answers-the-tail',
79
83
  route: 'GET /SASjsApi/admin/logs/{fileName}',
80
84
  description: 'answers the tail of a log the folder holds',
81
- request: { params: { fileName: CORPUS_LOG.name } },
85
+ request: { subject: ADMIN, params: { fileName: CORPUS_LOG.name } },
82
86
  expect: { status: 200, body: CORPUS_LOG_TAIL }
83
87
  },
84
88
  {
85
89
  id: 'admin-log-tail-refuses-a-traversal',
86
90
  route: 'GET /SASjsApi/admin/logs/{fileName}',
87
91
  description: 'refuses a name that could resolve outside the log folder, before the host is asked',
88
- request: { params: { fileName: '../20260101000000.log' } },
92
+ request: { subject: ADMIN, params: { fileName: '../20260101000000.log' } },
89
93
  expect: { status: 400, error: 'Invalid log file name.' }
90
94
  },
91
95
  {
92
96
  id: 'admin-log-tail-answers-404',
93
97
  route: 'GET /SASjsApi/admin/logs/{fileName}',
94
98
  description: 'answers 404 for a name the folder does not hold',
95
- request: { params: { fileName: '20250101000000.log' } },
99
+ request: { subject: ADMIN, params: { fileName: '20250101000000.log' } },
96
100
  expect: { status: 404, error: 'Log file not found.' }
101
+ },
102
+ {
103
+ id: 'admin-diagnostics-refused-to-a-restricted-account',
104
+ route: 'GET /SASjsApi/admin/diagnostics',
105
+ description: 'refuses a signed-in account that is not an administrator, in the wording verifyAdmin uses',
106
+ request: { subject: RESTRICTED },
107
+ expect: { status: 401, error: 'Admin account required' }
108
+ },
109
+ {
110
+ id: 'admin-logs-refused-to-a-restricted-account',
111
+ route: 'GET /SASjsApi/admin/logs',
112
+ description: 'refuses the log inventory to a restricted account',
113
+ request: { subject: RESTRICTED },
114
+ expect: { status: 401, error: 'Admin account required' }
115
+ },
116
+ {
117
+ id: 'admin-log-tail-refused-to-a-restricted-account',
118
+ route: 'GET /SASjsApi/admin/logs/{fileName}',
119
+ description: 'refuses a log tail to a restricted account',
120
+ request: { subject: RESTRICTED, params: { fileName: CORPUS_LOG.name } },
121
+ expect: { status: 401, error: 'Admin account required' }
122
+ },
123
+ {
124
+ id: 'admin-logs-refused-with-no-caller',
125
+ route: 'GET /SASjsApi/admin/logs',
126
+ description: 'refuses a request that carries no caller at all',
127
+ request: {},
128
+ expect: { status: 401, error: 'Unauthorized' }
97
129
  }
98
130
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/corpus/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAa5C,eAAO,MAAM,cAAc,EAAE,UAAU,EAyOtC,CAAA"}
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/corpus/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAgB5C,eAAO,MAAM,cAAc,EAAE,UAAU,EAgQtC,CAAA"}
@@ -1,4 +1,6 @@
1
1
  const ADMIN = { userId: 'user-admin', clientId: 'web_app' };
2
+ /** The fixture's restricted account: granted `stp/execute`, denied `code/execute`. */
3
+ const RESTRICTED = { userId: 'user-restricted', clientId: 'web_app' };
2
4
  const PROGRAM = '/Public/apps/demo/run.sas';
3
5
  const CODE = 'data _null_;\n put "hello";\nrun;';
4
6
  const UNAUTHORIZED = 'Unauthorized';
@@ -192,6 +194,28 @@ export const RUNTIME_CORPUS = [
192
194
  request: { body: {} },
193
195
  expect: { status: 401, error: UNAUTHORIZED }
194
196
  },
197
+ {
198
+ // The fixture denies this account `/SASjsApi/code/execute` with a user rule,
199
+ // and a denied rule refuses the call rather than only the menu entry beside
200
+ // it. On a server that is `authorize`; here it is the decision
201
+ // `myAuthorizedRoutes` reports from, asked of the same store.
202
+ id: 'code-execute-denied-by-a-rule',
203
+ route: 'POST /SASjsApi/code/execute',
204
+ description: 'refuses a caller the rules do not grant, with the 401 a missing token earns',
205
+ request: { subject: RESTRICTED, body: { code: CODE, runTime: 'sas' } },
206
+ expect: { status: 401, error: UNAUTHORIZED }
207
+ },
208
+ {
209
+ // The positive control for the case above: the same account is granted
210
+ // `stp/execute` by a group rule, so the refusal there is the rule and not a
211
+ // blanket refusal of everything a restricted account asks for.
212
+ id: 'stp-execute-granted-by-a-group-rule',
213
+ route: 'POST /SASjsApi/stp/execute',
214
+ description: 'admits a restricted account the rules grant',
215
+ request: { subject: RESTRICTED, body: { _program: PROGRAM } },
216
+ runOutput: { contents: 'granted run' },
217
+ expect: { status: 200, contents: 'granted run' }
218
+ },
195
219
  // ----------------------------------------------- POST /code/trigger
196
220
  {
197
221
  id: 'code-trigger-answers-session',
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch.d.ts","sourceRoot":"","sources":["../../../src/host/dispatch.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;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