@sasjs/api 0.44.3 → 0.44.5

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.
@@ -143,6 +143,25 @@ exports.RECORD_CORPUS = [
143
143
  partial: { uid: RESTRICTED_UID, username: 'sasjsuser', isAdmin: false }
144
144
  }
145
145
  },
146
+ {
147
+ id: 'get-user-by-username-mixed-case',
148
+ route: 'GET /SASjsApi/user/by/username/{username}',
149
+ description: 'finds the account when the path names it in another case',
150
+ identity: exports.ADMIN_SIGNED_IN,
151
+ request: { token: ADMIN, params: { username: 'SASJSUSER' } },
152
+ expect: { status: 200, partial: { uid: RESTRICTED_UID } }
153
+ },
154
+ {
155
+ id: 'get-user-by-username-refused-name',
156
+ route: 'GET /SASjsApi/user/by/username/{username}',
157
+ description: 'refuses a path parameter the username schema does not allow',
158
+ identity: exports.ADMIN_SIGNED_IN,
159
+ request: { token: ADMIN, params: { username: 'a-b' } },
160
+ expect: {
161
+ status: 400,
162
+ error: '"username" must only contain alpha-numeric characters'
163
+ }
164
+ },
146
165
  {
147
166
  id: 'get-user-by-username-unauthenticated',
148
167
  route: 'GET /SASjsApi/user/by/username/{username}',
@@ -222,6 +241,49 @@ exports.RECORD_CORPUS = [
222
241
  },
223
242
  expect: { status: 409, error: 'Username already exists.' }
224
243
  },
