@sasjs/api 0.42.0 → 0.44.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.
@@ -1,4 +1,40 @@
1
1
  import { DEPLOYMENT_FILE_ERROR } from '../drive/deploymentFile.js';
2
+ import { DEFAULT_IDENTITY } from '../identity/fixture.js';
3
+ /** The fixture's administrator: the caller these routes are exercised as. */
4
+ const ADMIN = { userId: 'user-admin', clientId: 'web_app' };
5
+ /**
6
+ * The restricted account, which the fixture grants `/drive/file` to through its
7
+ * group and nothing else in the drive.
8
+ */
9
+ const RESTRICTED = { userId: 'user-restricted', clientId: 'web_app' };
10
+ /** The restricted account without its group grant, for the denial cases. */
11
+ const NO_DRIVE_GRANTS = {
12
+ ...DEFAULT_IDENTITY,
13
+ permissions: DEFAULT_IDENTITY.permissions.filter((rule) => rule.uid !== 'rule-routes')
14
+ };
15
+ const PUBLIC_FILE = {
16
+ ...DEFAULT_IDENTITY,
17
+ groups: [
18
+ ...DEFAULT_IDENTITY.groups,
19
+ {
20
+ uid: 'group-public',
21
+ name: 'public',
22
+ description: 'Everyone',
23
+ isActive: true,
24
+ users: []
25
+ }
26
+ ],
27
+ permissions: [
28
+ ...DEFAULT_IDENTITY.permissions,
29
+ {
30
+ uid: 'rule-public-file',
31
+ path: '/SASjsApi/drive/file',
32
+ type: 'Route',
33
+ setting: 'Grant',
34
+ group: 'group-public'
35
+ }
36
+ ]
37
+ };
2
38
  const success = { status: 'success' };
