@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.
package/build/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- /* @sasjs/api 0.44.3 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
1
+ /* @sasjs/api 0.44.5 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
2
2
  "use strict";
3
3
  var SASjsApi = (() => {
4
4
  var __defProp = Object.defineProperty;
@@ -2224,7 +2224,7 @@ var SASjsApi = (() => {
2224
2224
  {
2225
2225
  name: "description",
2226
2226
  in: "body",
2227
- required: true,
2227
+ required: false,
2228
2228
  type: "string"
2229
2229
  },
2230
2230
  {
@@ -2240,6 +2240,10 @@ var SASjsApi = (() => {
2240
2240
  status: 200,
2241
2241
  description: "Ok"
2242
2242
  },
2243
+ {
2244
+ status: 400,
2245
+ description: 'A body the schema refuses, e.g. `"isActive" must be a boolean`.'
2246
+ },
2243
2247
  {
2244
2248
  status: 401,
2245
2249
  description: "Admin account required"
@@ -2938,6 +2942,10 @@ var SASjsApi = (() => {
2938
2942
  status: 200,
2939
2943
  description: "Ok"
2940
2944
  },
2945
+ {
2946
+ status: 400,
2947
+ description: 'A body the schema refuses, e.g. `"isAdmin" must be a boolean`.'
2948
+ },
2941
2949
  {
2942
2950
  status: 401,
2943
2951
  description: "Admin account required"
@@ -2974,6 +2982,10 @@ var SASjsApi = (() => {
2974
2982
  status: 200,
2975
2983
  description: "Account Deleted!"
2976
2984
  },
2985
+ {
2986
+ status: 400,
2987
+ description: 'A password shorter than six characters, or a key the deletion takes none of; e.g. `"password" is required`'
2988
+ },
2977
2989
  {
2978
2990
  status: 401,
2979
2991
  description: "Admin account required, or invalid password"
@@ -3030,19 +3042,19 @@ var SASjsApi = (() => {
3030
3042
  {
3031
3043
  name: "displayName",
3032
3044
  in: "body",
3033
- required: true,
3045
+ required: false,
3034
3046
  type: "string"
3035
3047
  },
3036
3048
  {
3037
3049
  name: "username",
3038
3050
  in: "body",
3039
- required: true,
3051
+ required: false,
3040
3052
  type: "string"
3041
3053
  },
3042
3054
  {
3043
3055
  name: "password",
3044
3056
  in: "body",
3045
- required: true,
3057
+ required: false,
3046
3058
  type: "string"
3047
3059
  },
3048
3060
  {
@@ -3070,6 +3082,10 @@ var SASjsApi = (() => {
3070
3082
  status: 200,
3071
3083
  description: "Ok"
3072
3084
  },
3085
+ {
3086
+ status: 400,
3087
+ description: 'A body the schema refuses, e.g. `"isAdmin" must be a boolean`.'
3088
+ },
3073
3089
  {
3074
3090
  status: 401,
3075
3091
  description: "Admin account required"
@@ -3114,6 +3130,10 @@ var SASjsApi = (() => {
3114
3130
  status: 200,
3115
3131
  description: "Account Deleted!"
3116
3132
  },
3133
+ {
3134
+ status: 400,
3135
+ description: 'A username the schema refuses, a password shorter than six characters, or a key an administrator\'s deletion takes none of; e.g. `"password" is required`'
3136
+ },
3117
3137
  {
3118
3138
  status: 401,
3119
3139
  description: "Admin account required, or invalid password"
@@ -3144,6 +3164,10 @@ var SASjsApi = (() => {
3144
3164
  status: 200,
3145
3165
  description: "Ok"
3146
3166
  },
3167
+ {
3168
+ status: 400,
3169
+ description: 'A username the schema refuses, e.g. `"username" must only contain alpha-numeric characters`'
3170
+ },
3147
3171
  {
3148
3172
  status: 401,
3149
3173
  description: "Unauthorized"
@@ -3170,19 +3194,19 @@ var SASjsApi = (() => {
3170
3194
  {
3171
3195
  name: "displayName",
3172
3196
  in: "body",
3173
- required: true,
3197
+ required: false,
3174
3198
  type: "string"
3175
3199
  },
3176
3200
  {
3177
3201
  name: "username",
3178
3202
  in: "body",
3179
- required: true,
3203
+ required: false,
3180
3204
  type: "string"
3181
3205
  },
3182
3206
  {
3183
3207
  name: "password",
3184
3208
  in: "body",
3185
- required: true,
3209
+ required: false,
3186
3210
  type: "string"
3187
3211
  },
3188
3212
  {
@@ -3210,6 +3234,10 @@ var SASjsApi = (() => {
3210
3234
  status: 200,
3211
3235
  description: "Ok"
3212
3236
  },
3237
+ {
3238
+ status: 400,
3239
+ description: 'A body the schema refuses, e.g. `"isAdmin" must be a boolean`.'
3240
+ },
3213
3241
  {
3214
3242
  status: 401,
3215
3243
  description: "Admin account required"
@@ -6790,11 +6818,155 @@ var SASjsApi = (() => {
6790
6818
  }
6791
6819
  };
6792
6820
  var APP_ENTRY_FILE = "index.html";
6793
- var flagOf = (value) => {
6821
+ var refused = (message) => new ApiError(400, message);
6822
+ var stringField = (field, value, allowEmpty = false) => {
6823
+ if (typeof value !== "string") throw refused(`"${field}" must be a string`);
6824
+ if (value === "" && !allowEmpty)
6825
+ throw refused(`"${field}" is not allowed to be empty`);
6826
+ return value;
6827
+ };
6828
+ var requiredField = (field, value) => {
6829
+ if (value === void 0) throw refused(`"${field}" is required`);
6830
+ return stringField(field, value);
6831
+ };
6832
+ var alphanumeric = (field, value, min, max) => {
6833
+ if (!/^[A-Za-z0-9]+$/.test(value))
6834
+ throw refused(`"${field}" must only contain alpha-numeric characters`);
6835
+ if (value.length < min)
6836
+ throw refused(`"${field}" length must be at least ${min} characters long`);
6837
+ if (value.length > max)
6838
+ throw refused(
6839
+ `"${field}" length must be less than or equal to ${max} characters long`
6840
+ );
6841
+ return value;
6842
+ };
6843
+ var lengthBetween = (field, value, min, max) => {
6844
+ if (value.length < min)
6845
+ throw refused(`"${field}" length must be at least ${min} characters long`);
6846
+ if (value.length > max)
6847
+ throw refused(
6848
+ `"${field}" length must be less than or equal to ${max} characters long`
6849
+ );
6850
+ return value;
6851
+ };
6852
+ var trimmedName = (field, value) => {
6853
+ const name = value.trim();
6854
+ if (name === "") throw refused(`"${field}" is not allowed to be empty`);
6855
+ if (name.length < 6)
6856
+ throw refused(`"${field}" length must be at least 6 characters long`);
6857
+ return name;
6858
+ };
6859
+ var refuseUnknown = (body, keys) => {
6860
+ for (const key of Object.keys(body))
6861
+ if (!keys.includes(key)) throw refused(`"${key}" is not allowed`);
6862
+ };
6863
+ var ADMIN_GATED_ROUTES = /* @__PURE__ */ new Set([
6864
+ "POST /SASjsApi/permission",
6865
+ "PATCH /SASjsApi/permission/{uid}",
6866
+ "DELETE /SASjsApi/permission/{uid}",
6867
+ "GET /SASjsApi/client",
6868
+ "POST /SASjsApi/client"
6869
+ ]);
6870
+ var foldedUsername = (value) => alphanumeric(
6871
+ "username",
6872
+ requiredField("username", value).toLowerCase(),
6873
+ 3,
6874
+ 16
6875
+ );
6876
+ var deletionBody = (body, admin) => {
6877
+ if (admin) {
6878
+ for (const key of Object.keys(body))
6879
+ throw refused(`"${key}" is not allowed`);
6880
+ return {};
6881
+ }
6882
+ const password = lengthBetween(
6883
+ "password",
6884
+ requiredField("password", body.password),
6885
+ 6,
6886
+ 1024
6887
+ );
6888
+ for (const key of Object.keys(body))
6889
+ if (key !== "password") throw refused(`"${key}" is not allowed`);
6890
+ return { password };
6891
+ };
6892
+ var USER_KEYS = [
6893
+ "displayName",
6894
+ "username",
6895
+ "password",
6896
+ "isAdmin",
6897
+ "isActive",
6898
+ "autoExec"
6899
+ ];
6900
+ var userCreate = (body) => {
6901
+ const displayName = trimmedName(
6902
+ "displayName",
6903
+ requiredField("displayName", body.displayName)
6904
+ );
6905
+ const username = alphanumeric(
6906
+ "username",
6907
+ requiredField("username", body.username).toLowerCase(),
6908
+ 3,
6909
+ 16
6910
+ );
6911
+ const password = lengthBetween(
6912
+ "password",
6913
+ requiredField("password", body.password),
6914
+ 6,
6915
+ 1024
6916
+ );
6917
+ const isAdmin = booleanOf(body.isAdmin, "isAdmin");
6918
+ const isActive = booleanOf(body.isActive, "isActive");
6919
+ const autoExec = body.autoExec === void 0 ? void 0 : stringField("autoExec", body.autoExec, true);
6920
+ refuseUnknown(body, USER_KEYS);
6921
+ return { displayName, username, password, isAdmin, isActive, autoExec };
6922
+ };
6923
+ var GROUP_CREATE_KEYS = ["name", "description", "isActive"];
6924
+ var groupCreate = (body) => {
6925
+ const name = alphanumeric("name", requiredField("name", body.name), 3, 16);
6926
+ const description = body.description === void 0 ? void 0 : stringField("description", body.description);
6927
+ const isActive = booleanOf(body.isActive, "isActive");
6928
+ refuseUnknown(body, GROUP_CREATE_KEYS);
6929
+ return { name, description, isActive };
6930
+ };
6931
+ var userUpdate = (body, admin) => {
6932
+ const changes = { ...body };
6933
+ if (changes.displayName !== void 0)
6934
+ changes.displayName = trimmedName(
6935
+ "displayName",
6936
+ stringField("displayName", changes.displayName)
6937
+ );
6938
+ if (changes.username !== void 0)
6939
+ changes.username = alphanumeric(
6940
+ "username",
6941
+ stringField("username", changes.username).toLowerCase(),
6942
+ 3,
6943
+ 16
6944
+ );
6945
+ if (changes.password !== void 0)
6946
+ lengthBetween(
6947
+ "password",
6948
+ stringField("password", changes.password),
6949
+ 6,
6950
+ 1024
6951
+ );
6952
+ if (changes.autoExec !== void 0)
6953
+ stringField("autoExec", changes.autoExec, true);
6954
+ const declared = admin ? USER_KEYS : USER_KEYS.filter((key) => key !== "isAdmin" && key !== "isActive");
6955
+ for (const field of ["isAdmin", "isActive"])
6956
+ if (admin && field in changes)
6957
+ changes[field] = booleanOf(changes[field], field);
6958
+ refuseUnknown(changes, declared);
6959
+ return changes;
6960
+ };
6961
+ var booleanOf = (value, field) => {
6962
+ if (value === void 0) return void 0;
6794
6963
  if (typeof value === "boolean") return value;
6795
- if (value === "true") return true;
6796
- if (value === "false") return false;
6797
- return void 0;
6964
+ if (typeof value === "string") {
6965
+ const text2 = value.trim().toLowerCase();
6966
+ if (text2 === "true") return true;
6967
+ if (text2 === "false") return false;
6968
+ }
6969
+ throw new ApiError(400, `"${field}" must be a boolean`);
6798
6970
  };