244
+ {
245
+ id: 'create-user-bad-admin-flag',
246
+ route: 'POST /SASjsApi/user',
247
+ description: 'refuses an isAdmin the schema does not call a boolean',
248
+ identity: exports.ADMIN_SIGNED_IN,
249
+ request: {
250
+ token: ADMIN,
251
+ body: {
252
+ username: 'flaguser',
253
+ displayName: 'Flag User',
254
+ password: 'password',
255
+ isAdmin: 'yes'
256
+ }
257
+ },
258
+ expect: { status: 400, error: '"isAdmin" must be a boolean' }
259
+ },
260
+ {
261
+ id: 'create-user-bad-active-flag',
262
+ route: 'POST /SASjsApi/user',
263
+ description: 'refuses an isActive the schema does not call a boolean',
264
+ identity: exports.ADMIN_SIGNED_IN,
265
+ request: {
266
+ token: ADMIN,
267
+ body: {
268
+ username: 'flaguser',
269
+ displayName: 'Flag User',
270
+ password: 'password',
271
+ isActive: 'sometimes'
272
+ }
273
+ },
274
+ expect: { status: 400, error: '"isActive" must be a boolean' }
275
+ },
276
+ {
277
+ id: 'create-user-not-admin-incomplete',
278
+ route: 'POST /SASjsApi/user',
279
+ description: 'refuses a non-admin before it reads the body it sent',
280
+ identity: exports.ADMIN_SIGNED_IN,
281
+ request: {
282
+ token: RESTRICTED,
283
+ body: { username: 'incomplete' }
284
+ },
285
+ expect: { status: 401, error: 'Admin account required' }
286
+ },
225
287
  {
226
288
  id: 'update-user',
227
289
  route: 'PATCH /SASjsApi/user/{uid}',
@@ -249,14 +311,49 @@ exports.RECORD_CORPUS = [
249
311
  request: {
250
312
  token: RESTRICTED,
251
313
  params: { uid: ADMIN_UID },
252
- body: {
253
- displayName: 'Hijacked',
254
- username: 'sasjsadmin',
255
- password: 'Orion123'
256
- }
314
+ // the body is one the schema would refuse too, so the case only passes when
315
+ // the caller is gated before the body is read, as the middleware order has it
316
+ body: { isAdmin: 'yes' }
257
317
  },
258
318
  expect: { status: 401, error: 'Admin account required' }
259
319
  },
320
+ {
321
+ id: 'update-user-empty-body',
322
+ route: 'PATCH /SASjsApi/user/{uid}',
323
+ description: 'applies an update that omits every field, which the controller stores as an empty name',
324
+ identity: exports.ADMIN_SIGNED_IN,
325
+ request: { token: ADMIN, params: { uid: RESTRICTED_UID }, body: {} },
326
+ // the controller always puts the sanitised display name into the update, so an
327
+ // omitted one is written as the empty string rather than left as it was
328
+ expect: {
329
+ status: 200,
330
+ partial: { uid: RESTRICTED_UID, displayName: '' }
331
+ }
332
+ },
333
+ {
334
+ id: 'update-user-self-admin-flag',
335
+ route: 'PATCH /SASjsApi/user/{uid}',
336
+ description: "refuses a flag only an administrator may send, on the caller's own account",
337
+ identity: exports.ADMIN_SIGNED_IN,
338
+ request: {
339
+ token: RESTRICTED,
340
+ params: { uid: RESTRICTED_UID },
341
+ body: { isAdmin: true }
342
+ },
343
+ expect: { status: 400, error: '"isAdmin" is not allowed' }
344
+ },
345
+ {
346
+ id: 'update-user-by-username-self-admin-flag',
347
+ route: 'PATCH /SASjsApi/user/by/username/{username}',
348
+ description: 'refuses a flag only an administrator may send, by username',
349
+ identity: exports.ADMIN_SIGNED_IN,
350
+ request: {
351
+ token: RESTRICTED,
352
+ params: { username: 'sasjsuser' },
353
+ body: { isAdmin: true }
354
+ },
355
+ expect: { status: 400, error: '"isAdmin" is not allowed' }
356
+ },
260
357
  {
261
358
  id: 'update-user-missing',
262
359
  route: 'PATCH /SASjsApi/user/{uid}',
@@ -329,14 +426,57 @@ exports.RECORD_CORPUS = [
329
426
  request: {
330
427
  token: RESTRICTED,
331
428
  params: { username: 'sasjsadmin' },
332
- body: {
333
- displayName: 'Hijacked',
334
- username: 'sasjsadmin',
335
- password: 'Orion123'
336
- }
429
+ // a body the schema would refuse for this caller, so the case only passes
430
+ // when the caller is gated before the body is read
431
+ body: { isAdmin: 'yes' }
337
432
  },
338
433
  expect: { status: 401, error: 'Admin account required' }
339
434
  },
435
+ {
436
+ id: 'update-user-by-username-mixed-case',
437
+ route: 'PATCH /SASjsApi/user/by/username/{username}',
438
+ description: 'finds the account when the path names it in another case',
439
+ identity: exports.ADMIN_SIGNED_IN,
440
+ request: {
441
+ token: ADMIN,
442
+ params: { username: 'SASJSUSER' },
443
+ body: { displayName: 'Renamed User' }
444
+ },
445
+ expect: {
446
+ status: 200,
447
+ partial: { uid: RESTRICTED_UID, displayName: 'Renamed User' }
448
+ }
449
+ },
450
+ {
451
+ id: 'update-user-by-username-parameter-before-body',
452
+ route: 'PATCH /SASjsApi/user/by/username/{username}',
453
+ description: 'refuses the path parameter before the body it is sent with',
454
+ identity: exports.ADMIN_SIGNED_IN,
455
+ request: {
456
+ token: ADMIN,
457
+ params: { username: 'a-b' },
458
+ body: { displayName: 'x' }
459
+ },
460
+ expect: {
461
+ status: 400,
462
+ error: '"username" must only contain alpha-numeric characters'
463
+ }
464
+ },
465
+ {
466
+ id: 'update-user-by-username-refused-name',
467
+ route: 'PATCH /SASjsApi/user/by/username/{username}',
468
+ description: 'refuses a path parameter the username schema does not allow',
469
+ identity: exports.ADMIN_SIGNED_IN,
470
+ request: {
471
+ token: ADMIN,
472
+ params: { username: 'a-b' },
473
+ body: { displayName: 'Renamed User' }
474
+ },
475
+ expect: {
476
+ status: 400,
477
+ error: '"username" must only contain alpha-numeric characters'
478
+ }
479
+ },
340
480
  {
341
481
  id: 'update-user-by-username-missing',
342
482
  route: 'PATCH /SASjsApi/user/by/username/{username}',
@@ -396,6 +536,18 @@ exports.RECORD_CORPUS = [
396
536
  request: { token: RESTRICTED, params: { uid: ADMIN_UID }, body: {} },
397
537
  expect: { status: 401, error: 'Admin account required' }
398
538
  },
539
+ {
540
+ id: 'delete-user-not-admin-no-password',
541
+ route: 'DELETE /SASjsApi/user/{uid}',
542
+ description: "requires the caller's own password when it is not an admin",
543
+ identity: exports.ADMIN_SIGNED_IN,
544
+ request: {
545
+ token: RESTRICTED,
546
+ params: { uid: RESTRICTED_UID },
547
+ body: {}
548
+ },
549
+ expect: { status: 400, error: '"password" is required' }
550
+ },
399
551
  {
400
552
  id: 'delete-user-missing',
401
553
  route: 'DELETE /SASjsApi/user/{uid}',
@@ -416,6 +568,72 @@ exports.RECORD_CORPUS = [
416
568
  },
417
569
  expect: { status: 200, body: 'Account Deleted!' }
418
570
  },
571
+ {
572
+ id: 'delete-user-admin-bodys-refused',
573
+ route: 'DELETE /SASjsApi/user/by/username/{username}',
574
+ description: "refuses a body an administrator's deletion takes none of",
575
+ identity: exports.ADMIN_SIGNED_IN,
576
+ request: {
577
+ token: ADMIN,
578
+ params: { username: 'sasjsuser' },
579
+ body: { password: 'Orion123' }
580
+ },
581
+ expect: { status: 400, error: '"password" is not allowed' }
582
+ },
583
+ {
584
+ id: 'delete-user-by-username-extra-key',
585
+ route: 'DELETE /SASjsApi/user/by/username/{username}',
586
+ description: 'refuses a key outside the password a self-deletion carries',
587
+ identity: exports.ADMIN_SIGNED_IN,
588
+ request: {
589
+ token: RESTRICTED,
590
+ params: { username: 'sasjsuser' },
591
+ body: { password: 'Orion123', extra: 1 }
592
+ },
593
+ expect: { status: 400, error: '"extra" is not allowed' }
594
+ },
595
+ {
596
+ id: 'delete-user-by-username-parameter-before-body',
597
+ route: 'DELETE /SASjsApi/user/by/username/{username}',
598
+ description: 'refuses the path parameter before the body it is sent with',
599
+ identity: exports.ADMIN_SIGNED_IN,
600
+ request: {
601
+ token: ADMIN,
602
+ params: { username: 'a-b' },
603
+ body: { password: 'Orion123' }
604
+ },
605
+ expect: {
606
+ status: 400,
607
+ error: '"username" must only contain alpha-numeric characters'
608
+ }
609
+ },
610
+ {
611
+ id: 'delete-user-by-username-short-password',
612
+ route: 'DELETE /SASjsApi/user/by/username/{username}',
613
+ description: 'refuses a password shorter than the schema allows, uncompared',
614
+ identity: exports.ADMIN_SIGNED_IN,
615
+ request: {
616
+ token: RESTRICTED,
617
+ params: { username: 'sasjsuser' },
618
+ body: { password: 'abc' }
619
+ },
620
+ expect: {
621
+ status: 400,
622
+ error: '"password" length must be at least 6 characters long'
623
+ }
624
+ },
625
+ {
626
+ id: 'delete-user-by-username-no-password',
627
+ route: 'DELETE /SASjsApi/user/by/username/{username}',
628
+ description: "requires the caller's own password for a self-deletion",
629
+ identity: exports.ADMIN_SIGNED_IN,
630
+ request: {
631
+ token: RESTRICTED,
632
+ params: { username: 'sasjsuser' },
633
+ body: {}
634
+ },
635
+ expect: { status: 400, error: '"password" is required' }
636
+ },
419
637
  {
420
638
  id: 'delete-user-by-username-wrong-password',
421
639
  route: 'DELETE /SASjsApi/user/by/username/{username}',
@@ -547,6 +765,42 @@ exports.RECORD_CORPUS = [
547
765
  request: { token: ADMIN, body: { name: 'DCGroup', description: 'again' } },
548
766
  expect: { status: 409, error: 'Group name already exists.' }
549
767
  },
768
+ {
769
+ id: 'create-group-empty-description',
770
+ route: 'POST /SASjsApi/group',
771
+ description: 'refuses an empty description, which the schema does not allow',
772
+ identity: exports.ADMIN_SIGNED_IN,
773
+ request: {
774
+ token: ADMIN,
775
+ body: { name: 'EmptyDescription', description: '' }
776
+ },
777
+ expect: {
778
+ status: 400,
779
+ error: '"description" is not allowed to be empty'
780
+ }
781
+ },
782
+ {
783
+ id: 'create-group-no-description',
784
+ route: 'POST /SASjsApi/group',
785
+ description: 'creates a group whose description the caller left out',
786
+ identity: exports.ADMIN_SIGNED_IN,
787
+ request: { token: ADMIN, body: { name: 'NoDescription' } },
788
+ expect: {
789
+ status: 200,
790
+ partial: { name: 'NoDescription', description: 'Group description.' }
791
+ }
792
+ },
793
+ {
794
+ id: 'create-group-bad-active-flag',
795
+ route: 'POST /SASjsApi/group',
796
+ description: 'refuses an isActive the schema does not call a boolean',
797
+ identity: exports.ADMIN_SIGNED_IN,
798
+ request: {
799
+ token: ADMIN,
800
+ body: { name: 'FlagGroup', description: 'a group', isActive: 'yes' }
801
+ },
802
+ expect: { status: 400, error: '"isActive" must be a boolean' }
803
+ },
550
804
  {
551
805
  id: 'add-user-to-group',
552
806
  route: 'POST /SASjsApi/group/{groupUid}/{userUid}',
@@ -957,16 +1211,9 @@ exports.RECORD_CORPUS = [
957
1211
  route: 'POST /SASjsApi/permission',
958
1212
  description: 'refuses a creation by a non-administrator',
959
1213
  identity: exports.ADMIN_SIGNED_IN,
960
- request: {
961
- token: RESTRICTED,
962
- body: {
963
- path: '/SASjsApi/drive/folder',
964
- type: 'Route',
965
- setting: 'Grant',
966
- principalType: 'user',
967
- principalId: RESTRICTED_UID
968
- }
969
- },
1214
+ // an empty body, which the document requires five fields of, so the case only
1215
+ // passes when the caller is refused before the schema is consulted
1216
+ request: { token: RESTRICTED, body: {} },
970
1217
  expect: { status: 401, error: 'Admin account required' }
971
1218
  },
972
1219
  {
@@ -1043,11 +1290,8 @@ exports.RECORD_CORPUS = [
1043
1290
  route: 'PATCH /SASjsApi/permission/{uid}',
1044
1291
  description: 'refuses a change by a non-administrator',
1045
1292
  identity: exports.ADMIN_SIGNED_IN,
1046
- request: {
1047
- token: RESTRICTED,
1048
- params: { uid: 'rule-code' },
1049
- body: { setting: 'Grant' }
1050
- },
1293
+ // `setting` is required, so an empty body only reaches 401 when the gate runs first
1294
+ request: { token: RESTRICTED, params: { uid: 'rule-code' }, body: {} },
1051
1295
  expect: { status: 401, error: 'Admin account required' }
1052
1296
  },
1053
1297
  {
@@ -1167,15 +1411,9 @@ exports.RECORD_CORPUS = [
1167
1411
  route: 'POST /SASjsApi/client',
1168
1412
  description: 'refuses a registration by a non-administrator',
1169
1413
  identity: exports.ADMIN_SIGNED_IN,
1170
- request: {
1171
- token: RESTRICTED,
1172
- body: {
1173
- clientId: 'new_app',
1174
- clientSecret: 'new_secret',
1175
- accessTokenExpiration: 3600,
1176
- refreshTokenExpiration: 86400
1177
- }
1178
- },
1414
+ // the document requires `clientId` here, so an empty body would be refused
1415
+ // first by a host that validated before it gated
1416
+ request: { token: RESTRICTED, body: {} },
1179
1417
  expect: { status: 401, error: 'Admin account required' }
1180
1418
  },
1181
1419
  {