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