3
39
  /**
4
40
  * Bytes without an encoding API: the package builds with `lib: ES2020` and no
@@ -18,6 +54,7 @@ export const DRIVE_CORPUS = [
18
54
  route: 'POST /SASjsApi/drive/file',
19
55
  description: 'creates a file the drive did not have',
20
56
  request: {
57
+ subject: ADMIN,
21
58
  query: { _filePath: '/data/users.csv' },
22
59
  file: { name: 'users.csv', contents: 'id,name\n1,Ann\n' }
23
60
  },
@@ -28,6 +65,7 @@ export const DRIVE_CORPUS = [
28
65
  route: 'POST /SASjsApi/drive/file',
29
66
  description: 'takes the destination from the form field when the query has none',
30
67
  request: {
68
+ subject: ADMIN,
31
69
  file: { name: 'x.csv', contents: 'x' },
32
70
  body: { filePath: '/data/from-form.csv' }
33
71
  },
@@ -39,6 +77,7 @@ export const DRIVE_CORPUS = [
39
77
  description: 'refuses a create over a file that exists, as 409',
40
78
  seed: { '/data/exists.csv': 'a' },
41
79
  request: {
80
+ subject: ADMIN,
42
81
  query: { _filePath: '/data/exists.csv' },
43
82
  file: { name: 'x', contents: 'b' }
44
83
  },
@@ -49,6 +88,7 @@ export const DRIVE_CORPUS = [
49
88
  route: 'POST /SASjsApi/drive/file',
50
89
  description: 'refuses a refused extension before touching the drive',
51
90
  request: {
91
+ subject: ADMIN,
52
92
  query: { _filePath: '/data/run.sh' },
53
93
  file: { name: 'run.sh', contents: 'x' }
54
94
  },
@@ -59,6 +99,7 @@ export const DRIVE_CORPUS = [
59
99
  route: 'POST /SASjsApi/drive/file',
60
100
  description: 'refuses a path that climbs out of the drive',
61
101
  request: {
102
+ subject: ADMIN,
62
103
  query: { _filePath: '/../escape.csv' },
63
104
  file: { name: 'x', contents: 'x' }
64
105
  },
@@ -68,14 +109,20 @@ export const DRIVE_CORPUS = [
68
109
  id: 'create-file-without-payload',
69
110
  route: 'POST /SASjsApi/drive/file',
70
111
  description: 'answers for a missing file with the server wording',
71
- request: { query: { _filePath: '/data/x.csv' } },
112
+ request: {
113
+ subject: ADMIN,
114
+ query: { _filePath: '/data/x.csv' }
115
+ },
72
116
  expect: { status: 400, error: '"file" is not present.' }
73
117
  },
74
118
  {
75
119
  id: 'create-file-without-destination',
76
120
  route: 'POST /SASjsApi/drive/file',
77
121
  description: 'answers for a missing destination with the validation wording',
78
- request: { file: { name: 'x', contents: 'x' } },
122
+ request: {
123
+ subject: ADMIN,
124
+ file: { name: 'x', contents: 'x' }
125
+ },
79
126
  expect: { status: 400, error: '"_filePath" is required' }
80
127
  },
81
128
  {
@@ -84,6 +131,7 @@ export const DRIVE_CORPUS = [
84
131
  description: 'replaces the contents of a file that exists',
85
132
  seed: { '/data/keep.csv': 'old' },
86
133
  request: {
134
+ subject: ADMIN,
87
135
  query: { _filePath: '/data/keep.csv' },
88
136
  file: { name: 'keep.csv', contents: 'new' }
89
137
  },
@@ -94,6 +142,7 @@ export const DRIVE_CORPUS = [
94
142
  route: 'PATCH /SASjsApi/drive/file',
95
143
  description: 'refuses a replace of a file that is not there, as 404',
96
144
  request: {
145
+ subject: ADMIN,
97
146
  query: { _filePath: '/data/missing.csv' },
98
147
  file: { name: 'x', contents: 'x' }
99
148
  },
@@ -104,6 +153,7 @@ export const DRIVE_CORPUS = [
104
153
  route: 'PATCH /SASjsApi/drive/file',
105
154
  description: 'refuses a replace of a path that climbs out of the drive',
106
155
  request: {
156
+ subject: ADMIN,
107
157
  query: { _filePath: '/../escape.csv' },
108
158
  file: { name: 'x', contents: 'x' }
109
159
  },
@@ -114,21 +164,30 @@ export const DRIVE_CORPUS = [
114
164
  route: 'GET /SASjsApi/drive/file',
115
165
  description: 'answers with the file contents',
116
166
  seed: { '/data/keep.csv': 'a,b\n1,2\n' },
117
- request: { query: { _filePath: '/data/keep.csv' } },
167
+ request: {
168
+ subject: ADMIN,
169
+ query: { _filePath: '/data/keep.csv' }
170
+ },
118
171
  expect: { status: 200, contents: 'a,b\n1,2\n' }
119
172
  },
120
173
  {
121
174
  id: 'read-file-missing',
122
175
  route: 'GET /SASjsApi/drive/file',
123
176
  description: 'refuses a read of a file that is not there',
124
- request: { query: { _filePath: '/data/missing.csv' } },
177
+ request: {
178
+ subject: ADMIN,
179
+ query: { _filePath: '/data/missing.csv' }
180
+ },
125
181
  expect: { status: 404, error: `File doesn't exist.` }
126
182
  },
127
183
  {
128
184
  id: 'read-file-outside-drive',
129
185
  route: 'GET /SASjsApi/drive/file',
130
186
  description: 'refuses a read of a path that climbs out of the drive',
131
- request: { query: { _filePath: '/../escape.csv' } },
187
+ request: {
188
+ subject: ADMIN,
189
+ query: { _filePath: '/../escape.csv' }
190
+ },
132
191
  expect: { status: 400, error: "Can't get file outside drive." }
133
192
  },
134
193
  {
@@ -137,6 +196,7 @@ export const DRIVE_CORPUS = [
137
196
  description: 'refuses a request that names the file twice, in two readings',
138
197
  seed: { '/data/keep.csv': 'a' },
139
198
  request: {
199
+ subject: ADMIN,
140
200
  query: { _filePath: '/data/keep.csv', _FILE: '/data/keep.csv' }
141
201
  },
142
202
  expect: {
@@ -149,14 +209,20 @@ export const DRIVE_CORPUS = [
149
209
  route: 'GET /SASjsApi/drive/file',
150
210
  description: 'reads a deployment file by the name a streamed page links to',
151
211
  seed: { '/Public/app/services/web/main.js': 'console.log(1)' },
152
- request: { query: { _FILE: '/Public/app/services/web/main.js' } },
212
+ request: {
213
+ subject: ADMIN,
214
+ query: { _FILE: '/Public/app/services/web/main.js' }
215
+ },
153
216
  expect: { status: 200, contents: 'console.log(1)' }
154
217
  },
155
218
  {
156
219
  id: 'read-streamed-file-missing',
157
220
  route: 'GET /SASjsApi/drive/file',
158
221
  description: 'answers a missing deployment file the way the estate does, not as a 404',
159
- request: { query: { _FILE: '/Public/app/services/web/gone.js' } },
222
+ request: {
223
+ subject: ADMIN,
224
+ query: { _FILE: '/Public/app/services/web/gone.js' }
225
+ },
160
226
  expect: { status: 202, contents: DEPLOYMENT_FILE_ERROR }
161
227
  },
162
228
  {
@@ -164,21 +230,30 @@ export const DRIVE_CORPUS = [
164
230
  route: 'DELETE /SASjsApi/drive/file',
165
231
  description: 'deletes a file that exists',
166
232
  seed: { '/data/keep.csv': 'a' },
167
- request: { query: { _filePath: '/data/keep.csv' } },
233
+ request: {
234
+ subject: ADMIN,
235
+ query: { _filePath: '/data/keep.csv' }
236
+ },
168
237
  expect: { status: 200, body: success }
169
238
  },
170
239
  {
171
240
  id: 'delete-file-missing',
172
241
  route: 'DELETE /SASjsApi/drive/file',
173
242
  description: 'refuses a delete of a file that is not there',
174
- request: { query: { _filePath: '/data/missing.csv' } },
243
+ request: {
244
+ subject: ADMIN,
245
+ query: { _filePath: '/data/missing.csv' }
246
+ },
175
247
  expect: { status: 404, error: `File doesn't exist.` }
176
248
  },
177
249
  {
178
250
  id: 'delete-file-outside-drive',
179
251
  route: 'DELETE /SASjsApi/drive/file',
180
252
  description: 'refuses a delete of a path that climbs out of the drive',
181
- request: { query: { _filePath: '/../escape.csv' } },
253
+ request: {
254
+ subject: ADMIN,
255
+ query: { _filePath: '/../escape.csv' }
256
+ },
182
257
  expect: { status: 400, error: "Can't delete file outside drive." }
183
258
  },
184
259
  {
@@ -186,42 +261,59 @@ export const DRIVE_CORPUS = [
186
261
  route: 'GET /SASjsApi/drive/folder',
187
262
  description: 'lists the files and folders of a folder',
188
263
  seed: { '/data/a.csv': 'a', '/data/reports/b.csv': 'b' },
189
- request: { query: { _folderPath: '/data' } },
264
+ request: {
265
+ subject: ADMIN,
266
+ query: { _folderPath: '/data' }
267
+ },
190
268
  expect: { status: 200, body: { files: ['a.csv'], folders: ['reports'] } }
191
269
  },
192
270
  {
193
271
  id: 'list-folder-missing',
194
272
  route: 'GET /SASjsApi/drive/folder',
195
273
  description: 'refuses a listing of a folder that is not there',
196
- request: { query: { _folderPath: '/nope' } },
274
+ request: {
275
+ subject: ADMIN,
276
+ query: { _folderPath: '/nope' }
277
+ },
197
278
  expect: { status: 404, error: `Folder doesn't exist.` }
198
279
  },
199
280
  {
200
281
  id: 'list-folder-outside-drive',
201
282
  route: 'GET /SASjsApi/drive/folder',
202
283
  description: 'refuses a listing of a path that climbs out of the drive',
203
- request: { query: { _folderPath: '/../escape' } },
284
+ request: {
285
+ subject: ADMIN,
286
+ query: { _folderPath: '/../escape' }
287
+ },
204
288
  expect: { status: 400, error: "Can't get folder outside drive." }
205
289
  },
206
290
  {
207
291
  id: 'delete-folder-without-path',
208
292
  route: 'DELETE /SASjsApi/drive/folder',
209
293
  description: 'answers for a missing folder path, because the table marks it required',
210
- request: {},
294
+ request: {
295
+ subject: ADMIN
296
+ },
211
297
  expect: { status: 400, error: '"_folderPath" is required' }
212
298
  },
213
299
  {
214
300
  id: 'create-folder-without-path',
215
301
  route: 'POST /SASjsApi/drive/folder',
216
302
  description: 'answers for a missing folder path in the body',
217
- request: { body: {} },
303
+ request: {
304
+ subject: ADMIN,
305
+ body: {}
306
+ },
218
307
  expect: { status: 400, error: '"folderPath" is required' }
219
308
  },
220
309
  {
221
310
  id: 'create-folder',
222
311
  route: 'POST /SASjsApi/drive/folder',
223
312
  description: 'creates a folder',
224
- request: { body: { folderPath: '/data/reports' } },
313
+ request: {
314
+ subject: ADMIN,
315
+ body: { folderPath: '/data/reports' }
316
+ },
225
317
  expect: { status: 200, body: success }
226
318
  },
227
319
  {
@@ -229,7 +321,10 @@ export const DRIVE_CORPUS = [
229
321
  route: 'POST /SASjsApi/drive/folder',
230
322
  description: 'refuses a folder that already exists, as 409',
231
323
  seed: { '/data/reports/a.csv': 'a' },
232
- request: { body: { folderPath: '/data/reports' } },
324
+ request: {
325
+ subject: ADMIN,
326
+ body: { folderPath: '/data/reports' }
327
+ },
233
328
  expect: { status: 409, error: 'Folder already exists.' }
234
329
  },
235
330
  {
@@ -237,14 +332,20 @@ export const DRIVE_CORPUS = [
237
332
  route: 'DELETE /SASjsApi/drive/folder',
238
333
  description: 'deletes a folder with everything under it',
239
334
  seed: { '/data/reports/a.csv': 'a', '/data/reports/nested/b.csv': 'b' },
240
- request: { query: { _folderPath: '/data/reports' } },
335
+ request: {
336
+ subject: ADMIN,
337
+ query: { _folderPath: '/data/reports' }
338
+ },
241
339
  expect: { status: 200, body: success }
242
340
  },
243
341
  {
244
342
  id: 'delete-folder-missing',
245
343
  route: 'DELETE /SASjsApi/drive/folder',
246
344
  description: 'refuses a delete of a folder that is not there',
247
- request: { query: { _folderPath: '/nope' } },
345
+ request: {
346
+ subject: ADMIN,
347
+ query: { _folderPath: '/nope' }
348
+ },
248
349
  expect: { status: 404, error: `Folder doesn't exist.` }
249
350
  },
250
351
  {
@@ -252,7 +353,10 @@ export const DRIVE_CORPUS = [
252
353
  route: 'POST /SASjsApi/drive/rename',
253
354
  description: 'moves a file to a new path',
254
355
  seed: { '/data/old.csv': 'r' },
255
- request: { body: { oldPath: '/data/old.csv', newPath: '/data/new.csv' } },
356
+ request: {
357
+ subject: ADMIN,
358
+ body: { oldPath: '/data/old.csv', newPath: '/data/new.csv' }
359
+ },
256
360
  expect: { status: 200, body: success }
257
361
  },
258
362
  {
@@ -260,14 +364,20 @@ export const DRIVE_CORPUS = [
260
364
  route: 'POST /SASjsApi/drive/rename',
261
365
  description: 'refuses a move onto something that exists',
262
366
  seed: { '/data/a.csv': 'a', '/data/b.csv': 'b' },
263
- request: { body: { oldPath: '/data/a.csv', newPath: '/data/b.csv' } },
367
+ request: {
368
+ subject: ADMIN,
369
+ body: { oldPath: '/data/a.csv', newPath: '/data/b.csv' }
370
+ },
264
371
  expect: { status: 409, error: 'File with new name already exists.' }
265
372
  },
266
373
  {
267
374
  id: 'rename-missing',
268
375
  route: 'POST /SASjsApi/drive/rename',
269
376
  description: 'refuses a move of something that is not there',
270
- request: { body: { oldPath: '/data/nope.csv', newPath: '/data/x.csv' } },
377
+ request: {
378
+ subject: ADMIN,
379
+ body: { oldPath: '/data/nope.csv', newPath: '/data/x.csv' }
380
+ },
271
381
  expect: { status: 404, error: 'No file/folder found for provided path.' }
272
382
  },
273
383
  {
@@ -276,6 +386,7 @@ export const DRIVE_CORPUS = [
276
386
  description: 'refuses a rename that would produce a name the file routes refuse',
277
387
  seed: { '/data/report.csv': 'a,b' },
278
388
  request: {
389
+ subject: ADMIN,
279
390
  body: { oldPath: '/data/report.csv', newPath: '/data/report.sh' }
280
391
  },
281
392
  expect: { status: 400, error: 'Invalid file extension' }
@@ -286,6 +397,7 @@ export const DRIVE_CORPUS = [
286
397
  description: 'renames a folder whose new name carries a blocked suffix',
287
398
  seed: { '/data/reports/a.csv': 'a' },
288
399
  request: {
400
+ subject: ADMIN,
289
401
  body: { oldPath: '/data/reports', newPath: '/data/reports.sh' }
290
402
  },
291
403
  expect: { status: 200, body: { status: 'success' } }
@@ -296,6 +408,7 @@ export const DRIVE_CORPUS = [
296
408
  description: 'refuses a folder moved inside itself, which the server loses at the filesystem',
297
409
  seed: { '/data/reports/a.csv': 'a' },
298
410
  request: {
411
+ subject: ADMIN,
299
412
  body: { oldPath: '/data/reports', newPath: '/data/reports/nested' }
300
413
  },
301
414
  expect: {
@@ -308,7 +421,10 @@ export const DRIVE_CORPUS = [
308
421
  route: 'GET /SASjsApi/drive/filetree',
309
422
  description: 'answers with the drive tree',
310
423
  seed: { '/data/a.csv': 'a' },
311
- request: { query: { _folderPath: '/data' } },
424
+ request: {
425
+ subject: ADMIN,
426
+ query: { _folderPath: '/data' }
427
+ },
312
428
  expect: {
313
429
  status: 200,
314
430
  // Partial, because a file's `created` and `modified` are the host's
@@ -337,6 +453,7 @@ export const DRIVE_CORPUS = [
337
453
  route: 'POST /SASjsApi/drive/deploy',
338
454
  description: 'writes a whole tree under the appLoc it names',
339
455
  request: {
456
+ subject: ADMIN,
340
457
  body: {
341
458
  appLoc: '/Public/apps/demo',
342
459
  fileTree: {
@@ -364,6 +481,7 @@ export const DRIVE_CORPUS = [
364
481
  route: 'POST /SASjsApi/drive/deploy',
365
482
  description: 'refuses a tree over the entry cap, naming the figure and the cap',
366
483
  request: {
484
+ subject: ADMIN,
367
485
  body: {
368
486
  appLoc: '/Public/apps/many',
369
487
  fileTree: { members: manyMembers(10001) }
@@ -383,6 +501,7 @@ export const DRIVE_CORPUS = [
383
501
  route: 'POST /SASjsApi/drive/deploy',
384
502
  description: 'refuses a member name that would escape the deployment root',
385
503
  request: {
504
+ subject: ADMIN,
386
505
  body: {
387
506
  appLoc: '/Public/apps/hostile',
388
507
  fileTree: {
@@ -403,7 +522,10 @@ export const DRIVE_CORPUS = [
403
522
  id: 'deploy-refused-by-shape',
404
523
  route: 'POST /SASjsApi/drive/deploy',
405
524
  description: 'refuses a fileTree that is not a tree, in the routes own envelope',
406
- request: { body: { appLoc: '/Public/apps/bad', fileTree: { members: 1 } } },
525
+ request: {
526
+ subject: ADMIN,
527
+ body: { appLoc: '/Public/apps/bad', fileTree: { members: 1 } }
528
+ },
407
529
  expect: {
408
530
  status: 400,
409
531
  body: {
@@ -419,6 +541,7 @@ export const DRIVE_CORPUS = [
419
541
  description: 'answers the routes 500 when the drive refuses the write',
420
542
  unwritable: true,
421
543
  request: {
544
+ subject: ADMIN,
422
545
  body: {
423
546
  appLoc: '/Public/apps/demo',
424
547
  fileTree: {
@@ -437,6 +560,7 @@ export const DRIVE_CORPUS = [
437
560
  route: 'POST /SASjsApi/drive/deploy',
438
561
  description: 'refuses an appLoc that resolves outside the drive',
439
562
  request: {
563
+ subject: ADMIN,
440
564
  body: { appLoc: '/../outside', fileTree: { members: [] } }
441
565
  },
442
566
  expect: {
@@ -450,7 +574,162 @@ export const DRIVE_CORPUS = [
450
574
  route: 'GET /SASjsApi/drive/file',
451
575
  description: 'keeps a byte file as bytes',
452
576
  seed: { '/data/pack.zip': bytes(80, 75, 3, 4) },
453
- request: { query: { _filePath: '/data/pack.zip' } },
577
+ request: {
578
+ subject: ADMIN,
579
+ query: { _filePath: '/data/pack.zip' }
580
+ },
454
581
  expect: { status: 200, contents: bytes(80, 75, 3, 4) }
455
- }
582
+ },
583
+ // --------------------------------------------------- the rule that decides
584
+ {
585
+ id: 'read-file-anonymous-public-grant',
586
+ route: 'GET /SASjsApi/drive/file',
587
+ description: 'admits an anonymous caller through an exact public group grant',
588
+ identity: PUBLIC_FILE,
589
+ seed: { '/data/public.csv': 'public contents' },
590
+ request: { query: { _filePath: '/data/public.csv' } },
591
+ expect: { status: 200, contents: 'public contents' }
592
+ },
593
+ {
594
+ id: 'read-file-public-invalid-token',
595
+ route: 'GET /SASjsApi/drive/file',
596
+ description: 'treats an invalid token as anonymous on an exactly public route',
597
+ identity: PUBLIC_FILE,
598
+ seed: { '/data/public.csv': 'public contents' },
599
+ request: {
600
+ token: 'invalid-token',
601
+ query: { _filePath: '/data/public.csv' }
602
+ },
603
+ expect: { status: 200, contents: 'public contents' }
604
+ },
605
+ {
606
+ id: 'read-file-public-inactive-token',
607
+ route: 'GET /SASjsApi/drive/file',
608
+ description: 'treats a deactivated token as anonymous on an exactly public route',
609
+ identity: {
610
+ ...PUBLIC_FILE,
611
+ users: PUBLIC_FILE.users.map((user) => user.uid === 'user-restricted' ? { ...user, isActive: false } : user),
612
+ tokens: [
613
+ {
614
+ username: 'sasjsuser',
615
+ clientId: 'web_app',
616
+ accessToken: 'inactive-access',
617
+ refreshToken: 'inactive-refresh'
618
+ }
619
+ ]
620
+ },
621
+ seed: { '/data/public.csv': 'public contents' },
622
+ request: {
623
+ token: 'inactive-access',
624
+ query: { _filePath: '/data/public.csv' }
625
+ },
626
+ expect: { status: 200, contents: 'public contents' }
627
+ },
628
+ {
629
+ id: 'create-file-anonymous-public-grant',
630
+ route: 'POST /SASjsApi/drive/file',
631
+ description: 'admits public writes when the exact route is granted',
632
+ identity: PUBLIC_FILE,
633
+ request: {
634
+ query: { _filePath: '/data/new.csv' },
635
+ file: { name: 'new.csv', contents: 'new' }
636
+ },
637
+ expect: { status: 200, body: success },
638
+ expectDrive: { present: ['/data/new.csv'] }
639
+ },
640
+ {
641
+ id: 'read-folder-anonymous-other-public-grant',
642
+ route: 'GET /SASjsApi/drive/folder',
643
+ description: 'refuses an anonymous caller when a different path is public',
644
+ identity: PUBLIC_FILE,
645
+ request: { query: { _folderPath: '/data' } },
646
+ expect: { status: 401, error: 'Unauthorized' }
647
+ },
648
+ {
649
+ id: 'read-file-anonymous-public-parent-grant',
650
+ route: 'GET /SASjsApi/drive/file',
651
+ description: 'does not inherit public authentication from a parent grant',
652
+ identity: {
653
+ ...PUBLIC_FILE,
654
+ permissions: PUBLIC_FILE.permissions.map((rule) => rule.uid === 'rule-public-file' ? { ...rule, path: '/SASjsApi' } : rule)
655
+ },
656
+ seed: { '/data/public.csv': 'public contents' },
657
+ request: { query: { _filePath: '/data/public.csv' } },
658
+ expect: { status: 401, error: 'Unauthorized' }
659
+ },
660
+ {
661
+ id: 'read-file-anonymous-public-deny',
662
+ route: 'GET /SASjsApi/drive/file',
663
+ description: 'does not authenticate an anonymous caller through a public deny',
664
+ identity: {
665
+ ...PUBLIC_FILE,
666
+ permissions: PUBLIC_FILE.permissions.map((rule) => rule.uid === 'rule-public-file' ? { ...rule, setting: 'Deny' } : rule)
667
+ },
668
+ request: { query: { _filePath: '/data/public.csv' } },
669
+ expect: { status: 401, error: 'Unauthorized' }
670
+ },
671
+ {
672
+ id: 'read-file-public-user-deny',
673
+ route: 'GET /SASjsApi/drive/file',
674
+ description: 'admits an authenticated caller despite an explicit user deny on a public route',
675
+ identity: {
676
+ ...PUBLIC_FILE,
677
+ permissions: [
678
+ ...PUBLIC_FILE.permissions,
679
+ {
680
+ uid: 'user-file-deny',
681
+ path: '/SASjsApi/drive/file',
682
+ type: 'Route',
683
+ setting: 'Deny',
684
+ user: 'user-restricted'
685
+ }
686
+ ]
687
+ },
688
+ seed: { '/data/public.csv': 'public contents' },
689
+ request: { subject: RESTRICTED, query: { _filePath: '/data/public.csv' } },
690
+ expect: { status: 200, contents: 'public contents' }
691
+ },
692
+ {
693
+ id: 'read-file-granted-by-a-group-rule',
694
+ route: 'GET /SASjsApi/drive/file',
695
+ description: 'admits a restricted account the fixture grants this route, so the refusal beside it is the rule',
696
+ seed: { '/data/keep.csv': 'a,b\n1,2\n' },
697
+ request: { subject: RESTRICTED, query: { _filePath: '/data/keep.csv' } },
698
+ expect: { status: 200, contents: 'a,b\n1,2\n' }
699
+ },
700
+ {
701
+ id: 'rename-file-denied-to-a-restricted-account',
702
+ route: 'POST /SASjsApi/drive/rename',
703
+ description: 'refuses a drive route the rules do not grant, with the 401 a missing token earns',
704
+ seed: { '/data/old.csv': 'r' },
705
+ request: {
706
+ subject: RESTRICTED,
707
+ body: { oldPath: '/data/old.csv', newPath: '/data/new.csv' }
708
+ },
709
+ expect: { status: 401, error: 'Unauthorized' }
710
+ },
711
+ // The permission gate refuses a caller the rules do not grant, on every route
712
+ // the inventory addresses. Each of these is the same account and the same
713
+ // refusal - the gate runs before the payload is read, which is why a bare
714
+ // request answers 401 rather than the 400 a missing parameter would earn.
715
+ ...[
716
+ 'GET /SASjsApi/drive/file',
717
+ 'GET /SASjsApi/drive/folder',
718
+ 'GET /SASjsApi/drive/filetree',
719
+ 'POST /SASjsApi/drive/file',
720
+ 'PATCH /SASjsApi/drive/file',
721
+ 'DELETE /SASjsApi/drive/file',
722
+ 'POST /SASjsApi/drive/folder',
723
+ 'DELETE /SASjsApi/drive/folder',
724
+ 'POST /SASjsApi/drive/deploy',
725
+ 'DELETE /SASjsApi/drive/deploy',
726
+ 'POST /SASjsApi/drive/deploy/upload'
727
+ ].map((route) => ({
728
+ id: `${route.toLowerCase().replace(/[^a-z0-9]+/g, '-')}-denied-to-a-restricted-account`,
729
+ route,
730
+ description: 'refuses a drive route the rules do not grant, before it reads the payload',
731
+ identity: NO_DRIVE_GRANTS,
732
+ request: { subject: RESTRICTED },
733
+ expect: { status: 401, error: 'Unauthorized' }
734
+ }))
456
735
  ];
@@ -97,7 +97,11 @@ export interface Services {
97
97
  * implement - the difference is the message, and it names the capability.
98
98
  */
99
99
  identity?: IdentityService;
100
- /** Users, groups, permission rules and clients. Absent, the record routes answer 501. */
100
+ /**
101
+ * Users, groups, permission rules and clients. Absent, the record routes answer
102
+ * 501. If an identity service is configured, permission-gated routes also
103
+ * answer 501 without records; a drive-only host has no identity gate.
104
+ */
101
105
  records?: RecordService;
102
106
  /**
103
107
  * A triggered session's record, log, output and state. A host without one
@@ -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;AAC3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