6799
6971
  var APP_NOT_REGISTERED = "No App Stream is registered with that id.";
6800
6972
  var appNotRegistered = () => new ApiError(404, APP_NOT_REGISTERED, {
@@ -6870,7 +7042,6 @@ var SASjsApi = (() => {
6870
7042
  if (grantScoped && records && !publicGrant && !await records.mayUseRoute(callerSubject, grantScoped))
6871
7043
  throw new ApiError(401, "Unauthorized");
6872
7044
  }
6873
- validate(route, request);
6874
7045
  const query = request.query || {};
6875
7046
  const body = request.body || {};
6876
7047
  const params = request.params || {};
@@ -6902,6 +7073,20 @@ var SASjsApi = (() => {
6902
7073
  status: 200,
6903
7074
  contents: output.contents
6904
7075
  });
7076
+ const callerRecord = async () => {
7077
+ const recordsService = required();
7078
+ const subject2 = await caller();
7079
+ return recordsService.getUser(subject2, {
7080
+ uid: String(subject2?.userId ?? "")
7081
+ });
7082
+ };
7083
+ const verifyAdminIfNeeded = async (target) => {
7084
+ const me = await callerRecord();
7085
+ if (me.isAdmin) return true;
7086
+ const ownAccount = target.uid !== void 0 && target.uid === me.uid || target.username !== void 0 && target.username === me.username;
7087
+ if (!ownAccount) throw new ApiError(401, "Admin account required");
7088
+ return false;
7089
+ };
6905
7090
  const required = () => {
6906
7091
  if (!records)
6907
7092
  throw new ApiError(
@@ -6910,6 +7095,51 @@ var SASjsApi = (() => {
6910
7095
  );
6911
7096
  return records;
6912
7097
  };
7098
+ const controllerRules = {
7099
+ "POST /SASjsApi/user": async (request2) => {
7100
+ if (!(await callerRecord()).isAdmin)
7101
+ throw new ApiError(401, "Admin account required");
7102
+ return { body: userCreate(request2.body || {}) };
7103
+ },
7104
+ "POST /SASjsApi/group": async (request2) => {
7105
+ if (!(await callerRecord()).isAdmin)
7106
+ throw new ApiError(401, "Admin account required");
7107
+ return { body: groupCreate(request2.body || {}) };
7108
+ },
7109
+ "PATCH /SASjsApi/user/{uid}": async (request2) => {
7110
+ const admin = await verifyAdminIfNeeded({
7111
+ uid: String(request2.params?.uid ?? "")
7112
+ });
7113
+ return { body: userUpdate(request2.body || {}, admin) };
7114
+ },
7115
+ "PATCH /SASjsApi/user/by/username/{username}": async (request2) => {
7116
+ const admin = await verifyAdminIfNeeded({
7117
+ username: String(request2.params?.username ?? "")
7118
+ });
7119
+ const username = foldedUsername(request2.params?.username);
7120
+ return { body: userUpdate(request2.body || {}, admin), username };
7121
+ },
7122
+ "DELETE /SASjsApi/user/by/username/{username}": async (request2) => {
7123
+ const admin = await verifyAdminIfNeeded({
7124
+ username: String(request2.params?.username ?? "")
7125
+ });
7126
+ const username = foldedUsername(request2.params?.username);
7127
+ return { body: deletionBody(request2.body || {}, admin), username };
7128
+ },
7129
+ "DELETE /SASjsApi/user/{uid}": async (request2) => {
7130
+ const admin = await verifyAdminIfNeeded({
7131
+ uid: String(request2.params?.uid ?? "")
7132
+ });
7133
+ return { body: deletionBody(request2.body || {}, admin) };
7134
+ }
7135
+ };
7136
+ const controllerRule = controllerRules[routeId];
7137
+ const controllerAnswer = controllerRule ? await controllerRule(request) : void 0;
7138
+ if (!controllerRule) {
7139
+ if (ADMIN_GATED_ROUTES.has(routeId) && !(await callerRecord()).isAdmin)
7140
+ throw new ApiError(401, "Admin account required");
7141
+ validate(route, request);
7142
+ }
6913
7143
  if (routeId.startsWith("POST /SASjsApi/auth/") || routeId.startsWith("POST /SASLogon/") || routeId === "GET /SASLogon/logout" || routeId === "GET /SASjsApi/session") {
6914
7144
  if (!identity)
6915
7145
  throw new ApiError(
@@ -7340,20 +7570,16 @@ var SASjsApi = (() => {
7340
7570
  return {
7341
7571
  status: 200,
7342
7572
  body: await required().getUser(await caller(), {
7343
- username: String(params.username ?? "")
7573
+ username: foldedUsername(params.username)
7344
7574
  })
7345
7575
  };
7346
7576
  case "POST /SASjsApi/user":
7347
7577
  return {
7348
7578
  status: 200,
7349
- body: await required().createUser(await caller(), {
7350
- username: String(body.username ?? ""),
7351
- displayName: String(body.displayName ?? ""),
7352
- password: String(body.password ?? ""),
7353
- isAdmin: body.isAdmin,
7354
- isActive: body.isActive,
7355
- autoExec: body.autoExec
7356
- })
7579
+ body: await required().createUser(
7580
+ await caller(),
7581
+ controllerAnswer.body
7582
+ )
7357
7583
  };
7358
7584
  case "PATCH /SASjsApi/user/{uid}":
7359
7585
  return {
@@ -7361,7 +7587,9 @@ var SASjsApi = (() => {
7361
7587
  body: await required().updateUser(
7362
7588
  await caller(),
7363
7589
  { uid: String(params.uid ?? "") },
7364
- body
7590
+ // the body the controller's own schema accepted, with what Joi converts
7591
+ // already converted
7592
+ controllerAnswer.body
7365
7593
  )
7366
7594
  };
7367
7595
  case "PATCH /SASjsApi/user/by/username/{username}":
@@ -7369,8 +7597,8 @@ var SASjsApi = (() => {
7369
7597
  status: 200,
7370
7598
  body: await required().updateUser(
7371
7599
  await caller(),
7372
- { username: String(params.username ?? "") },
7373
- body
7600
+ { username: controllerAnswer.username ?? "" },
7601
+ controllerAnswer.body
7374
7602
  )
7375
7603
  };
7376
7604
  case "DELETE /SASjsApi/user/{uid}":
@@ -7379,7 +7607,7 @@ var SASjsApi = (() => {
7379
7607
  body: await required().deleteUser(
7380
7608
  await caller(),
7381
7609
  { uid: String(params.uid ?? "") },
7382
- { password: body.password }
7610
+ { password: controllerAnswer.body.password }
7383
7611
  )
7384
7612
  };
7385
7613
  case "DELETE /SASjsApi/user/by/username/{username}":
@@ -7387,7 +7615,7 @@ var SASjsApi = (() => {
7387
7615
  status: 200,
7388
7616
  body: await required().deleteUser(
7389
7617
  await caller(),
7390
- { username: String(params.username ?? "") },
7618
+ { username: controllerAnswer.username ?? "" },
7391
7619
  { password: body.password }
7392
7620
  )
7393
7621
  };
@@ -7417,7 +7645,7 @@ var SASjsApi = (() => {
7417
7645
  filePath: body.filePath,
7418
7646
  // the body is rebuilt field by field here, so a flag the service reads
7419
7647
  // has to be named or the request's own answer is lost on the way
7420
- layout: flagOf(body.layout)
7648
+ layout: booleanOf(body.layout, "layout")
7421
7649
  })
7422
7650
  };
7423
7651
  case "GET /SASjsApi/info/authorizedRoutes":
@@ -7450,9 +7678,10 @@ var SASjsApi = (() => {
7450
7678
  return {
7451
7679
  status: 200,
7452
7680
  body: await required().createGroup(await caller(), {
7453
- name: String(body.name ?? ""),
7454
- description: String(body.description ?? ""),
7455
- isActive: body.isActive
7681
+ name: String(controllerAnswer.body.name ?? ""),
7682
+ // left absent rather than made empty: the service applies the model's default
7683
+ description: controllerAnswer.body.description,
7684
+ isActive: controllerAnswer.body.isActive
7456
7685
  })
7457
7686
  };
7458
7687
  case "POST /SASjsApi/group/{groupUid}/{userUid}":
@@ -7834,7 +8063,7 @@ var SASjsApi = (() => {
7834
8063
  throw new ApiError(409, "Username already exists.");
7835
8064
  change.username = body.username;
7836
8065
  }
7837
- if (displayName) change.displayName = displayName;
8066
+ change.displayName = displayName;
7838
8067
  if (body.isAdmin !== void 0) change.isAdmin = body.isAdmin;
7839
8068
  if (body.isActive !== void 0) change.isActive = body.isActive;
7840
8069
  if (body.autoExec !== void 0) change.autoExec = body.autoExec;
@@ -7876,7 +8105,8 @@ var SASjsApi = (() => {
7876
8105
  throw new ApiError(409, "Group name already exists.");
7877
8106
  const created = await store.createGroup({
7878
8107
  name: body.name,
7879
- description: body.description,
8108
+ // the model defaults the field, so an absent description is the model's
8109
+ description: body.description ?? "Group description.",
7880
8110
  isActive: body.isActive !== false
7881
8111
  });
7882
8112
  return groupDetails(created);
@@ -11889,6 +12119,25 @@ var SASjsApi = (() => {
11889
12119
  partial: { uid: RESTRICTED_UID, username: "sasjsuser", isAdmin: false }
11890
12120
  }
11891
12121
  },
12122
+ {
12123
+ id: "get-user-by-username-mixed-case",
12124
+ route: "GET /SASjsApi/user/by/username/{username}",
12125
+ description: "finds the account when the path names it in another case",
12126
+ identity: ADMIN_SIGNED_IN,
12127
+ request: { token: ADMIN5, params: { username: "SASJSUSER" } },
12128
+ expect: { status: 200, partial: { uid: RESTRICTED_UID } }
12129
+ },
12130
+ {
12131
+ id: "get-user-by-username-refused-name",
12132
+ route: "GET /SASjsApi/user/by/username/{username}",
12133
+ description: "refuses a path parameter the username schema does not allow",
12134
+ identity: ADMIN_SIGNED_IN,
12135
+ request: { token: ADMIN5, params: { username: "a-b" } },
12136
+ expect: {
12137
+ status: 400,
12138
+ error: '"username" must only contain alpha-numeric characters'
12139
+ }
12140
+ },
11892
12141
  {
11893
12142
  id: "get-user-by-username-unauthenticated",
11894
12143
  route: "GET /SASjsApi/user/by/username/{username}",
@@ -11968,6 +12217,49 @@ var SASjsApi = (() => {
11968
12217
  },
11969
12218
  expect: { status: 409, error: "Username already exists." }
11970
12219
  },
12220
+ {
12221
+ id: "create-user-bad-admin-flag",
12222
+ route: "POST /SASjsApi/user",
12223
+ description: "refuses an isAdmin the schema does not call a boolean",
12224
+ identity: ADMIN_SIGNED_IN,
12225
+ request: {
12226
+ token: ADMIN5,
12227
+ body: {
12228
+ username: "flaguser",
12229
+ displayName: "Flag User",
12230
+ password: "password",
12231
+ isAdmin: "yes"
12232
+ }
12233
+ },
12234
+ expect: { status: 400, error: '"isAdmin" must be a boolean' }
12235
+ },
12236
+ {
12237
+ id: "create-user-bad-active-flag",
12238
+ route: "POST /SASjsApi/user",
12239
+ description: "refuses an isActive the schema does not call a boolean",
12240
+ identity: ADMIN_SIGNED_IN,
12241
+ request: {
12242
+ token: ADMIN5,
12243
+ body: {
12244
+ username: "flaguser",
12245
+ displayName: "Flag User",
12246
+ password: "password",
12247
+ isActive: "sometimes"
12248
+ }
12249
+ },
12250
+ expect: { status: 400, error: '"isActive" must be a boolean' }
12251
+ },
12252
+ {
12253
+ id: "create-user-not-admin-incomplete",
12254
+ route: "POST /SASjsApi/user",
12255
+ description: "refuses a non-admin before it reads the body it sent",
12256
+ identity: ADMIN_SIGNED_IN,
12257
+ request: {
12258
+ token: RESTRICTED5,
12259
+ body: { username: "incomplete" }
12260
+ },
12261
+ expect: { status: 401, error: "Admin account required" }
12262
+ },
11971
12263
  {
11972
12264
  id: "update-user",
11973
12265
  route: "PATCH /SASjsApi/user/{uid}",
@@ -11995,14 +12287,49 @@ var SASjsApi = (() => {
11995
12287
  request: {
11996
12288
  token: RESTRICTED5,
11997
12289
  params: { uid: ADMIN_UID },
11998
- body: {
11999
- displayName: "Hijacked",
12000
- username: "sasjsadmin",
12001
- password: "Orion123"
12002
- }
12290
+ // the body is one the schema would refuse too, so the case only passes when
12291
+ // the caller is gated before the body is read, as the middleware order has it
12292
+ body: { isAdmin: "yes" }
12003
12293
  },
12004
12294
  expect: { status: 401, error: "Admin account required" }
12005
12295
  },
12296
+ {
12297
+ id: "update-user-empty-body",
12298
+ route: "PATCH /SASjsApi/user/{uid}",
12299
+ description: "applies an update that omits every field, which the controller stores as an empty name",
12300
+ identity: ADMIN_SIGNED_IN,
12301
+ request: { token: ADMIN5, params: { uid: RESTRICTED_UID }, body: {} },
12302
+ // the controller always puts the sanitised display name into the update, so an
12303
+ // omitted one is written as the empty string rather than left as it was
12304
+ expect: {
12305
+ status: 200,
12306
+ partial: { uid: RESTRICTED_UID, displayName: "" }
12307
+ }
12308
+ },
12309
+ {
12310
+ id: "update-user-self-admin-flag",
12311
+ route: "PATCH /SASjsApi/user/{uid}",
12312
+ description: "refuses a flag only an administrator may send, on the caller's own account",
12313
+ identity: ADMIN_SIGNED_IN,
12314
+ request: {
12315
+ token: RESTRICTED5,
12316
+ params: { uid: RESTRICTED_UID },
12317
+ body: { isAdmin: true }
12318
+ },
12319
+ expect: { status: 400, error: '"isAdmin" is not allowed' }
12320
+ },
12321
+ {
12322
+ id: "update-user-by-username-self-admin-flag",
12323
+ route: "PATCH /SASjsApi/user/by/username/{username}",
12324
+ description: "refuses a flag only an administrator may send, by username",
12325
+ identity: ADMIN_SIGNED_IN,
12326
+ request: {
12327
+ token: RESTRICTED5,
12328
+ params: { username: "sasjsuser" },
12329
+ body: { isAdmin: true }
12330
+ },
12331
+ expect: { status: 400, error: '"isAdmin" is not allowed' }
12332
+ },
12006
12333
  {
12007
12334
  id: "update-user-missing",
12008
12335
  route: "PATCH /SASjsApi/user/{uid}",
@@ -12075,14 +12402,57 @@ var SASjsApi = (() => {
12075
12402
  request: {
12076
12403
  token: RESTRICTED5,
12077
12404
  params: { username: "sasjsadmin" },
12078
- body: {
12079
- displayName: "Hijacked",
12080
- username: "sasjsadmin",
12081
- password: "Orion123"
12082
- }
12405
+ // a body the schema would refuse for this caller, so the case only passes
12406
+ // when the caller is gated before the body is read
12407
+ body: { isAdmin: "yes" }
12083
12408
  },
12084
12409
  expect: { status: 401, error: "Admin account required" }
12085
12410
  },
12411
+ {
12412
+ id: "update-user-by-username-mixed-case",
12413
+ route: "PATCH /SASjsApi/user/by/username/{username}",
12414
+ description: "finds the account when the path names it in another case",
12415
+ identity: ADMIN_SIGNED_IN,
12416
+ request: {
12417
+ token: ADMIN5,
12418
+ params: { username: "SASJSUSER" },
12419
+ body: { displayName: "Renamed User" }
12420
+ },
12421
+ expect: {
12422
+ status: 200,
12423
+ partial: { uid: RESTRICTED_UID, displayName: "Renamed User" }
12424
+ }
12425
+ },
12426
+ {
12427
+ id: "update-user-by-username-parameter-before-body",
12428
+ route: "PATCH /SASjsApi/user/by/username/{username}",
12429
+ description: "refuses the path parameter before the body it is sent with",
12430
+ identity: ADMIN_SIGNED_IN,
12431
+ request: {
12432
+ token: ADMIN5,
12433
+ params: { username: "a-b" },
12434
+ body: { displayName: "x" }
12435
+ },
12436
+ expect: {
12437
+ status: 400,
12438
+ error: '"username" must only contain alpha-numeric characters'
12439
+ }
12440
+ },
12441
+ {
12442
+ id: "update-user-by-username-refused-name",
12443
+ route: "PATCH /SASjsApi/user/by/username/{username}",
12444
+ description: "refuses a path parameter the username schema does not allow",
12445
+ identity: ADMIN_SIGNED_IN,
12446
+ request: {
12447
+ token: ADMIN5,
12448
+ params: { username: "a-b" },
12449
+ body: { displayName: "Renamed User" }
12450
+ },
12451
+ expect: {
12452
+ status: 400,
12453
+ error: '"username" must only contain alpha-numeric characters'
12454
+ }
12455
+ },
12086
12456
  {
12087
12457
  id: "update-user-by-username-missing",
12088
12458
  route: "PATCH /SASjsApi/user/by/username/{username}",
@@ -12142,6 +12512,18 @@ var SASjsApi = (() => {
12142
12512
  request: { token: RESTRICTED5, params: { uid: ADMIN_UID }, body: {} },
12143
12513
  expect: { status: 401, error: "Admin account required" }
12144
12514
  },
12515
+ {
12516
+ id: "delete-user-not-admin-no-password",
12517
+ route: "DELETE /SASjsApi/user/{uid}",
12518
+ description: "requires the caller's own password when it is not an admin",
12519
+ identity: ADMIN_SIGNED_IN,
12520
+ request: {
12521
+ token: RESTRICTED5,
12522
+ params: { uid: RESTRICTED_UID },
12523
+ body: {}
12524
+ },
12525
+ expect: { status: 400, error: '"password" is required' }
12526
+ },
12145
12527
  {
12146
12528
  id: "delete-user-missing",
12147
12529
  route: "DELETE /SASjsApi/user/{uid}",
@@ -12162,6 +12544,72 @@ var SASjsApi = (() => {
12162
12544
  },
12163
12545
  expect: { status: 200, body: "Account Deleted!" }
12164
12546
  },
12547
+ {
12548
+ id: "delete-user-admin-bodys-refused",
12549
+ route: "DELETE /SASjsApi/user/by/username/{username}",
12550
+ description: "refuses a body an administrator's deletion takes none of",
12551
+ identity: ADMIN_SIGNED_IN,
12552
+ request: {
12553
+ token: ADMIN5,
12554
+ params: { username: "sasjsuser" },
12555
+ body: { password: "Orion123" }
12556
+ },
12557
+ expect: { status: 400, error: '"password" is not allowed' }
12558
+ },
12559
+ {
12560
+ id: "delete-user-by-username-extra-key",
12561
+ route: "DELETE /SASjsApi/user/by/username/{username}",
12562
+ description: "refuses a key outside the password a self-deletion carries",
12563
+ identity: ADMIN_SIGNED_IN,
12564
+ request: {
12565
+ token: RESTRICTED5,
12566
+ params: { username: "sasjsuser" },
12567
+ body: { password: "Orion123", extra: 1 }
12568
+ },
12569
+ expect: { status: 400, error: '"extra" is not allowed' }
12570
+ },
12571
+ {
12572
+ id: "delete-user-by-username-parameter-before-body",
12573
+ route: "DELETE /SASjsApi/user/by/username/{username}",
12574
+ description: "refuses the path parameter before the body it is sent with",
12575
+ identity: ADMIN_SIGNED_IN,
12576
+ request: {
12577
+ token: ADMIN5,
12578
+ params: { username: "a-b" },
12579
+ body: { password: "Orion123" }
12580
+ },
12581
+ expect: {
12582
+ status: 400,
12583
+ error: '"username" must only contain alpha-numeric characters'
12584
+ }
12585
+ },
12586
+ {
12587
+ id: "delete-user-by-username-short-password",
12588
+ route: "DELETE /SASjsApi/user/by/username/{username}",
12589
+ description: "refuses a password shorter than the schema allows, uncompared",
12590
+ identity: ADMIN_SIGNED_IN,
12591
+ request: {
12592
+ token: RESTRICTED5,
12593
+ params: { username: "sasjsuser" },
12594
+ body: { password: "abc" }
12595
+ },
12596
+ expect: {
12597
+ status: 400,
12598
+ error: '"password" length must be at least 6 characters long'
12599
+ }
12600
+ },
12601
+ {
12602
+ id: "delete-user-by-username-no-password",
12603
+ route: "DELETE /SASjsApi/user/by/username/{username}",
12604
+ description: "requires the caller's own password for a self-deletion",
12605
+ identity: ADMIN_SIGNED_IN,
12606
+ request: {
12607
+ token: RESTRICTED5,
12608
+ params: { username: "sasjsuser" },
12609
+ body: {}
12610
+ },
12611
+ expect: { status: 400, error: '"password" is required' }
12612
+ },
12165
12613
  {
12166
12614
  id: "delete-user-by-username-wrong-password",
12167
12615
  route: "DELETE /SASjsApi/user/by/username/{username}",
@@ -12293,6 +12741,42 @@ var SASjsApi = (() => {
12293
12741
  request: { token: ADMIN5, body: { name: "DCGroup", description: "again" } },
12294
12742
  expect: { status: 409, error: "Group name already exists." }
12295
12743
  },
12744
+ {
12745
+ id: "create-group-empty-description",
12746
+ route: "POST /SASjsApi/group",
12747
+ description: "refuses an empty description, which the schema does not allow",
12748
+ identity: ADMIN_SIGNED_IN,
12749
+ request: {
12750
+ token: ADMIN5,
12751
+ body: { name: "EmptyDescription", description: "" }
12752
+ },
12753
+ expect: {
12754
+ status: 400,
12755
+ error: '"description" is not allowed to be empty'
12756
+ }
12757
+ },
12758
+ {
12759
+ id: "create-group-no-description",
12760
+ route: "POST /SASjsApi/group",
12761
+ description: "creates a group whose description the caller left out",
12762
+ identity: ADMIN_SIGNED_IN,
12763
+ request: { token: ADMIN5, body: { name: "NoDescription" } },
12764
+ expect: {
12765
+ status: 200,
12766
+ partial: { name: "NoDescription", description: "Group description." }
12767
+ }
12768
+ },
12769
+ {
12770
+ id: "create-group-bad-active-flag",
12771
+ route: "POST /SASjsApi/group",
12772
+ description: "refuses an isActive the schema does not call a boolean",
12773
+ identity: ADMIN_SIGNED_IN,
12774
+ request: {
12775
+ token: ADMIN5,
12776
+ body: { name: "FlagGroup", description: "a group", isActive: "yes" }
12777
+ },
12778
+ expect: { status: 400, error: '"isActive" must be a boolean' }
12779
+ },
12296
12780
  {
12297
12781
  id: "add-user-to-group",
12298
12782
  route: "POST /SASjsApi/group/{groupUid}/{userUid}",
@@ -12703,16 +13187,9 @@ var SASjsApi = (() => {
12703
13187
  route: "POST /SASjsApi/permission",
12704
13188
  description: "refuses a creation by a non-administrator",
12705
13189
  identity: ADMIN_SIGNED_IN,
12706
- request: {
12707
- token: RESTRICTED5,
12708
- body: {
12709
- path: "/SASjsApi/drive/folder",
12710
- type: "Route",
12711
- setting: "Grant",
12712
- principalType: "user",
12713
- principalId: RESTRICTED_UID
12714
- }
12715
- },
13190
+ // an empty body, which the document requires five fields of, so the case only
13191
+ // passes when the caller is refused before the schema is consulted
13192
+ request: { token: RESTRICTED5, body: {} },
12716
13193
  expect: { status: 401, error: "Admin account required" }
12717
13194
  },
12718
13195
  {
@@ -12789,11 +13266,8 @@ var SASjsApi = (() => {
12789
13266
  route: "PATCH /SASjsApi/permission/{uid}",
12790
13267
  description: "refuses a change by a non-administrator",
12791
13268
  identity: ADMIN_SIGNED_IN,
12792
- request: {
12793
- token: RESTRICTED5,
12794
- params: { uid: "rule-code" },
12795
- body: { setting: "Grant" }
12796
- },
13269
+ // `setting` is required, so an empty body only reaches 401 when the gate runs first
13270
+ request: { token: RESTRICTED5, params: { uid: "rule-code" }, body: {} },
12797
13271
  expect: { status: 401, error: "Admin account required" }
12798
13272
  },
12799
13273
  {
@@ -12913,15 +13387,9 @@ var SASjsApi = (() => {
12913
13387
  route: "POST /SASjsApi/client",
12914
13388
  description: "refuses a registration by a non-administrator",
12915
13389
  identity: ADMIN_SIGNED_IN,
12916
- request: {
12917
- token: RESTRICTED5,
12918
- body: {
12919
- clientId: "new_app",
12920
- clientSecret: "new_secret",
12921
- accessTokenExpiration: 3600,
12922
- refreshTokenExpiration: 86400
12923
- }
12924
- },
13390
+ // the document requires `clientId` here, so an empty body would be refused
13391
+ // first by a host that validated before it gated
13392
+ request: { token: RESTRICTED5, body: {} },
12925
13393
  expect: { status: 401, error: "Admin account required" }
12926
13394
  },
12927
13395
  {