@sasjs/api 0.21.0 → 0.22.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.
package/build/browser.js CHANGED
@@ -1,4 +1,4 @@
1
- /* @sasjs/api 0.21.0 - the SASjs Server API, for a service worker. https://github.com/sasjs/api */
1
+ /* @sasjs/api 0.22.0 - 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;
@@ -33,6 +33,7 @@ var SASjsApi = (() => {
33
33
  CODE_DEBUG: () => CODE_DEBUG,
34
34
  DEFAULT_GRANTABLE_ROUTES: () => DEFAULT_GRANTABLE_ROUTES,
35
35
  DEFAULT_IDENTITY: () => DEFAULT_IDENTITY,
36
+ DEFAULT_LOG_LINES: () => DEFAULT_LOG_LINES,
36
37
  DEFAULT_SESSIONS: () => DEFAULT_SESSIONS,
37
38
  DEPLOY_CORPUS: () => DEPLOY_CORPUS,
38
39
  DEPLOY_LIMITS: () => DEPLOY_LIMITS,
@@ -46,6 +47,7 @@ var SASjsApi = (() => {
46
47
  IDENTITY_CORPUS: () => IDENTITY_CORPUS,
47
48
  IDENTITY_FORMAT: () => IDENTITY_FORMAT,
48
49
  INFO_CORPUS: () => INFO_CORPUS,
50
+ MAX_LOG_LINES: () => MAX_LOG_LINES,
49
51
  MemoryAppStreamRegistry: () => MemoryAppStreamRegistry,
50
52
  MemoryDriveStore: () => MemoryDriveStore,
51
53
  MemoryIdentityStore: () => MemoryIdentityStore,
@@ -63,6 +65,10 @@ var SASjsApi = (() => {
63
65
  TOP_LEVEL_ROUTES: () => TOP_LEVEL_ROUTES,
64
66
  basename: () => basename,
65
67
  checkDeployTree: () => checkDeployTree,
68
+ checkLogFileName: () => checkLogFileName,
69
+ createAdminService: () => createAdminService,
70
+ createAuthConfigService: () => createAuthConfigService,
71
+ createDirectoryService: () => createDirectoryService,
66
72
  createDriveService: () => createDriveService,
67
73
  createHomeService: () => createHomeService,
68
74
  createIdentityService: () => createIdentityService,
@@ -80,9 +86,13 @@ var SASjsApi = (() => {
80
86
  isDeployTree: () => isDeployTree,
81
87
  isRoot: () => isRoot,
82
88
  isRouteGranted: () => isRouteGranted,
89
+ logLines: () => logLines,
83
90
  measureDeployTree: () => measureDeployTree,
91
+ normaliseAuthConfig: () => normaliseAuthConfig,
92
+ normaliseDiagnostics: () => normaliseDiagnostics,
84
93
  normaliseDrivePath: () => normaliseDrivePath,
85
94
  normaliseInfo: () => normaliseInfo,
95
+ normaliseLogFiles: () => normaliseLogFiles,
86
96
  parseIdentity: () => parseIdentity,
87
97
  routeById: () => routeById,
88
98
  runCase: () => runCase,
@@ -4578,915 +4588,1289 @@ var SASjsApi = (() => {
4578
4588
  };
4579
4589
  };
4580
4590
 
4581
- // src/identity/fixture.ts
4582
- var IDENTITY_FORMAT = 1;
4583
- var SECONDS_IN_A_DAY2 = 86400;
4584
- var DEFAULT_IDENTITY = {
4585
- format: IDENTITY_FORMAT,
4586
- users: [
4587
- {
4588
- uid: "user-admin",
4589
- username: "admin",
4590
- displayName: "Demo Admin",
4591
- // long enough to pass the API's own password rule (six characters), so a
4592
- // demo can sign in against a real server as well as a mock
4593
- password: "admin123",
4594
- isAdmin: true,
4595
- isActive: true,
4596
- needsToUpdatePassword: false
4597
- },
4598
- {
4599
- uid: "user-restricted",
4600
- username: "user2",
4601
- displayName: "Demo User",
4602
- password: "user123",
4603
- isAdmin: false,
4604
- isActive: true,
4605
- needsToUpdatePassword: false
4606
- }
4607
- ],
4608
- groups: [
4609
- {
4610
- uid: "group-data-controller",
4611
- name: "DCGroup",
4612
- description: "Data Controller users",
4613
- isActive: true,
4614
- users: ["user2"]
4615
- },
4616
- {
4617
- uid: "group-admins",
4618
- name: "Admins",
4619
- description: "Everything the API offers",
4620
- isActive: true,
4621
- users: ["admin"]
4622
- }
4623
- ],
4624
- permissions: [
4625
- {
4626
- uid: "rule-routes",
4627
- path: "/SASjsApi/drive/file",
4628
- type: "Route",
4629
- setting: "Grant",
4630
- group: "group-data-controller"
4631
- },
4632
- {
4633
- uid: "rule-execute",
4634
- path: "/SASjsApi/stp/execute",
4635
- type: "Route",
4636
- setting: "Grant",
4637
- group: "group-data-controller"
4638
- },
4639
- {
4640
- uid: "rule-code",
4641
- path: "/SASjsApi/code/execute",
4642
- type: "Route",
4643
- setting: "Deny",
4644
- user: "user-restricted"
4645
- }
4646
- ],
4647
- clients: [
4648
- {
4649
- clientId: "web_app",
4650
- clientSecret: "web_app",
4651
- accessTokenExpiration: SECONDS_IN_A_DAY2,
4652
- refreshTokenExpiration: SECONDS_IN_A_DAY2 * 30
4653
- },
4654
- {
4655
- clientId: "sasjs",
4656
- clientSecret: "sasjs",
4657
- accessTokenExpiration: 3600,
4658
- refreshTokenExpiration: SECONDS_IN_A_DAY2
4659
- }
4660
- ]
4661
- };
4662
- var parseIdentity = (raw) => {
4663
- const fixture = raw;
4664
- if (!fixture || typeof fixture !== "object")
4665
- throw new Error("The identity fixture is not an object.");
4666
- if (fixture.format !== IDENTITY_FORMAT)
4591
+ // src/authconfig/service.ts
4592
+ var LDAP_FIELDS = [
4593
+ "url",
4594
+ "bindDn",
4595
+ "usersBaseDn",
4596
+ "groupsBaseDn",
4597
+ "bindPasswordSet"
4598
+ ];
4599
+ var OIDC_FIELDS = [
4600
+ "providerName",
4601
+ "issuerUrl",
4602
+ "clientId",
4603
+ "redirectUri",
4604
+ "scope",
4605
+ "signingAlg",
4606
+ "usernameClaim",
4607
+ "jitProvision",
4608
+ "clientSecretSet"
4609
+ ];
4610
+ var SECRET = /(password|secret|passwd|token)/i;
4611
+ var checkProvider = (name, block, fields, booleans) => {
4612
+ if (!block || typeof block !== "object")
4667
4613
  throw new Error(
4668
- `The identity fixture states format ${String(fixture.format)}, and this build reads format ${IDENTITY_FORMAT}. Rebuild the site, or replace mock-identity.json with one this version wrote.`
4614
+ `The auth configuration states \`${name}\` as ${JSON.stringify(block)}; a provider is an object, or absent when it is not enabled.`
4669
4615
  );
4670
- for (const key of ["users", "groups", "permissions", "clients"])
4671
- if (!Array.isArray(fixture[key]))
4672
- throw new Error(`The identity fixture has no \`${key}\` array.`);
4673
- for (const token of fixture.tokens || [])
4674
- if (!token.accessToken || !token.refreshToken)
4616
+ for (const key of Object.keys(block)) {
4617
+ if (!fields.includes(key))
4675
4618
  throw new Error(
4676
- `The identity fixture declares a half pair for ${token.username}/${token.clientId}: a seeded token needs both an accessToken and a refreshToken, because a token only authenticates while the subject's pair holds it.`
4619
+ SECRET.test(key) ? `The auth configuration states \`${name}.${key}\`, which looks like a secret. Secrets are never echoed by this route: pass \`${key}Set: true\` instead, so the answer carries whether one is configured and not the value.` : `The auth configuration carries \`${name}.${key}\`, which the document's example does not state. Remove it, or add it to the provider's fields here and to the document.`
4677
4620
  );
4678
- if (!fixture.users.some((user3) => user3.isAdmin))
4621
+ }
4622
+ for (const key of fields) {
4623
+ if (!(key in block))
4624
+ throw new Error(
4625
+ `The auth configuration does not state \`${name}.${key}\`, which the administration interface reads. State the empty string when the host has no value for it.`
4626
+ );
4627
+ const value = block[key];
4628
+ if (booleans.includes(key)) {
4629
+ if (typeof value !== "boolean")
4630
+ throw new Error(
4631
+ `The auth configuration states \`${name}.${key}\` as ${JSON.stringify(value)}; it says whether the secret is configured, so it is a boolean.`
4632
+ );
4633
+ } else if (typeof value !== "string")
4634
+ throw new Error(
4635
+ `The auth configuration states \`${name}.${key}\` as ${JSON.stringify(value)}; the document states a string.`
4636
+ );
4637
+ }
4638
+ };
4639
+ var normaliseAuthConfig = (config) => {
4640
+ if (!config || typeof config !== "object")
4641
+ throw new Error("The auth configuration is not an object.");
4642
+ for (const key of Object.keys(config))
4643
+ if (key !== "ldap" && key !== "oidc")
4644
+ throw new Error(
4645
+ SECRET.test(key) ? `The auth configuration states \`${key}\` at the top level, which looks like a secret. Secrets are never echoed by this route; put the provider under \`ldap\` or \`oidc\` and report whether the secret is set.` : `The auth configuration carries \`${key}\`, which is not a provider this API has. The document states \`ldap\` and \`oidc\`.`
4646
+ );
4647
+ const answer = {};
4648
+ if (config.ldap !== void 0) {
4649
+ checkProvider("ldap", config.ldap, LDAP_FIELDS, ["bindPasswordSet"]);
4650
+ answer.ldap = {
4651
+ LDAP_URL: config.ldap.url,
4652
+ LDAP_BIND_DN: config.ldap.bindDn,
4653
+ LDAP_USERS_BASE_DN: config.ldap.usersBaseDn,
4654
+ LDAP_GROUPS_BASE_DN: config.ldap.groupsBaseDn,
4655
+ LDAP_BIND_PASSWORD_SET: config.ldap.bindPasswordSet
4656
+ };
4657
+ }
4658
+ if (config.oidc !== void 0) {
4659
+ checkProvider("oidc", config.oidc, OIDC_FIELDS, ["clientSecretSet"]);
4660
+ answer.oidc = {
4661
+ OIDC_PROVIDER_NAME: config.oidc.providerName,
4662
+ OIDC_ISSUER_URL: config.oidc.issuerUrl,
4663
+ OIDC_CLIENT_ID: config.oidc.clientId,
4664
+ OIDC_REDIRECT_URI: config.oidc.redirectUri,
4665
+ OIDC_SCOPE: config.oidc.scope,
4666
+ OIDC_SIGNING_ALG: config.oidc.signingAlg,
4667
+ OIDC_USERNAME_CLAIM: config.oidc.usernameClaim,
4668
+ OIDC_JIT_PROVISION: config.oidc.jitProvision,
4669
+ OIDC_CLIENT_SECRET_SET: config.oidc.clientSecretSet
4670
+ };
4671
+ }
4672
+ return answer;
4673
+ };
4674
+ var createAuthConfigService = (config) => {
4675
+ const read = () => typeof config === "function" ? config() : config;
4676
+ return {
4677
+ async authConfig() {
4678
+ return normaliseAuthConfig(read());
4679
+ }
4680
+ };
4681
+ };
4682
+
4683
+ // src/admin/service.ts
4684
+ var DEFAULT_LOG_LINES = 200;
4685
+ var MAX_LOG_LINES = 5e3;
4686
+ var isObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
4687
+ var isNumber = (value) => typeof value === "number" && Number.isFinite(value);
4688
+ var isString = (value) => typeof value === "string";
4689
+ var requireString = (holder, key, where) => {
4690
+ if (!isString(holder[key]))
4679
4691
  throw new Error(
4680
- "The identity fixture declares no administrator: a demo with nobody able to administer it cannot exercise the admin routes."
4692
+ `The ${where} report states \`${key}\` as ${JSON.stringify(holder[key])}; the document states a string, and a client that renders it would print the value as it stands.`
4681
4693
  );
4682
- return fixture;
4683
4694
  };
4684
-
4685
- // src/identity/memory-store.ts
4686
- var keyOf = (subject) => `${subject.userId}|${subject.clientId}`;
4687
- var randomHex = (bytes3) => {
4688
- const source = globalThis.crypto;
4689
- if (!source)
4690
- throw new ApiError(
4691
- 500,
4692
- "This host has no Web Crypto (`globalThis.crypto`), so it cannot mint an unguessable identity string."
4695
+ var requireNumber = (holder, key, where) => {
4696
+ if (!isNumber(holder[key]))
4697
+ throw new Error(
4698
+ `The ${where} report states \`${key}\` as ${JSON.stringify(holder[key])}; the document states a number, and a client that renders it would print NaN.`
4693
4699
  );
4694
- const buffer = new Uint8Array(bytes3);
4695
- source.getRandomValues(buffer);
4696
- return Array.from(buffer, (byte) => byte.toString(16).padStart(2, "0")).join(
4697
- ""
4698
- );
4699
4700
  };
4700
- var CODE_LIFETIME_SECONDS = 30;
4701
- var live = (issued, now) => issued && (issued.expiresAt === void 0 || issued.expiresAt > now) ? issued.subject : void 0;
4702
- var MemoryIdentityStore = class {
4703
- constructor(fixture = DEFAULT_IDENTITY) {
4704
- this.userList = [];
4705
- this.passwords = /* @__PURE__ */ new Map();
4706
- this.groupList = /* @__PURE__ */ new Map();
4707
- this.permissionList = /* @__PURE__ */ new Map();
4708
- this.clientRecords = /* @__PURE__ */ new Map();
4709
- this.clientMap = /* @__PURE__ */ new Map();
4710
- this.pairs = /* @__PURE__ */ new Map();
4711
- this.access = /* @__PURE__ */ new Map();
4712
- this.refresh = /* @__PURE__ */ new Map();
4713
- this.codes = /* @__PURE__ */ new Map();
4714
- this.claimed = /* @__PURE__ */ new Set();
4715
- if (fixture.format !== IDENTITY_FORMAT)
4716
- throw new ApiError(
4717
- 500,
4718
- `The identity fixture states format ${String(fixture.format)}; this store reads ${IDENTITY_FORMAT}.`
4719
- );
4720
- for (const user3 of fixture.users) {
4721
- this.userList.push({
4722
- uid: user3.uid,
4723
- username: user3.username,
4724
- displayName: user3.displayName,
4725
- isAdmin: user3.isAdmin,
4726
- isActive: user3.isActive,
4727
- needsToUpdatePassword: user3.needsToUpdatePassword,
4728
- authProvider: user3.authProvider,
4729
- autoExec: user3.autoExec
4730
- });
4731
- this.passwords.set(user3.uid, user3.password);
4732
- }
4733
- for (const client of fixture.clients) {
4734
- this.clientMap.set(client.clientId, {
4735
- clientId: client.clientId,
4736
- accessTokenExpiration: client.accessTokenExpiration,
4737
- refreshTokenExpiration: client.refreshTokenExpiration
4738
- });
4739
- this.clientRecords.set(client.clientId, {
4740
- clientId: client.clientId,
4741
- clientSecret: client.clientSecret,
4742
- accessTokenExpiration: client.accessTokenExpiration,
4743
- refreshTokenExpiration: client.refreshTokenExpiration
4744
- });
4745
- }
4746
- for (const group of fixture.groups) {
4747
- const uid = group.uid;
4748
- this.groupList.set(uid, {
4749
- uid,
4750
- name: group.name,
4751
- description: group.description,
4752
- isActive: group.isActive,
4753
- authProvider: group.authProvider,
4754
- users: group.users.map(
4755
- (username) => this.userList.find((user3) => user3.username === username)?.uid
4756
- ).filter((member) => member !== void 0)
4757
- });
4758
- }
4759
- for (const permission of fixture.permissions) {
4760
- this.permissionList.set(permission.uid, {
4761
- uid: permission.uid,
4762
- path: permission.path,
4763
- type: permission.type,
4764
- setting: permission.setting,
4765
- user: permission.user ? this.userList.find((user3) => user3.uid === permission.user)?.uid : void 0,
4766
- group: permission.group ? this.groupList.get(permission.group)?.uid : void 0
4767
- });
4768
- }
4769
- for (const token of fixture.tokens || []) {
4770
- const user3 = this.userList.find(
4771
- (candidate) => candidate.username === token.username
4701
+ var requireObject = (holder, key, where) => {
4702
+ const value = holder[key];
4703
+ if (!isObject(value))
4704
+ throw new Error(
4705
+ `The ${where} report states \`${key}\` as ${JSON.stringify(value)}; the document states an object.`
4706
+ );
4707
+ return value;
4708
+ };
4709
+ var normaliseDiagnostics = (report) => {
4710
+ if (!isObject(report))
4711
+ throw new Error("The diagnostics report is not an object.");
4712
+ const build = requireObject(
4713
+ report,
4714
+ "build",
4715
+ "diagnostics"
4716
+ );
4717
+ requireString(build, "version", "diagnostics build");
4718
+ requireString(build, "gitHash", "diagnostics build");
4719
+ if (!(build.buildDate === null || isString(build.buildDate)))
4720
+ throw new Error(
4721
+ `The diagnostics build states \`buildDate\` as ${JSON.stringify(build.buildDate)}; the document states an ISO timestamp or null.`
4722
+ );
4723
+ const server = requireObject(
4724
+ report,
4725
+ "server",
4726
+ "diagnostics"
4727
+ );
4728
+ requireString(server, "mode", "diagnostics server");
4729
+ requireString(server, "startedAt", "diagnostics server");
4730
+ requireString(server, "nodeVersion", "diagnostics server");
4731
+ requireString(server, "platform", "diagnostics server");
4732
+ requireString(server, "arch", "diagnostics server");
4733
+ requireString(server, "cpuModel", "diagnostics server");
4734
+ requireString(server, "sasjsRoot", "diagnostics server");
4735
+ requireNumber(server, "uptimeSeconds", "diagnostics server");
4736
+ requireNumber(server, "pid", "diagnostics server");
4737
+ requireNumber(server, "cpuCount", "diagnostics server");
4738
+ if (!Array.isArray(server.loadAverage) || !server.loadAverage.every(isNumber))
4739
+ throw new Error(
4740
+ "The diagnostics server report states `loadAverage` as something other than an array of numbers."
4741
+ );
4742
+ if (!Array.isArray(server.runTimes) || !server.runTimes.every(isString))
4743
+ throw new Error(
4744
+ "The diagnostics server report states `runTimes` as something other than an array of strings."
4745
+ );
4746
+ const memory = requireObject(
4747
+ report,
4748
+ "memory",
4749
+ "diagnostics"
4750
+ );
4751
+ for (const key of [
4752
+ "rssBytes",
4753
+ "heapTotalBytes",
4754
+ "heapUsedBytes",
4755
+ "externalBytes",
4756
+ "systemTotalBytes",
4757
+ "systemFreeBytes"
4758
+ ])
4759
+ requireNumber(memory, key, "diagnostics memory");
4760
+ const filesystem = report.filesystem;
4761
+ if (filesystem !== null) {
4762
+ if (!isObject(filesystem))
4763
+ throw new Error(
4764
+ `The diagnostics report states \`filesystem\` as ${JSON.stringify(filesystem)}; the document states an object or null.`
4772
4765
  );
4773
- if (!user3) continue;
4774
- const subject = { userId: user3.uid, clientId: token.clientId };
4775
- if (token.accessToken) this.access.set(token.accessToken, { subject });
4776
- if (token.refreshToken) this.refresh.set(token.refreshToken, { subject });
4777
- if (token.accessToken && token.refreshToken)
4778
- this.pairs.set(keyOf(subject), {
4779
- accessToken: token.accessToken,
4780
- refreshToken: token.refreshToken
4781
- });
4782
- }
4783
- for (const code of fixture.codes || []) {
4784
- const user3 = this.userList.find(
4785
- (candidate) => candidate.username === code.username
4766
+ requireString(
4767
+ filesystem,
4768
+ "path",
4769
+ "diagnostics filesystem"
4770
+ );
4771
+ for (const key of ["totalBytes", "freeBytes", "usedBytes", "usedPercent"])
4772
+ requireNumber(
4773
+ filesystem,
4774
+ key,
4775
+ "diagnostics filesystem"
4786
4776
  );
4787
- if (!user3) continue;
4788
- this.codes.set(code.code, {
4789
- subject: { userId: user3.uid, clientId: code.clientId }
4790
- });
4791
- }
4792
4777
  }
4793
- async userByName(username) {
4794
- const user3 = this.userList.find(
4795
- (candidate) => candidate.username === username
4778
+ if (!Array.isArray(report.folders))
4779
+ throw new Error(
4780
+ "The diagnostics report states `folders` as something other than an array."
4796
4781
  );
4797
- return user3 ? this.recordOf(user3) : void 0;
4782
+ for (const folder of report.folders) {
4783
+ if (!isObject(folder))
4784
+ throw new Error(
4785
+ "The diagnostics report carries a folder that is not an object."
4786
+ );
4787
+ const entry = folder;
4788
+ requireString(entry, "label", "diagnostics folder");
4789
+ requireString(entry, "path", "diagnostics folder");
4790
+ requireNumber(entry, "bytes", "diagnostics folder");
4791
+ requireNumber(entry, "files", "diagnostics folder");
4792
+ if (typeof entry.exists !== "boolean" || typeof entry.truncated !== "boolean")
4793
+ throw new Error(
4794
+ "The diagnostics folder report states `exists` or `truncated` as something other than a boolean."
4795
+ );
4798
4796
  }
4799
- async userById(uid) {
4800
- const user3 = this.userList.find((candidate) => candidate.uid === uid);
4801
- return user3 ? this.recordOf(user3) : void 0;
4797
+ const logs = requireObject(
4798
+ report,
4799
+ "logs",
4800
+ "diagnostics"
4801
+ );
4802
+ requireString(logs, "folder", "diagnostics logs");
4803
+ requireNumber(logs, "fileCount", "diagnostics logs");
4804
+ requireNumber(logs, "totalBytes", "diagnostics logs");
4805
+ for (const key of ["newestFile", "newestModified"])
4806
+ if (!(logs[key] === null || isString(logs[key])))
4807
+ throw new Error(
4808
+ `The diagnostics logs summary states \`${key}\` as ${JSON.stringify(logs[key])}; the document states a string or null.`
4809
+ );
4810
+ return report;
4811
+ };
4812
+ var normaliseLogFiles = (files) => {
4813
+ if (!Array.isArray(files))
4814
+ throw new Error("The log report is not an array of files.");
4815
+ return files.map((file) => {
4816
+ if (!isObject(file))
4817
+ throw new Error("The log report carries an entry that is not an object.");
4818
+ const entry = file;
4819
+ requireString(entry, "name", "logs");
4820
+ requireString(entry, "modified", "logs");
4821
+ requireNumber(entry, "sizeBytes", "logs");
4822
+ return file;
4823
+ });
4824
+ };
4825
+ var checkLogFileName = (fileName) => {
4826
+ if (!fileName || fileName.includes("/") || fileName.includes("\\") || fileName.split(/[\\/]/).pop() !== fileName || !fileName.toLowerCase().endsWith(".log"))
4827
+ throw new ApiError(400, "Invalid log file name.");
4828
+ return fileName;
4829
+ };
4830
+ var logLines = (lines) => {
4831
+ if (lines === void 0 || lines === null || lines === "")
4832
+ return DEFAULT_LOG_LINES;
4833
+ const wanted = Number(lines);
4834
+ if (!Number.isFinite(wanted)) return DEFAULT_LOG_LINES;
4835
+ return Math.min(Math.max(Math.trunc(wanted), 1), MAX_LOG_LINES);
4836
+ };
4837
+ var normaliseLogTail = (tail) => {
4838
+ if (!isObject(tail)) throw new Error("The log tail report is not an object.");
4839
+ const entry = tail;
4840
+ requireString(entry, "fileName", "log tail");
4841
+ requireString(entry, "content", "log tail");
4842
+ requireNumber(entry, "lines", "log tail");
4843
+ requireNumber(entry, "bytesRead", "log tail");
4844
+ if (typeof entry.truncated !== "boolean")
4845
+ throw new Error(
4846
+ "The log tail report states `truncated` as something other than a boolean."
4847
+ );
4848
+ return tail;
4849
+ };
4850
+ var createAdminService = (reports) => ({
4851
+ async diagnostics() {
4852
+ return normaliseDiagnostics(await reports.diagnostics());
4853
+ },
4854
+ async logs() {
4855
+ return normaliseLogFiles(await reports.logs());
4856
+ },
4857
+ async logTail(fileName, lines) {
4858
+ const name = checkLogFileName(fileName);
4859
+ const tail = await reports.logTail(name, logLines(lines));
4860
+ if (tail === void 0) throw new ApiError(404, "Log file not found.");
4861
+ return normaliseLogTail(tail);
4802
4862
  }
4803
- /** A fixture holds the password in clear, so the check is an equality. */
4804
- async passwordMatches(user3, password) {
4805
- return this.passwords.get(user3.uid) === password;
4863
+ });
4864
+
4865
+ // src/directory/service.ts
4866
+ var isNonEmptyString3 = (value) => typeof value === "string" && value.length > 0;
4867
+ var usersOf = (users) => {
4868
+ if (!Array.isArray(users))
4869
+ throw new Error("The directory answer has no users array.");
4870
+ const seen = /* @__PURE__ */ new Set();
4871
+ for (const user3 of users) {
4872
+ if (!isNonEmptyString3(user3?.username) || !isNonEmptyString3(user3?.displayName))
4873
+ throw new Error(
4874
+ `The directory answer carries a user without a username or displayName: ${JSON.stringify(user3)}. Both are what the API keys an account on, so the import cannot guess them.`
4875
+ );
4876
+ if (seen.has(user3.username))
4877
+ throw new Error(
4878
+ `The directory answer names ${user3.username} twice. A directory that returns one account twice is a filter problem, and importing it would hide that.`
4879
+ );
4880
+ seen.add(user3.username);
4806
4881
  }
4807
- async client(clientId) {
4808
- return this.clientMap.get(clientId);
4809
- }
4810
- async issue(subject, client) {
4811
- const issuedAt = Date.now();
4812
- const pair = {
4813
- accessToken: `access-${randomHex(16)}`,
4814
- refreshToken: `refresh-${randomHex(16)}`
4815
- };
4816
- this.access.set(pair.accessToken, {
4817
- subject,
4818
- expiresAt: issuedAt + client.accessTokenExpiration * 1e3
4819
- });
4820
- this.refresh.set(pair.refreshToken, {
4821
- subject,
4822
- expiresAt: issuedAt + client.refreshTokenExpiration * 1e3
4823
- });
4824
- return pair;
4825
- }
4826
- /**
4827
- * A token names its subject only while that subject's CURRENT pair holds it.
4828
- * The server verifies a token against the pair saved for the user and client,
4829
- * so a logged-out or rotated token stops working there too; without the same
4830
- * check here, the browser host would honour a token the server had revoked.
4831
- */
4832
- async readAccess(token) {
4833
- return this.current(token, this.access, "accessToken");
4834
- }
4835
- async readRefresh(token) {
4836
- return this.current(token, this.refresh, "refreshToken");
4837
- }
4838
- current(token, issued, kind) {
4839
- const entry = issued.get(token);
4840
- if (!entry) return void 0;
4841
- const subject = live(entry, Date.now());
4842
- if (!subject) return void 0;
4843
- const pair = this.pairs.get(keyOf(subject));
4844
- return pair && pair[kind] === token ? subject : void 0;
4845
- }
4846
- /**
4847
- * The subject's saved pair, while both of its tokens are still live.
4848
- *
4849
- * An exchange hands a saved pair back rather than rotating a second tab's
4850
- * tokens. That is only an answer if the pair can still be used: a saved pair
4851
- * whose access token has aged out would sign the caller in and then refuse
4852
- * every request it makes, so an aged-out pair is reported as absent and the
4853
- * exchange mints a fresh one. `live()` reads the issue-time expiry, which a
4854
- * seeded token does not carry - a seeded pair therefore never ages out here.
4855
- */
4856
- async pairFor(subject) {
4857
- const pair = this.pairs.get(keyOf(subject));
4858
- if (!pair) return void 0;
4859
- const now = Date.now();
4860
- const access = this.access.get(pair.accessToken);
4861
- const refresh = this.refresh.get(pair.refreshToken);
4862
- return live(access, now) && live(refresh, now) ? pair : void 0;
4863
- }
4864
- async savePair(subject, pair) {
4865
- this.pairs.set(keyOf(subject), pair);
4866
- }
4867
- async deletePair(subject) {
4868
- this.pairs.delete(keyOf(subject));
4869
- }
4870
- async issueCode(subject) {
4871
- const code = `code-${randomHex(16)}`;
4872
- this.codes.set(code, {
4873
- subject,
4874
- expiresAt: Date.now() + CODE_LIFETIME_SECONDS * 1e3
4875
- });
4876
- return code;
4877
- }
4878
- async readCode(code) {
4879
- return live(this.codes.get(code), Date.now());
4880
- }
4881
- async claimCode(code) {
4882
- if (this.claimed.has(code) || !this.codes.has(code)) return false;
4883
- this.claimed.add(code);
4884
- return true;
4885
- }
4886
- // ---------------------------------------------------------------- records
4887
- async users() {
4888
- return this.userList.map((user3) => this.recordOf(user3));
4889
- }
4890
- /** A user as the administration routes report one: groups derived, not stored. */
4891
- recordOf(user3) {
4892
- return {
4893
- ...user3,
4894
- groups: [...this.groupList.values()].filter((group) => group.users.includes(user3.uid)).map((group) => group.uid)
4895
- };
4896
- }
4897
- async createUser(input) {
4898
- const user3 = {
4899
- uid: `user-${randomHex(6)}`,
4900
- username: input.username,
4901
- displayName: input.displayName,
4902
- isAdmin: input.isAdmin,
4903
- isActive: input.isActive,
4904
- needsToUpdatePassword: false,
4905
- autoExec: input.autoExec,
4906
- authProvider: input.authProvider
4907
- };
4908
- this.userList.push(user3);
4909
- return this.recordOf(user3);
4910
- }
4911
- async updateUser(uid, change) {
4912
- const user3 = this.userList.find((candidate) => candidate.uid === uid);
4913
- if (!user3) return void 0;
4914
- if (change.username !== void 0) user3.username = change.username;
4915
- if (change.displayName !== void 0) user3.displayName = change.displayName;
4916
- if (change.isAdmin !== void 0) user3.isAdmin = change.isAdmin;
4917
- if (change.isActive !== void 0) user3.isActive = change.isActive;
4918
- if (change.needsToUpdatePassword !== void 0)
4919
- user3.needsToUpdatePassword = change.needsToUpdatePassword;
4920
- if (change.autoExec !== void 0) user3.autoExec = change.autoExec;
4921
- return this.recordOf(user3);
4922
- }
4923
- async deleteUser(uid) {
4924
- const index = this.userList.findIndex((user3) => user3.uid === uid);
4925
- if (index === -1) return;
4926
- this.userList.splice(index, 1);
4927
- this.passwords.delete(uid);
4928
- for (const group of this.groupList.values())
4929
- group.users = group.users.filter((member) => member !== uid);
4930
- for (const [key, permission] of this.permissionList)
4931
- if (permission.user === uid) this.permissionList.delete(key);
4932
- for (const key of this.pairs.keys())
4933
- if (key.startsWith(`${uid}|`)) this.pairs.delete(key);
4934
- }
4935
- async setPassword(uid, password) {
4936
- this.passwords.set(uid, password);
4937
- }
4938
- async groups() {
4939
- return [...this.groupList.values()];
4940
- }
4941
- async groupById(uid) {
4942
- return this.groupList.get(uid);
4943
- }
4944
- async groupByName(name) {
4945
- return [...this.groupList.values()].find((group) => group.name === name);
4946
- }
4947
- async createGroup(input) {
4948
- const group = {
4949
- uid: `group-${randomHex(6)}`,
4950
- name: input.name,
4951
- description: input.description,
4952
- isActive: input.isActive,
4953
- users: [],
4954
- ...input.authProvider === void 0 ? {} : { authProvider: input.authProvider }
4955
- };
4956
- this.groupList.set(group.uid, group);
4957
- return group;
4958
- }
4959
- async deleteGroup(uid) {
4960
- this.groupList.delete(uid);
4961
- for (const [key, permission] of this.permissionList)
4962
- if (permission.group === uid) this.permissionList.delete(key);
4963
- }
4964
- async addToGroup(groupUid, userUid) {
4965
- const group = this.groupList.get(groupUid);
4966
- if (!group) return void 0;
4967
- if (!group.users.includes(userUid)) group.users.push(userUid);
4968
- return group;
4969
- }
4970
- async removeFromGroup(groupUid, userUid) {
4971
- const group = this.groupList.get(groupUid);
4972
- if (!group) return void 0;
4973
- group.users = group.users.filter((member) => member !== userUid);
4974
- return group;
4975
- }
4976
- async permissions() {
4977
- return [...this.permissionList.values()];
4978
- }
4979
- async permissionById(uid) {
4980
- return this.permissionList.get(uid);
4981
- }
4982
- async createPermission(input) {
4983
- const permission = {
4984
- uid: `rule-${randomHex(6)}`,
4985
- path: input.path,
4986
- type: input.type,
4987
- setting: input.setting,
4988
- user: input.user,
4989
- group: input.group
4990
- };
4991
- this.permissionList.set(permission.uid, permission);
4992
- return permission;
4993
- }
4994
- async setPermissionSetting(uid, setting) {
4995
- const permission = this.permissionList.get(uid);
4996
- if (!permission) return void 0;
4997
- permission.setting = setting;
4998
- return permission;
4999
- }
5000
- async deletePermission(uid) {
5001
- this.permissionList.delete(uid);
5002
- }
5003
- async clients() {
5004
- return [...this.clientRecords.values()];
5005
- }
5006
- async createClient(input) {
5007
- this.clientRecords.set(input.clientId, input);
5008
- this.clientMap.set(input.clientId, {
5009
- clientId: input.clientId,
5010
- accessTokenExpiration: input.accessTokenExpiration,
5011
- refreshTokenExpiration: input.refreshTokenExpiration
5012
- });
5013
- return input;
4882
+ return users;
4883
+ };
4884
+ var groupsOf = (groups) => {
4885
+ if (!Array.isArray(groups))
4886
+ throw new Error("The directory answer has no groups array.");
4887
+ const seen = /* @__PURE__ */ new Set();
4888
+ for (const group of groups) {
4889
+ if (!isNonEmptyString3(group?.name))
4890
+ throw new Error(
4891
+ `The directory answer carries a group without a name: ${JSON.stringify(group)}.`
4892
+ );
4893
+ if (seen.has(group.name))
4894
+ throw new Error(
4895
+ `The directory answer names the group ${group.name} twice, which would apply its members twice.`
4896
+ );
4897
+ seen.add(group.name);
5014
4898
  }
4899
+ return groups;
4900
+ };
4901
+ var createDirectoryService = (store, source, options = {}) => {
4902
+ const provider = options.provider || "ldap";
4903
+ return {
4904
+ async synchronise() {
4905
+ const directoryUsers = usersOf(await source.users());
4906
+ const directoryGroups = groupsOf(await source.groups());
4907
+ const existingUsers = await store.users();
4908
+ const existingGroups = await store.groups();
4909
+ const userByName = new Map(
4910
+ existingUsers.map((user3) => [user3.username, user3])
4911
+ );
4912
+ const groupByName = new Map(
4913
+ existingGroups.map((group) => [group.name, group])
4914
+ );
4915
+ const imported = [];
4916
+ for (const user3 of directoryUsers) {
4917
+ if (userByName.has(user3.username)) continue;
4918
+ const created = await store.createUser({
4919
+ username: user3.username,
4920
+ displayName: user3.displayName,
4921
+ isAdmin: false,
4922
+ isActive: true,
4923
+ authProvider: provider
4924
+ });
4925
+ userByName.set(created.username, created);
4926
+ imported.push(created);
4927
+ }
4928
+ const importedGroups = [];
4929
+ for (const group of directoryGroups) {
4930
+ if (groupByName.has(group.name)) continue;
4931
+ const created = await store.createGroup({
4932
+ name: group.name,
4933
+ description: "",
4934
+ isActive: true,
4935
+ authProvider: provider
4936
+ });
4937
+ groupByName.set(created.name, created);
4938
+ importedGroups.push(created);
4939
+ }
4940
+ const membersOf = /* @__PURE__ */ new Map();
4941
+ const note = (groupName, username) => {
4942
+ const members = membersOf.get(groupName) || /* @__PURE__ */ new Set();
4943
+ members.add(username);
4944
+ membersOf.set(groupName, members);
4945
+ };
4946
+ for (const group of directoryGroups)
4947
+ for (const member of group.members || []) note(group.name, member);
4948
+ for (const user3 of directoryUsers)
4949
+ for (const groupName of user3.groups || [])
4950
+ note(groupName, user3.username);
4951
+ for (const group of importedGroups)
4952
+ for (const username of membersOf.get(group.name) || []) {
4953
+ const user3 = userByName.get(username);
4954
+ if (user3) await store.addToGroup(group.uid, user3.uid);
4955
+ }
4956
+ return { userCount: imported.length, groupCount: importedGroups.length };
4957
+ }
4958
+ };
5015
4959
  };
5016
4960
 
5017
- // src/corpus/drive.ts
5018
- var success2 = { status: "success" };
5019
- var bytes = (...values) => Uint8Array.from(values);
5020
- var manyMembers = (count) => Array.from({ length: count }, (_, at) => ({
5021
- name: `f${at}.txt`,
5022
- type: "file",
5023
- code: ""
5024
- }));
5025
- var DRIVE_CORPUS = [
5026
- {
5027
- id: "create-file",
5028
- route: "POST /SASjsApi/drive/file",
5029
- description: "creates a file the drive did not have",
5030
- request: {
5031
- query: { _filePath: "/data/users.csv" },
5032
- file: { name: "users.csv", contents: "id,name\n1,Ann\n" }
5033
- },
5034
- expect: { status: 200, body: success2 }
5035
- },
5036
- {
5037
- id: "create-file-at-form-path",
5038
- route: "POST /SASjsApi/drive/file",
5039
- description: "takes the destination from the form field when the query has none",
5040
- request: {
5041
- file: { name: "x.csv", contents: "x" },
5042
- body: { filePath: "/data/from-form.csv" }
5043
- },
5044
- expect: { status: 200, body: success2 }
5045
- },
5046
- {
5047
- id: "create-file-over-existing",
5048
- route: "POST /SASjsApi/drive/file",
5049
- description: "refuses a create over a file that exists, as 409",
5050
- seed: { "/data/exists.csv": "a" },
5051
- request: {
5052
- query: { _filePath: "/data/exists.csv" },
5053
- file: { name: "x", contents: "b" }
5054
- },
5055
- expect: { status: 409, error: "File already exists." }
5056
- },
5057
- {
5058
- id: "create-file-blocked-extension",
5059
- route: "POST /SASjsApi/drive/file",
5060
- description: "refuses a refused extension before touching the drive",
5061
- request: {
5062
- query: { _filePath: "/data/run.sh" },
5063
- file: { name: "run.sh", contents: "x" }
4961
+ // src/identity/fixture.ts
4962
+ var IDENTITY_FORMAT = 1;
4963
+ var SECONDS_IN_A_DAY2 = 86400;
4964
+ var DEFAULT_IDENTITY = {
4965
+ format: IDENTITY_FORMAT,
4966
+ users: [
4967
+ {
4968
+ uid: "user-admin",
4969
+ username: "sasjsadmin",
4970
+ displayName: "Demo Admin",
4971
+ // long enough to pass the API's own password rule (six characters), so a
4972
+ // demo can sign in against a real server as well as a mock
4973
+ password: "Orion123",
4974
+ isAdmin: true,
4975
+ isActive: true,
4976
+ needsToUpdatePassword: false
5064
4977
  },
5065
- expect: { status: 400, error: "Invalid file extension" }
5066
- },
5067
- {
5068
- id: "create-file-outside-drive",
5069
- route: "POST /SASjsApi/drive/file",
5070
- description: "refuses a path that climbs out of the drive",
5071
- request: {
5072
- query: { _filePath: "/../escape.csv" },
5073
- file: { name: "x", contents: "x" }
4978
+ {
4979
+ uid: "user-restricted",
4980
+ username: "sasjsuser",
4981
+ displayName: "Demo User",
4982
+ password: "Orion123",
4983
+ isAdmin: false,
4984
+ isActive: true,
4985
+ needsToUpdatePassword: false
4986
+ }
4987
+ ],
4988
+ groups: [
4989
+ {
4990
+ uid: "group-data-controller",
4991
+ name: "DCGroup",
4992
+ description: "Data Controller users",
4993
+ isActive: true,
4994
+ users: ["sasjsuser"]
5074
4995
  },
5075
- expect: { status: 400, error: "Can't put file outside drive." }
5076
- },
5077
- {
5078
- id: "create-file-without-payload",
5079
- route: "POST /SASjsApi/drive/file",
5080
- description: "answers for a missing file with the server wording",
5081
- request: { query: { _filePath: "/data/x.csv" } },
5082
- expect: { status: 400, error: '"file" is not present.' }
5083
- },
5084
- {
5085
- id: "create-file-without-destination",
5086
- route: "POST /SASjsApi/drive/file",
5087
- description: "answers for a missing destination with the validation wording",
5088
- request: { file: { name: "x", contents: "x" } },
5089
- expect: { status: 400, error: '"_filePath" is required' }
5090
- },
5091
- {
5092
- id: "replace-file",
5093
- route: "PATCH /SASjsApi/drive/file",
5094
- description: "replaces the contents of a file that exists",
5095
- seed: { "/data/keep.csv": "old" },
5096
- request: {
5097
- query: { _filePath: "/data/keep.csv" },
5098
- file: { name: "keep.csv", contents: "new" }
4996
+ {
4997
+ uid: "group-admins",
4998
+ name: "Admins",
4999
+ description: "Everything the API offers",
5000
+ isActive: true,
5001
+ users: ["sasjsadmin"]
5002
+ }
5003
+ ],
5004
+ permissions: [
5005
+ {
5006
+ uid: "rule-routes",
5007
+ path: "/SASjsApi/drive/file",
5008
+ type: "Route",
5009
+ setting: "Grant",
5010
+ group: "group-data-controller"
5099
5011
  },
5100
- expect: { status: 200, body: success2 }
5101
- },
5102
- {
5103
- id: "replace-file-missing",
5104
- route: "PATCH /SASjsApi/drive/file",
5105
- description: "refuses a replace of a file that is not there, as 404",
5106
- request: {
5107
- query: { _filePath: "/data/missing.csv" },
5108
- file: { name: "x", contents: "x" }
5012
+ {
5013
+ uid: "rule-execute",
5014
+ path: "/SASjsApi/stp/execute",
5015
+ type: "Route",
5016
+ setting: "Grant",
5017
+ group: "group-data-controller"
5109
5018
  },
5110
- expect: { status: 404, error: `File doesn't exist.` }
5111
- },
5112
- {
5113
- id: "replace-file-outside-drive",
5114
- route: "PATCH /SASjsApi/drive/file",
5115
- description: "refuses a replace of a path that climbs out of the drive",
5116
- request: {
5117
- query: { _filePath: "/../escape.csv" },
5118
- file: { name: "x", contents: "x" }
5119
- },
5120
- expect: { status: 400, error: "Can't modify file outside drive." }
5121
- },
5122
- {
5123
- id: "read-file",
5124
- route: "GET /SASjsApi/drive/file",
5125
- description: "answers with the file contents",
5126
- seed: { "/data/keep.csv": "a,b\n1,2\n" },
5127
- request: { query: { _filePath: "/data/keep.csv" } },
5128
- expect: { status: 200, contents: "a,b\n1,2\n" }
5129
- },
5130
- {
5131
- id: "read-file-missing",
5132
- route: "GET /SASjsApi/drive/file",
5133
- description: "refuses a read of a file that is not there",
5134
- request: { query: { _filePath: "/data/missing.csv" } },
5135
- expect: { status: 404, error: `File doesn't exist.` }
5136
- },
5137
- {
5138
- id: "read-file-outside-drive",
5139
- route: "GET /SASjsApi/drive/file",
5140
- description: "refuses a read of a path that climbs out of the drive",
5141
- request: { query: { _filePath: "/../escape.csv" } },
5142
- expect: { status: 400, error: "Can't get file outside drive." }
5143
- },
5144
- {
5145
- id: "delete-file",
5146
- route: "DELETE /SASjsApi/drive/file",
5147
- description: "deletes a file that exists",
5148
- seed: { "/data/keep.csv": "a" },
5149
- request: { query: { _filePath: "/data/keep.csv" } },
5150
- expect: { status: 200, body: success2 }
5151
- },
5152
- {
5153
- id: "delete-file-missing",
5154
- route: "DELETE /SASjsApi/drive/file",
5155
- description: "refuses a delete of a file that is not there",
5156
- request: { query: { _filePath: "/data/missing.csv" } },
5157
- expect: { status: 404, error: `File doesn't exist.` }
5158
- },
5159
- {
5160
- id: "delete-file-outside-drive",
5161
- route: "DELETE /SASjsApi/drive/file",
5162
- description: "refuses a delete of a path that climbs out of the drive",
5163
- request: { query: { _filePath: "/../escape.csv" } },
5164
- expect: { status: 400, error: "Can't delete file outside drive." }
5165
- },
5166
- {
5167
- id: "list-folder",
5168
- route: "GET /SASjsApi/drive/folder",
5169
- description: "lists the files and folders of a folder",
5170
- seed: { "/data/a.csv": "a", "/data/reports/b.csv": "b" },
5171
- request: { query: { _folderPath: "/data" } },
5172
- expect: { status: 200, body: { files: ["a.csv"], folders: ["reports"] } }
5173
- },
5174
- {
5175
- id: "list-folder-missing",
5176
- route: "GET /SASjsApi/drive/folder",
5177
- description: "refuses a listing of a folder that is not there",
5178
- request: { query: { _folderPath: "/nope" } },
5179
- expect: { status: 404, error: `Folder doesn't exist.` }
5180
- },
5181
- {
5182
- id: "list-folder-outside-drive",
5183
- route: "GET /SASjsApi/drive/folder",
5184
- description: "refuses a listing of a path that climbs out of the drive",
5185
- request: { query: { _folderPath: "/../escape" } },
5186
- expect: { status: 400, error: "Can't get folder outside drive." }
5187
- },
5188
- {
5189
- id: "delete-folder-without-path",
5190
- route: "DELETE /SASjsApi/drive/folder",
5191
- description: "answers for a missing folder path, because the table marks it required",
5192
- request: {},
5193
- expect: { status: 400, error: '"_folderPath" is required' }
5194
- },
5195
- {
5196
- id: "create-folder-without-path",
5197
- route: "POST /SASjsApi/drive/folder",
5198
- description: "answers for a missing folder path in the body",
5199
- request: { body: {} },
5200
- expect: { status: 400, error: '"folderPath" is required' }
5201
- },
5202
- {
5203
- id: "create-folder",
5204
- route: "POST /SASjsApi/drive/folder",
5205
- description: "creates a folder",
5206
- request: { body: { folderPath: "/data/reports" } },
5207
- expect: { status: 200, body: success2 }
5208
- },
5209
- {
5210
- id: "create-folder-existing",
5211
- route: "POST /SASjsApi/drive/folder",
5212
- description: "refuses a folder that already exists, as 409",
5213
- seed: { "/data/reports/a.csv": "a" },
5214
- request: { body: { folderPath: "/data/reports" } },
5215
- expect: { status: 409, error: "Folder already exists." }
5216
- },
5217
- {
5218
- id: "delete-folder",
5219
- route: "DELETE /SASjsApi/drive/folder",
5220
- description: "deletes a folder with everything under it",
5221
- seed: { "/data/reports/a.csv": "a", "/data/reports/nested/b.csv": "b" },
5222
- request: { query: { _folderPath: "/data/reports" } },
5223
- expect: { status: 200, body: success2 }
5224
- },
5225
- {
5226
- id: "delete-folder-missing",
5227
- route: "DELETE /SASjsApi/drive/folder",
5228
- description: "refuses a delete of a folder that is not there",
5229
- request: { query: { _folderPath: "/nope" } },
5230
- expect: { status: 404, error: `Folder doesn't exist.` }
5231
- },
5232
- {
5233
- id: "rename-file",
5234
- route: "POST /SASjsApi/drive/rename",
5235
- description: "moves a file to a new path",
5236
- seed: { "/data/old.csv": "r" },
5237
- request: { body: { oldPath: "/data/old.csv", newPath: "/data/new.csv" } },
5238
- expect: { status: 200, body: success2 }
5239
- },
5240
- {
5241
- id: "rename-onto-existing",
5242
- route: "POST /SASjsApi/drive/rename",
5243
- description: "refuses a move onto something that exists",
5244
- seed: { "/data/a.csv": "a", "/data/b.csv": "b" },
5245
- request: { body: { oldPath: "/data/a.csv", newPath: "/data/b.csv" } },
5246
- expect: { status: 409, error: "File with new name already exists." }
5247
- },
5248
- {
5249
- id: "rename-missing",
5250
- route: "POST /SASjsApi/drive/rename",
5251
- description: "refuses a move of something that is not there",
5252
- request: { body: { oldPath: "/data/nope.csv", newPath: "/data/x.csv" } },
5253
- expect: { status: 404, error: "No file/folder found for provided path." }
5254
- },
5255
- {
5256
- id: "rename-file-to-blocked-extension",
5257
- route: "POST /SASjsApi/drive/rename",
5258
- description: "refuses a rename that would produce a name the file routes refuse",
5259
- seed: { "/data/report.csv": "a,b" },
5260
- request: {
5261
- body: { oldPath: "/data/report.csv", newPath: "/data/report.sh" }
5262
- },
5263
- expect: { status: 400, error: "Invalid file extension" }
5264
- },
5265
- {
5266
- id: "rename-folder-to-dotted-name",
5267
- route: "POST /SASjsApi/drive/rename",
5268
- description: "renames a folder whose new name carries a blocked suffix",
5269
- seed: { "/data/reports/a.csv": "a" },
5270
- request: {
5271
- body: { oldPath: "/data/reports", newPath: "/data/reports.sh" }
5272
- },
5273
- expect: { status: 200, body: { status: "success" } }
5274
- },
5275
- {
5276
- id: "rename-folder-into-itself",
5277
- route: "POST /SASjsApi/drive/rename",
5278
- description: "refuses a folder moved inside itself, which the server loses at the filesystem",
5279
- seed: { "/data/reports/a.csv": "a" },
5280
- request: {
5281
- body: { oldPath: "/data/reports", newPath: "/data/reports/nested" }
5282
- },
5283
- expect: {
5284
- status: 400,
5285
- error: "New path can't be inside the folder being moved."
5286
- }
5287
- },
5288
- {
5289
- id: "tree",
5290
- route: "GET /SASjsApi/drive/filetree",
5291
- description: "answers with the drive tree",
5292
- seed: { "/data/a.csv": "a" },
5293
- request: { query: { _folderPath: "/data" } },
5294
- expect: {
5295
- status: 200,
5296
- body: {
5297
- status: "success",
5298
- tree: {
5299
- name: "data",
5300
- relativePath: "/data",
5301
- isFolder: true,
5302
- children: [
5303
- {
5304
- name: "a.csv",
5305
- relativePath: "/data/a.csv",
5306
- isFolder: false,
5307
- children: []
5308
- }
5309
- ]
5310
- }
5311
- }
5312
- }
5313
- },
5314
- {
5315
- id: "deploy-tree",
5316
- route: "POST /SASjsApi/drive/deploy",
5317
- description: "writes a whole tree under the appLoc it names",
5318
- request: {
5319
- body: {
5320
- appLoc: "/Public/apps/demo",
5321
- fileTree: {
5322
- members: [
5323
- {
5324
- name: "services",
5325
- type: "folder",
5326
- members: [{ name: "run", type: "service", code: "%put hi;" }]
5327
- },
5328
- { name: "index.html", type: "file", code: "PGgxPkhlbGxvPC9oMT4=" }
5329
- ]
5330
- }
5331
- }
5332
- },
5333
- expect: {
5334
- status: 200,
5335
- body: {
5336
- status: "success",
5337
- message: "Files deployed successfully to @sasjs/server."
5338
- }
5339
- }
5340
- },
5341
- {
5342
- id: "deploy-refused-by-entry-count",
5343
- route: "POST /SASjsApi/drive/deploy",
5344
- description: "refuses a tree over the entry cap, naming the figure and the cap",
5345
- request: {
5346
- body: {
5347
- appLoc: "/Public/apps/many",
5348
- fileTree: { members: manyMembers(10001) }
5349
- }
5350
- },
5351
- expect: {
5352
- status: 413,
5353
- body: {
5354
- status: "failure",
5355
- message: "The file tree exceeds the deploy limit: 10001 entries (maximum 10000)."
5356
- },
5357
- error: "The file tree exceeds the deploy limit: 10001 entries (maximum 10000)."
5358
- }
5359
- },
5360
- {
5361
- id: "deploy-refused-by-name",
5362
- route: "POST /SASjsApi/drive/deploy",
5363
- description: "refuses a member name that would escape the deployment root",
5364
- request: {
5365
- body: {
5366
- appLoc: "/Public/apps/hostile",
5367
- fileTree: {
5368
- members: [{ name: "../escape", type: "service", code: "%put hi;" }]
5369
- }
5370
- }
5371
- },
5372
- expect: {
5373
- status: 400,
5374
- body: {
5375
- status: "failure",
5376
- message: "Invalid member name: '../escape.sas'. Member names must be single path segments (no '/', '\\', '..')."
5377
- },
5378
- error: "Invalid member name: '../escape.sas'. Member names must be single path segments (no '/', '\\', '..')."
5379
- }
5380
- },
5381
- {
5382
- id: "deploy-refused-by-shape",
5383
- route: "POST /SASjsApi/drive/deploy",
5384
- description: "refuses a fileTree that is not a tree, in the routes own envelope",
5385
- request: { body: { appLoc: "/Public/apps/bad", fileTree: { members: 1 } } },
5386
- expect: {
5387
- status: 400,
5388
- body: {
5389
- status: "failure",
5390
- message: "Provided not supported data format."
5391
- },
5392
- error: "Provided not supported data format."
5393
- }
5394
- },
5395
- {
5396
- id: "deploy-refused-by-store",
5397
- route: "POST /SASjsApi/drive/deploy",
5398
- description: "answers the routes 500 when the drive refuses the write",
5399
- unwritable: true,
5400
- request: {
5401
- body: {
5402
- appLoc: "/Public/apps/demo",
5403
- fileTree: {
5404
- members: [{ name: "run", type: "service", code: "%put hi;" }]
5405
- }
5406
- }
5407
- },
5408
- expect: {
5409
- status: 500,
5410
- body: { status: "failure", message: "Deployment failed!" },
5411
- error: "Deployment failed!"
5412
- }
5413
- },
5414
- {
5415
- id: "deploy-refused-outside-drive",
5416
- route: "POST /SASjsApi/drive/deploy",
5417
- description: "refuses an appLoc that resolves outside the drive",
5418
- request: {
5419
- body: { appLoc: "/../outside", fileTree: { members: [] } }
5420
- },
5421
- expect: {
5422
- status: 400,
5423
- body: { status: "failure", message: "appLoc cannot be outside drive." },
5424
- error: "appLoc cannot be outside drive."
5425
- }
5426
- },
5427
- {
5428
- id: "bytes-round-trip",
5429
- route: "GET /SASjsApi/drive/file",
5430
- description: "keeps a byte file as bytes",
5431
- seed: { "/data/pack.zip": bytes(80, 75, 3, 4) },
5432
- request: { query: { _filePath: "/data/pack.zip" } },
5433
- expect: { status: 200, contents: bytes(80, 75, 3, 4) }
5434
- }
5435
- ];
5436
-
5437
- // src/corpus/identity.ts
5438
- var SIGNED_IN = {
5439
- ...DEFAULT_IDENTITY,
5440
- tokens: [
5441
- {
5442
- username: "user2",
5443
- clientId: "web_app",
5444
- accessToken: "seed-access",
5445
- refreshToken: "seed-refresh"
5019
+ {
5020
+ uid: "rule-code",
5021
+ path: "/SASjsApi/code/execute",
5022
+ type: "Route",
5023
+ setting: "Deny",
5024
+ user: "user-restricted"
5025
+ }
5026
+ ],
5027
+ clients: [
5028
+ {
5029
+ clientId: "web_app",
5030
+ clientSecret: "web_app",
5031
+ accessTokenExpiration: SECONDS_IN_A_DAY2,
5032
+ refreshTokenExpiration: SECONDS_IN_A_DAY2 * 30
5446
5033
  },
5447
5034
  {
5448
- username: "admin",
5449
- clientId: "removed_client",
5450
- accessToken: "seed-access-orphan",
5451
- refreshToken: "seed-refresh-orphan"
5452
- }
5453
- ],
5454
- codes: [
5455
- { code: "seed-code", username: "user2", clientId: "web_app" },
5456
- { code: "seed-orphan-code", username: "user2", clientId: "removed_client" },
5457
- // the same shape with a pair already issued: the exchange must still refuse,
5458
- // rather than handing back tokens that belong to a client that is gone
5459
- {
5460
- code: "seed-orphan-pair-code",
5461
- username: "admin",
5462
- clientId: "removed_client"
5035
+ clientId: "sasjs",
5036
+ clientSecret: "sasjs",
5037
+ accessTokenExpiration: 3600,
5038
+ refreshTokenExpiration: SECONDS_IN_A_DAY2
5463
5039
  }
5464
5040
  ]
5465
5041
  };
5466
- var DEACTIVATED = {
5467
- ...SIGNED_IN,
5468
- users: SIGNED_IN.users.map(
5469
- (user3) => user3.username === "user2" ? { ...user3, isActive: false } : user3
5470
- )
5471
- };
5472
- var user2 = {
5473
- username: "user2",
5474
- displayName: "Demo User",
5475
- isAdmin: false,
5476
- needsToUpdatePassword: false
5477
- };
5478
- var IDENTITY_CORPUS = [
5479
- {
5480
- id: "login",
5481
- route: "POST /SASLogon/login",
5482
- description: "signs a seeded user in",
5483
- request: { body: { username: "admin", password: "admin123" } },
5484
- expect: {
5485
- status: 200,
5042
+ var parseIdentity = (raw) => {
5043
+ const fixture = raw;
5044
+ if (!fixture || typeof fixture !== "object")
5045
+ throw new Error("The identity fixture is not an object.");
5046
+ if (fixture.format !== IDENTITY_FORMAT)
5047
+ throw new Error(
5048
+ `The identity fixture states format ${String(fixture.format)}, and this build reads format ${IDENTITY_FORMAT}. Rebuild the site, or replace mock-identity.json with one this version wrote.`
5049
+ );
5050
+ for (const key of ["users", "groups", "permissions", "clients"])
5051
+ if (!Array.isArray(fixture[key]))
5052
+ throw new Error(`The identity fixture has no \`${key}\` array.`);
5053
+ for (const token of fixture.tokens || [])
5054
+ if (!token.accessToken || !token.refreshToken)
5055
+ throw new Error(
5056
+ `The identity fixture declares a half pair for ${token.username}/${token.clientId}: a seeded token needs both an accessToken and a refreshToken, because a token only authenticates while the subject's pair holds it.`
5057
+ );
5058
+ if (!fixture.users.some((user3) => user3.isAdmin))
5059
+ throw new Error(
5060
+ "The identity fixture declares no administrator: a demo with nobody able to administer it cannot exercise the admin routes."
5061
+ );
5062
+ return fixture;
5063
+ };
5064
+
5065
+ // src/identity/memory-store.ts
5066
+ var keyOf = (subject) => `${subject.userId}|${subject.clientId}`;
5067
+ var randomHex = (bytes3) => {
5068
+ const source = globalThis.crypto;
5069
+ if (!source)
5070
+ throw new ApiError(
5071
+ 500,
5072
+ "This host has no Web Crypto (`globalThis.crypto`), so it cannot mint an unguessable identity string."
5073
+ );
5074
+ const buffer = new Uint8Array(bytes3);
5075
+ source.getRandomValues(buffer);
5076
+ return Array.from(buffer, (byte) => byte.toString(16).padStart(2, "0")).join(
5077
+ ""
5078
+ );
5079
+ };
5080
+ var CODE_LIFETIME_SECONDS = 30;
5081
+ var live = (issued, now) => issued && (issued.expiresAt === void 0 || issued.expiresAt > now) ? issued.subject : void 0;
5082
+ var MemoryIdentityStore = class {
5083
+ constructor(fixture = DEFAULT_IDENTITY) {
5084
+ this.userList = [];
5085
+ this.passwords = /* @__PURE__ */ new Map();
5086
+ this.groupList = /* @__PURE__ */ new Map();
5087
+ this.permissionList = /* @__PURE__ */ new Map();
5088
+ this.clientRecords = /* @__PURE__ */ new Map();
5089
+ this.clientMap = /* @__PURE__ */ new Map();
5090
+ this.pairs = /* @__PURE__ */ new Map();
5091
+ this.access = /* @__PURE__ */ new Map();
5092
+ this.refresh = /* @__PURE__ */ new Map();
5093
+ this.codes = /* @__PURE__ */ new Map();
5094
+ this.claimed = /* @__PURE__ */ new Set();
5095
+ if (fixture.format !== IDENTITY_FORMAT)
5096
+ throw new ApiError(
5097
+ 500,
5098
+ `The identity fixture states format ${String(fixture.format)}; this store reads ${IDENTITY_FORMAT}.`
5099
+ );
5100
+ for (const user3 of fixture.users) {
5101
+ this.userList.push({
5102
+ uid: user3.uid,
5103
+ username: user3.username,
5104
+ displayName: user3.displayName,
5105
+ isAdmin: user3.isAdmin,
5106
+ isActive: user3.isActive,
5107
+ needsToUpdatePassword: user3.needsToUpdatePassword,
5108
+ authProvider: user3.authProvider,
5109
+ autoExec: user3.autoExec
5110
+ });
5111
+ this.passwords.set(user3.uid, user3.password);
5112
+ }
5113
+ for (const client of fixture.clients) {
5114
+ this.clientMap.set(client.clientId, {
5115
+ clientId: client.clientId,
5116
+ accessTokenExpiration: client.accessTokenExpiration,
5117
+ refreshTokenExpiration: client.refreshTokenExpiration
5118
+ });
5119
+ this.clientRecords.set(client.clientId, {
5120
+ clientId: client.clientId,
5121
+ clientSecret: client.clientSecret,
5122
+ accessTokenExpiration: client.accessTokenExpiration,
5123
+ refreshTokenExpiration: client.refreshTokenExpiration
5124
+ });
5125
+ }
5126
+ for (const group of fixture.groups) {
5127
+ const uid = group.uid;
5128
+ this.groupList.set(uid, {
5129
+ uid,
5130
+ name: group.name,
5131
+ description: group.description,
5132
+ isActive: group.isActive,
5133
+ authProvider: group.authProvider,
5134
+ users: group.users.map(
5135
+ (username) => this.userList.find((user3) => user3.username === username)?.uid
5136
+ ).filter((member) => member !== void 0)
5137
+ });
5138
+ }
5139
+ for (const permission of fixture.permissions) {
5140
+ this.permissionList.set(permission.uid, {
5141
+ uid: permission.uid,
5142
+ path: permission.path,
5143
+ type: permission.type,
5144
+ setting: permission.setting,
5145
+ user: permission.user ? this.userList.find((user3) => user3.uid === permission.user)?.uid : void 0,
5146
+ group: permission.group ? this.groupList.get(permission.group)?.uid : void 0
5147
+ });
5148
+ }
5149
+ for (const token of fixture.tokens || []) {
5150
+ const user3 = this.userList.find(
5151
+ (candidate) => candidate.username === token.username
5152
+ );
5153
+ if (!user3) continue;
5154
+ const subject = { userId: user3.uid, clientId: token.clientId };
5155
+ if (token.accessToken) this.access.set(token.accessToken, { subject });
5156
+ if (token.refreshToken) this.refresh.set(token.refreshToken, { subject });
5157
+ if (token.accessToken && token.refreshToken)
5158
+ this.pairs.set(keyOf(subject), {
5159
+ accessToken: token.accessToken,
5160
+ refreshToken: token.refreshToken
5161
+ });
5162
+ }
5163
+ for (const code of fixture.codes || []) {
5164
+ const user3 = this.userList.find(
5165
+ (candidate) => candidate.username === code.username
5166
+ );
5167
+ if (!user3) continue;
5168
+ this.codes.set(code.code, {
5169
+ subject: { userId: user3.uid, clientId: code.clientId }
5170
+ });
5171
+ }
5172
+ }
5173
+ async userByName(username) {
5174
+ const user3 = this.userList.find(
5175
+ (candidate) => candidate.username === username
5176
+ );
5177
+ return user3 ? this.recordOf(user3) : void 0;
5178
+ }
5179
+ async userById(uid) {
5180
+ const user3 = this.userList.find((candidate) => candidate.uid === uid);
5181
+ return user3 ? this.recordOf(user3) : void 0;
5182
+ }
5183
+ /** A fixture holds the password in clear, so the check is an equality. */
5184
+ async passwordMatches(user3, password) {
5185
+ return this.passwords.get(user3.uid) === password;
5186
+ }
5187
+ async client(clientId) {
5188
+ return this.clientMap.get(clientId);
5189
+ }
5190
+ async issue(subject, client) {
5191
+ const issuedAt = Date.now();
5192
+ const pair = {
5193
+ accessToken: `access-${randomHex(16)}`,
5194
+ refreshToken: `refresh-${randomHex(16)}`
5195
+ };
5196
+ this.access.set(pair.accessToken, {
5197
+ subject,
5198
+ expiresAt: issuedAt + client.accessTokenExpiration * 1e3
5199
+ });
5200
+ this.refresh.set(pair.refreshToken, {
5201
+ subject,
5202
+ expiresAt: issuedAt + client.refreshTokenExpiration * 1e3
5203
+ });
5204
+ return pair;
5205
+ }
5206
+ /**
5207
+ * A token names its subject only while that subject's CURRENT pair holds it.
5208
+ * The server verifies a token against the pair saved for the user and client,
5209
+ * so a logged-out or rotated token stops working there too; without the same
5210
+ * check here, the browser host would honour a token the server had revoked.
5211
+ */
5212
+ async readAccess(token) {
5213
+ return this.current(token, this.access, "accessToken");
5214
+ }
5215
+ async readRefresh(token) {
5216
+ return this.current(token, this.refresh, "refreshToken");
5217
+ }
5218
+ current(token, issued, kind) {
5219
+ const entry = issued.get(token);
5220
+ if (!entry) return void 0;
5221
+ const subject = live(entry, Date.now());
5222
+ if (!subject) return void 0;
5223
+ const pair = this.pairs.get(keyOf(subject));
5224
+ return pair && pair[kind] === token ? subject : void 0;
5225
+ }
5226
+ /**
5227
+ * The subject's saved pair, while both of its tokens are still live.
5228
+ *
5229
+ * An exchange hands a saved pair back rather than rotating a second tab's
5230
+ * tokens. That is only an answer if the pair can still be used: a saved pair
5231
+ * whose access token has aged out would sign the caller in and then refuse
5232
+ * every request it makes, so an aged-out pair is reported as absent and the
5233
+ * exchange mints a fresh one. `live()` reads the issue-time expiry, which a
5234
+ * seeded token does not carry - a seeded pair therefore never ages out here.
5235
+ */
5236
+ async pairFor(subject) {
5237
+ const pair = this.pairs.get(keyOf(subject));
5238
+ if (!pair) return void 0;
5239
+ const now = Date.now();
5240
+ const access = this.access.get(pair.accessToken);
5241
+ const refresh = this.refresh.get(pair.refreshToken);
5242
+ return live(access, now) && live(refresh, now) ? pair : void 0;
5243
+ }
5244
+ async savePair(subject, pair) {
5245
+ this.pairs.set(keyOf(subject), pair);
5246
+ }
5247
+ async deletePair(subject) {
5248
+ this.pairs.delete(keyOf(subject));
5249
+ }
5250
+ async issueCode(subject) {
5251
+ const code = `code-${randomHex(16)}`;
5252
+ this.codes.set(code, {
5253
+ subject,
5254
+ expiresAt: Date.now() + CODE_LIFETIME_SECONDS * 1e3
5255
+ });
5256
+ return code;
5257
+ }
5258
+ async readCode(code) {
5259
+ return live(this.codes.get(code), Date.now());
5260
+ }
5261
+ async claimCode(code) {
5262
+ if (this.claimed.has(code) || !this.codes.has(code)) return false;
5263
+ this.claimed.add(code);
5264
+ return true;
5265
+ }
5266
+ // ---------------------------------------------------------------- records
5267
+ async users() {
5268
+ return this.userList.map((user3) => this.recordOf(user3));
5269
+ }
5270
+ /** A user as the administration routes report one: groups derived, not stored. */
5271
+ recordOf(user3) {
5272
+ return {
5273
+ ...user3,
5274
+ groups: [...this.groupList.values()].filter((group) => group.users.includes(user3.uid)).map((group) => group.uid)
5275
+ };
5276
+ }
5277
+ async createUser(input) {
5278
+ const user3 = {
5279
+ uid: `user-${randomHex(6)}`,
5280
+ username: input.username,
5281
+ displayName: input.displayName,
5282
+ isAdmin: input.isAdmin,
5283
+ isActive: input.isActive,
5284
+ needsToUpdatePassword: false,
5285
+ autoExec: input.autoExec,
5286
+ authProvider: input.authProvider
5287
+ };
5288
+ this.userList.push(user3);
5289
+ return this.recordOf(user3);
5290
+ }
5291
+ async updateUser(uid, change) {
5292
+ const user3 = this.userList.find((candidate) => candidate.uid === uid);
5293
+ if (!user3) return void 0;
5294
+ if (change.username !== void 0) user3.username = change.username;
5295
+ if (change.displayName !== void 0) user3.displayName = change.displayName;
5296
+ if (change.isAdmin !== void 0) user3.isAdmin = change.isAdmin;
5297
+ if (change.isActive !== void 0) user3.isActive = change.isActive;
5298
+ if (change.needsToUpdatePassword !== void 0)
5299
+ user3.needsToUpdatePassword = change.needsToUpdatePassword;
5300
+ if (change.autoExec !== void 0) user3.autoExec = change.autoExec;
5301
+ return this.recordOf(user3);
5302
+ }
5303
+ async deleteUser(uid) {
5304
+ const index = this.userList.findIndex((user3) => user3.uid === uid);
5305
+ if (index === -1) return;
5306
+ this.userList.splice(index, 1);
5307
+ this.passwords.delete(uid);
5308
+ for (const group of this.groupList.values())
5309
+ group.users = group.users.filter((member) => member !== uid);
5310
+ for (const [key, permission] of this.permissionList)
5311
+ if (permission.user === uid) this.permissionList.delete(key);
5312
+ for (const key of this.pairs.keys())
5313
+ if (key.startsWith(`${uid}|`)) this.pairs.delete(key);
5314
+ }
5315
+ async setPassword(uid, password) {
5316
+ this.passwords.set(uid, password);
5317
+ }
5318
+ async groups() {
5319
+ return [...this.groupList.values()];
5320
+ }
5321
+ async groupById(uid) {
5322
+ return this.groupList.get(uid);
5323
+ }
5324
+ async groupByName(name) {
5325
+ return [...this.groupList.values()].find((group) => group.name === name);
5326
+ }
5327
+ async createGroup(input) {
5328
+ const group = {
5329
+ uid: `group-${randomHex(6)}`,
5330
+ name: input.name,
5331
+ description: input.description,
5332
+ isActive: input.isActive,
5333
+ users: [],
5334
+ ...input.authProvider === void 0 ? {} : { authProvider: input.authProvider }
5335
+ };
5336
+ this.groupList.set(group.uid, group);
5337
+ return group;
5338
+ }
5339
+ async deleteGroup(uid) {
5340
+ this.groupList.delete(uid);
5341
+ for (const [key, permission] of this.permissionList)
5342
+ if (permission.group === uid) this.permissionList.delete(key);
5343
+ }
5344
+ async addToGroup(groupUid, userUid) {
5345
+ const group = this.groupList.get(groupUid);
5346
+ if (!group) return void 0;
5347
+ if (!group.users.includes(userUid)) group.users.push(userUid);
5348
+ return group;
5349
+ }
5350
+ async removeFromGroup(groupUid, userUid) {
5351
+ const group = this.groupList.get(groupUid);
5352
+ if (!group) return void 0;
5353
+ group.users = group.users.filter((member) => member !== userUid);
5354
+ return group;
5355
+ }
5356
+ async permissions() {
5357
+ return [...this.permissionList.values()];
5358
+ }
5359
+ async permissionById(uid) {
5360
+ return this.permissionList.get(uid);
5361
+ }
5362
+ async createPermission(input) {
5363
+ const permission = {
5364
+ uid: `rule-${randomHex(6)}`,
5365
+ path: input.path,
5366
+ type: input.type,
5367
+ setting: input.setting,
5368
+ user: input.user,
5369
+ group: input.group
5370
+ };
5371
+ this.permissionList.set(permission.uid, permission);
5372
+ return permission;
5373
+ }
5374
+ async setPermissionSetting(uid, setting) {
5375
+ const permission = this.permissionList.get(uid);
5376
+ if (!permission) return void 0;
5377
+ permission.setting = setting;
5378
+ return permission;
5379
+ }
5380
+ async deletePermission(uid) {
5381
+ this.permissionList.delete(uid);
5382
+ }
5383
+ async clients() {
5384
+ return [...this.clientRecords.values()];
5385
+ }
5386
+ async createClient(input) {
5387
+ this.clientRecords.set(input.clientId, input);
5388
+ this.clientMap.set(input.clientId, {
5389
+ clientId: input.clientId,
5390
+ accessTokenExpiration: input.accessTokenExpiration,
5391
+ refreshTokenExpiration: input.refreshTokenExpiration
5392
+ });
5393
+ return input;
5394
+ }
5395
+ };
5396
+
5397
+ // src/corpus/drive.ts
5398
+ var success2 = { status: "success" };
5399
+ var bytes = (...values) => Uint8Array.from(values);
5400
+ var manyMembers = (count) => Array.from({ length: count }, (_, at) => ({
5401
+ name: `f${at}.txt`,
5402
+ type: "file",
5403
+ code: ""
5404
+ }));
5405
+ var DRIVE_CORPUS = [
5406
+ {
5407
+ id: "create-file",
5408
+ route: "POST /SASjsApi/drive/file",
5409
+ description: "creates a file the drive did not have",
5410
+ request: {
5411
+ query: { _filePath: "/data/users.csv" },
5412
+ file: { name: "users.csv", contents: "id,name\n1,Ann\n" }
5413
+ },
5414
+ expect: { status: 200, body: success2 }
5415
+ },
5416
+ {
5417
+ id: "create-file-at-form-path",
5418
+ route: "POST /SASjsApi/drive/file",
5419
+ description: "takes the destination from the form field when the query has none",
5420
+ request: {
5421
+ file: { name: "x.csv", contents: "x" },
5422
+ body: { filePath: "/data/from-form.csv" }
5423
+ },
5424
+ expect: { status: 200, body: success2 }
5425
+ },
5426
+ {
5427
+ id: "create-file-over-existing",
5428
+ route: "POST /SASjsApi/drive/file",
5429
+ description: "refuses a create over a file that exists, as 409",
5430
+ seed: { "/data/exists.csv": "a" },
5431
+ request: {
5432
+ query: { _filePath: "/data/exists.csv" },
5433
+ file: { name: "x", contents: "b" }
5434
+ },
5435
+ expect: { status: 409, error: "File already exists." }
5436
+ },
5437
+ {
5438
+ id: "create-file-blocked-extension",
5439
+ route: "POST /SASjsApi/drive/file",
5440
+ description: "refuses a refused extension before touching the drive",
5441
+ request: {
5442
+ query: { _filePath: "/data/run.sh" },
5443
+ file: { name: "run.sh", contents: "x" }
5444
+ },
5445
+ expect: { status: 400, error: "Invalid file extension" }
5446
+ },
5447
+ {
5448
+ id: "create-file-outside-drive",
5449
+ route: "POST /SASjsApi/drive/file",
5450
+ description: "refuses a path that climbs out of the drive",
5451
+ request: {
5452
+ query: { _filePath: "/../escape.csv" },
5453
+ file: { name: "x", contents: "x" }
5454
+ },
5455
+ expect: { status: 400, error: "Can't put file outside drive." }
5456
+ },
5457
+ {
5458
+ id: "create-file-without-payload",
5459
+ route: "POST /SASjsApi/drive/file",
5460
+ description: "answers for a missing file with the server wording",
5461
+ request: { query: { _filePath: "/data/x.csv" } },
5462
+ expect: { status: 400, error: '"file" is not present.' }
5463
+ },
5464
+ {
5465
+ id: "create-file-without-destination",
5466
+ route: "POST /SASjsApi/drive/file",
5467
+ description: "answers for a missing destination with the validation wording",
5468
+ request: { file: { name: "x", contents: "x" } },
5469
+ expect: { status: 400, error: '"_filePath" is required' }
5470
+ },
5471
+ {
5472
+ id: "replace-file",
5473
+ route: "PATCH /SASjsApi/drive/file",
5474
+ description: "replaces the contents of a file that exists",
5475
+ seed: { "/data/keep.csv": "old" },
5476
+ request: {
5477
+ query: { _filePath: "/data/keep.csv" },
5478
+ file: { name: "keep.csv", contents: "new" }
5479
+ },
5480
+ expect: { status: 200, body: success2 }
5481
+ },
5482
+ {
5483
+ id: "replace-file-missing",
5484
+ route: "PATCH /SASjsApi/drive/file",
5485
+ description: "refuses a replace of a file that is not there, as 404",
5486
+ request: {
5487
+ query: { _filePath: "/data/missing.csv" },
5488
+ file: { name: "x", contents: "x" }
5489
+ },
5490
+ expect: { status: 404, error: `File doesn't exist.` }
5491
+ },
5492
+ {
5493
+ id: "replace-file-outside-drive",
5494
+ route: "PATCH /SASjsApi/drive/file",
5495
+ description: "refuses a replace of a path that climbs out of the drive",
5496
+ request: {
5497
+ query: { _filePath: "/../escape.csv" },
5498
+ file: { name: "x", contents: "x" }
5499
+ },
5500
+ expect: { status: 400, error: "Can't modify file outside drive." }
5501
+ },
5502
+ {
5503
+ id: "read-file",
5504
+ route: "GET /SASjsApi/drive/file",
5505
+ description: "answers with the file contents",
5506
+ seed: { "/data/keep.csv": "a,b\n1,2\n" },
5507
+ request: { query: { _filePath: "/data/keep.csv" } },
5508
+ expect: { status: 200, contents: "a,b\n1,2\n" }
5509
+ },
5510
+ {
5511
+ id: "read-file-missing",
5512
+ route: "GET /SASjsApi/drive/file",
5513
+ description: "refuses a read of a file that is not there",
5514
+ request: { query: { _filePath: "/data/missing.csv" } },
5515
+ expect: { status: 404, error: `File doesn't exist.` }
5516
+ },
5517
+ {
5518
+ id: "read-file-outside-drive",
5519
+ route: "GET /SASjsApi/drive/file",
5520
+ description: "refuses a read of a path that climbs out of the drive",
5521
+ request: { query: { _filePath: "/../escape.csv" } },
5522
+ expect: { status: 400, error: "Can't get file outside drive." }
5523
+ },
5524
+ {
5525
+ id: "delete-file",
5526
+ route: "DELETE /SASjsApi/drive/file",
5527
+ description: "deletes a file that exists",
5528
+ seed: { "/data/keep.csv": "a" },
5529
+ request: { query: { _filePath: "/data/keep.csv" } },
5530
+ expect: { status: 200, body: success2 }
5531
+ },
5532
+ {
5533
+ id: "delete-file-missing",
5534
+ route: "DELETE /SASjsApi/drive/file",
5535
+ description: "refuses a delete of a file that is not there",
5536
+ request: { query: { _filePath: "/data/missing.csv" } },
5537
+ expect: { status: 404, error: `File doesn't exist.` }
5538
+ },
5539
+ {
5540
+ id: "delete-file-outside-drive",
5541
+ route: "DELETE /SASjsApi/drive/file",
5542
+ description: "refuses a delete of a path that climbs out of the drive",
5543
+ request: { query: { _filePath: "/../escape.csv" } },
5544
+ expect: { status: 400, error: "Can't delete file outside drive." }
5545
+ },
5546
+ {
5547
+ id: "list-folder",
5548
+ route: "GET /SASjsApi/drive/folder",
5549
+ description: "lists the files and folders of a folder",
5550
+ seed: { "/data/a.csv": "a", "/data/reports/b.csv": "b" },
5551
+ request: { query: { _folderPath: "/data" } },
5552
+ expect: { status: 200, body: { files: ["a.csv"], folders: ["reports"] } }
5553
+ },
5554
+ {
5555
+ id: "list-folder-missing",
5556
+ route: "GET /SASjsApi/drive/folder",
5557
+ description: "refuses a listing of a folder that is not there",
5558
+ request: { query: { _folderPath: "/nope" } },
5559
+ expect: { status: 404, error: `Folder doesn't exist.` }
5560
+ },
5561
+ {
5562
+ id: "list-folder-outside-drive",
5563
+ route: "GET /SASjsApi/drive/folder",
5564
+ description: "refuses a listing of a path that climbs out of the drive",
5565
+ request: { query: { _folderPath: "/../escape" } },
5566
+ expect: { status: 400, error: "Can't get folder outside drive." }
5567
+ },
5568
+ {
5569
+ id: "delete-folder-without-path",
5570
+ route: "DELETE /SASjsApi/drive/folder",
5571
+ description: "answers for a missing folder path, because the table marks it required",
5572
+ request: {},
5573
+ expect: { status: 400, error: '"_folderPath" is required' }
5574
+ },
5575
+ {
5576
+ id: "create-folder-without-path",
5577
+ route: "POST /SASjsApi/drive/folder",
5578
+ description: "answers for a missing folder path in the body",
5579
+ request: { body: {} },
5580
+ expect: { status: 400, error: '"folderPath" is required' }
5581
+ },
5582
+ {
5583
+ id: "create-folder",
5584
+ route: "POST /SASjsApi/drive/folder",
5585
+ description: "creates a folder",
5586
+ request: { body: { folderPath: "/data/reports" } },
5587
+ expect: { status: 200, body: success2 }
5588
+ },
5589
+ {
5590
+ id: "create-folder-existing",
5591
+ route: "POST /SASjsApi/drive/folder",
5592
+ description: "refuses a folder that already exists, as 409",
5593
+ seed: { "/data/reports/a.csv": "a" },
5594
+ request: { body: { folderPath: "/data/reports" } },
5595
+ expect: { status: 409, error: "Folder already exists." }
5596
+ },
5597
+ {
5598
+ id: "delete-folder",
5599
+ route: "DELETE /SASjsApi/drive/folder",
5600
+ description: "deletes a folder with everything under it",
5601
+ seed: { "/data/reports/a.csv": "a", "/data/reports/nested/b.csv": "b" },
5602
+ request: { query: { _folderPath: "/data/reports" } },
5603
+ expect: { status: 200, body: success2 }
5604
+ },
5605
+ {
5606
+ id: "delete-folder-missing",
5607
+ route: "DELETE /SASjsApi/drive/folder",
5608
+ description: "refuses a delete of a folder that is not there",
5609
+ request: { query: { _folderPath: "/nope" } },
5610
+ expect: { status: 404, error: `Folder doesn't exist.` }
5611
+ },
5612
+ {
5613
+ id: "rename-file",
5614
+ route: "POST /SASjsApi/drive/rename",
5615
+ description: "moves a file to a new path",
5616
+ seed: { "/data/old.csv": "r" },
5617
+ request: { body: { oldPath: "/data/old.csv", newPath: "/data/new.csv" } },
5618
+ expect: { status: 200, body: success2 }
5619
+ },
5620
+ {
5621
+ id: "rename-onto-existing",
5622
+ route: "POST /SASjsApi/drive/rename",
5623
+ description: "refuses a move onto something that exists",
5624
+ seed: { "/data/a.csv": "a", "/data/b.csv": "b" },
5625
+ request: { body: { oldPath: "/data/a.csv", newPath: "/data/b.csv" } },
5626
+ expect: { status: 409, error: "File with new name already exists." }
5627
+ },
5628
+ {
5629
+ id: "rename-missing",
5630
+ route: "POST /SASjsApi/drive/rename",
5631
+ description: "refuses a move of something that is not there",
5632
+ request: { body: { oldPath: "/data/nope.csv", newPath: "/data/x.csv" } },
5633
+ expect: { status: 404, error: "No file/folder found for provided path." }
5634
+ },
5635
+ {
5636
+ id: "rename-file-to-blocked-extension",
5637
+ route: "POST /SASjsApi/drive/rename",
5638
+ description: "refuses a rename that would produce a name the file routes refuse",
5639
+ seed: { "/data/report.csv": "a,b" },
5640
+ request: {
5641
+ body: { oldPath: "/data/report.csv", newPath: "/data/report.sh" }
5642
+ },
5643
+ expect: { status: 400, error: "Invalid file extension" }
5644
+ },
5645
+ {
5646
+ id: "rename-folder-to-dotted-name",
5647
+ route: "POST /SASjsApi/drive/rename",
5648
+ description: "renames a folder whose new name carries a blocked suffix",
5649
+ seed: { "/data/reports/a.csv": "a" },
5650
+ request: {
5651
+ body: { oldPath: "/data/reports", newPath: "/data/reports.sh" }
5652
+ },
5653
+ expect: { status: 200, body: { status: "success" } }
5654
+ },
5655
+ {
5656
+ id: "rename-folder-into-itself",
5657
+ route: "POST /SASjsApi/drive/rename",
5658
+ description: "refuses a folder moved inside itself, which the server loses at the filesystem",
5659
+ seed: { "/data/reports/a.csv": "a" },
5660
+ request: {
5661
+ body: { oldPath: "/data/reports", newPath: "/data/reports/nested" }
5662
+ },
5663
+ expect: {
5664
+ status: 400,
5665
+ error: "New path can't be inside the folder being moved."
5666
+ }
5667
+ },
5668
+ {
5669
+ id: "tree",
5670
+ route: "GET /SASjsApi/drive/filetree",
5671
+ description: "answers with the drive tree",
5672
+ seed: { "/data/a.csv": "a" },
5673
+ request: { query: { _folderPath: "/data" } },
5674
+ expect: {
5675
+ status: 200,
5676
+ body: {
5677
+ status: "success",
5678
+ tree: {
5679
+ name: "data",
5680
+ relativePath: "/data",
5681
+ isFolder: true,
5682
+ children: [
5683
+ {
5684
+ name: "a.csv",
5685
+ relativePath: "/data/a.csv",
5686
+ isFolder: false,
5687
+ children: []
5688
+ }
5689
+ ]
5690
+ }
5691
+ }
5692
+ }
5693
+ },
5694
+ {
5695
+ id: "deploy-tree",
5696
+ route: "POST /SASjsApi/drive/deploy",
5697
+ description: "writes a whole tree under the appLoc it names",
5698
+ request: {
5699
+ body: {
5700
+ appLoc: "/Public/apps/demo",
5701
+ fileTree: {
5702
+ members: [
5703
+ {
5704
+ name: "services",
5705
+ type: "folder",
5706
+ members: [{ name: "run", type: "service", code: "%put hi;" }]
5707
+ },
5708
+ { name: "index.html", type: "file", code: "PGgxPkhlbGxvPC9oMT4=" }
5709
+ ]
5710
+ }
5711
+ }
5712
+ },
5713
+ expect: {
5714
+ status: 200,
5715
+ body: {
5716
+ status: "success",
5717
+ message: "Files deployed successfully to @sasjs/server."
5718
+ }
5719
+ }
5720
+ },
5721
+ {
5722
+ id: "deploy-refused-by-entry-count",
5723
+ route: "POST /SASjsApi/drive/deploy",
5724
+ description: "refuses a tree over the entry cap, naming the figure and the cap",
5725
+ request: {
5726
+ body: {
5727
+ appLoc: "/Public/apps/many",
5728
+ fileTree: { members: manyMembers(10001) }
5729
+ }
5730
+ },
5731
+ expect: {
5732
+ status: 413,
5733
+ body: {
5734
+ status: "failure",
5735
+ message: "The file tree exceeds the deploy limit: 10001 entries (maximum 10000)."
5736
+ },
5737
+ error: "The file tree exceeds the deploy limit: 10001 entries (maximum 10000)."
5738
+ }
5739
+ },
5740
+ {
5741
+ id: "deploy-refused-by-name",
5742
+ route: "POST /SASjsApi/drive/deploy",
5743
+ description: "refuses a member name that would escape the deployment root",
5744
+ request: {
5745
+ body: {
5746
+ appLoc: "/Public/apps/hostile",
5747
+ fileTree: {
5748
+ members: [{ name: "../escape", type: "service", code: "%put hi;" }]
5749
+ }
5750
+ }
5751
+ },
5752
+ expect: {
5753
+ status: 400,
5754
+ body: {
5755
+ status: "failure",
5756
+ message: "Invalid member name: '../escape.sas'. Member names must be single path segments (no '/', '\\', '..')."
5757
+ },
5758
+ error: "Invalid member name: '../escape.sas'. Member names must be single path segments (no '/', '\\', '..')."
5759
+ }
5760
+ },
5761
+ {
5762
+ id: "deploy-refused-by-shape",
5763
+ route: "POST /SASjsApi/drive/deploy",
5764
+ description: "refuses a fileTree that is not a tree, in the routes own envelope",
5765
+ request: { body: { appLoc: "/Public/apps/bad", fileTree: { members: 1 } } },
5766
+ expect: {
5767
+ status: 400,
5768
+ body: {
5769
+ status: "failure",
5770
+ message: "Provided not supported data format."
5771
+ },
5772
+ error: "Provided not supported data format."
5773
+ }
5774
+ },
5775
+ {
5776
+ id: "deploy-refused-by-store",
5777
+ route: "POST /SASjsApi/drive/deploy",
5778
+ description: "answers the routes 500 when the drive refuses the write",
5779
+ unwritable: true,
5780
+ request: {
5781
+ body: {
5782
+ appLoc: "/Public/apps/demo",
5783
+ fileTree: {
5784
+ members: [{ name: "run", type: "service", code: "%put hi;" }]
5785
+ }
5786
+ }
5787
+ },
5788
+ expect: {
5789
+ status: 500,
5790
+ body: { status: "failure", message: "Deployment failed!" },
5791
+ error: "Deployment failed!"
5792
+ }
5793
+ },
5794
+ {
5795
+ id: "deploy-refused-outside-drive",
5796
+ route: "POST /SASjsApi/drive/deploy",
5797
+ description: "refuses an appLoc that resolves outside the drive",
5798
+ request: {
5799
+ body: { appLoc: "/../outside", fileTree: { members: [] } }
5800
+ },
5801
+ expect: {
5802
+ status: 400,
5803
+ body: { status: "failure", message: "appLoc cannot be outside drive." },
5804
+ error: "appLoc cannot be outside drive."
5805
+ }
5806
+ },
5807
+ {
5808
+ id: "bytes-round-trip",
5809
+ route: "GET /SASjsApi/drive/file",
5810
+ description: "keeps a byte file as bytes",
5811
+ seed: { "/data/pack.zip": bytes(80, 75, 3, 4) },
5812
+ request: { query: { _filePath: "/data/pack.zip" } },
5813
+ expect: { status: 200, contents: bytes(80, 75, 3, 4) }
5814
+ }
5815
+ ];
5816
+
5817
+ // src/corpus/identity.ts
5818
+ var SIGNED_IN = {
5819
+ ...DEFAULT_IDENTITY,
5820
+ tokens: [
5821
+ {
5822
+ username: "sasjsuser",
5823
+ clientId: "web_app",
5824
+ accessToken: "seed-access",
5825
+ refreshToken: "seed-refresh"
5826
+ },
5827
+ {
5828
+ username: "sasjsadmin",
5829
+ clientId: "removed_client",
5830
+ accessToken: "seed-access-orphan",
5831
+ refreshToken: "seed-refresh-orphan"
5832
+ }
5833
+ ],
5834
+ codes: [
5835
+ { code: "seed-code", username: "sasjsuser", clientId: "web_app" },
5836
+ {
5837
+ code: "seed-orphan-code",
5838
+ username: "sasjsuser",
5839
+ clientId: "removed_client"
5840
+ },
5841
+ // the same shape with a pair already issued: the exchange must still refuse,
5842
+ // rather than handing back tokens that belong to a client that is gone
5843
+ {
5844
+ code: "seed-orphan-pair-code",
5845
+ username: "sasjsadmin",
5846
+ clientId: "removed_client"
5847
+ }
5848
+ ]
5849
+ };
5850
+ var DEACTIVATED = {
5851
+ ...SIGNED_IN,
5852
+ users: SIGNED_IN.users.map(
5853
+ (user3) => user3.username === "sasjsuser" ? { ...user3, isActive: false } : user3
5854
+ )
5855
+ };
5856
+ var user2 = {
5857
+ username: "sasjsuser",
5858
+ displayName: "Demo User",
5859
+ isAdmin: false,
5860
+ needsToUpdatePassword: false
5861
+ };
5862
+ var IDENTITY_CORPUS = [
5863
+ {
5864
+ id: "login",
5865
+ route: "POST /SASLogon/login",
5866
+ description: "signs a seeded user in",
5867
+ request: { body: { username: "sasjsadmin", password: "Orion123" } },
5868
+ expect: {
5869
+ status: 200,
5486
5870
  partial: {
5487
5871
  loggedIn: true,
5488
5872
  user: {
5489
- username: "admin",
5873
+ username: "sasjsadmin",
5490
5874
  displayName: "Demo Admin",
5491
5875
  isAdmin: true,
5492
5876
  needsToUpdatePassword: false
@@ -5498,7 +5882,7 @@ var SASjsApi = (() => {
5498
5882
  id: "login-missing-username",
5499
5883
  route: "POST /SASLogon/login",
5500
5884
  description: "refuses a sign-in with no username as 400, naming the field",
5501
- request: { body: { password: "admin123" } },
5885
+ request: { body: { password: "Orion123" } },
5502
5886
  expect: { status: 400, error: '"username" is required' }
5503
5887
  },
5504
5888
  {
@@ -5506,21 +5890,21 @@ var SASjsApi = (() => {
5506
5890
  route: "POST /SASLogon/login",
5507
5891
  description: "refuses a deactivated account, naming it",
5508
5892
  identity: DEACTIVATED,
5509
- request: { body: { username: "user2", password: "user123" } },
5893
+ request: { body: { username: "sasjsuser", password: "Orion123" } },
5510
5894
  expect: { status: 401, error: "This account is not active." }
5511
5895
  },
5512
5896
  {
5513
5897
  id: "login-wrong-password",
5514
5898
  route: "POST /SASLogon/login",
5515
5899
  description: "refuses a wrong password as 401, naming it",
5516
- request: { body: { username: "admin", password: "wrong123" } },
5900
+ request: { body: { username: "sasjsadmin", password: "wrong123" } },
5517
5901
  expect: { status: 401, error: "Invalid Password." }
5518
5902
  },
5519
5903
  {
5520
5904
  id: "login-unknown-user",
5521
5905
  route: "POST /SASLogon/login",
5522
5906
  description: "refuses an unknown username as 401, naming it",
5523
- request: { body: { username: "nobody", password: "admin123" } },
5907
+ request: { body: { username: "nobody", password: "Orion123" } },
5524
5908
  expect: { status: 401, error: "Username is not found." }
5525
5909
  },
5526
5910
  {
@@ -6528,13 +6912,13 @@ var SASjsApi = (() => {
6528
6912
  // src/corpus/records.ts
6529
6913
  var SIGNED_IN_TOKENS = [
6530
6914
  {
6531
- username: "admin",
6915
+ username: "sasjsadmin",
6532
6916
  clientId: "web_app",
6533
6917
  accessToken: "admin-access",
6534
6918
  refreshToken: "admin-refresh"
6535
6919
  },
6536
6920
  {
6537
- username: "user2",
6921
+ username: "sasjsuser",
6538
6922
  clientId: "web_app",
6539
6923
  accessToken: "user-access",
6540
6924
  refreshToken: "user-refresh"
@@ -6604,13 +6988,13 @@ var SASjsApi = (() => {
6604
6988
  body: [
6605
6989
  {
6606
6990
  uid: ADMIN_UID,
6607
- username: "admin",
6991
+ username: "sasjsadmin",
6608
6992
  displayName: "Demo Admin",
6609
6993
  isAdmin: true
6610
6994
  },
6611
6995
  {
6612
6996
  uid: RESTRICTED_UID,
6613
- username: "user2",
6997
+ username: "sasjsuser",
6614
6998
  displayName: "Demo User",
6615
6999
  isAdmin: false
6616
7000
  }
@@ -6627,7 +7011,7 @@ var SASjsApi = (() => {
6627
7011
  status: 200,
6628
7012
  partial: {
6629
7013
  uid: RESTRICTED_UID,
6630
- username: "user2",
7014
+ username: "sasjsuser",
6631
7015
  isActive: true,
6632
7016
  isAdmin: false,
6633
7017
  autoExec: ""
@@ -6655,10 +7039,10 @@ var SASjsApi = (() => {
6655
7039
  route: "GET /SASjsApi/user/by/username/{username}",
6656
7040
  description: "finds an account by username",
6657
7041
  identity: ADMIN_SIGNED_IN,
6658
- request: { token: ADMIN3, params: { username: "user2" } },
7042
+ request: { token: ADMIN3, params: { username: "sasjsuser" } },
6659
7043
  expect: {
6660
7044
  status: 200,
6661
- partial: { uid: RESTRICTED_UID, username: "user2", isAdmin: false }
7045
+ partial: { uid: RESTRICTED_UID, username: "sasjsuser", isAdmin: false }
6662
7046
  }
6663
7047
  },
6664
7048
  {
@@ -6666,7 +7050,7 @@ var SASjsApi = (() => {
6666
7050
  route: "GET /SASjsApi/user/by/username/{username}",
6667
7051
  description: "refuses the by-username read with no caller",
6668
7052
  identity: ADMIN_SIGNED_IN,
6669
- request: { params: { username: "user2" } },
7053
+ request: { params: { username: "sasjsuser" } },
6670
7054
  expect: { status: 401, error: "Unauthorized" }
6671
7055
  },
6672
7056
  {
@@ -6732,7 +7116,11 @@ var SASjsApi = (() => {
6732
7116
  identity: ADMIN_SIGNED_IN,
6733
7117
  request: {
6734
7118
  token: ADMIN3,
6735
- body: { username: "user2", displayName: "Another", password: "newpass" }
7119
+ body: {
7120
+ username: "sasjsuser",
7121
+ displayName: "Another",
7122
+ password: "newpass"
7123
+ }
6736
7124
  },
6737
7125
  expect: { status: 409, error: "Username already exists." }
6738
7126
  },
@@ -6746,8 +7134,8 @@ var SASjsApi = (() => {
6746
7134
  params: { uid: RESTRICTED_UID },
6747
7135
  body: {
6748
7136
  displayName: "Renamed User",
6749
- username: "user2",
6750
- password: "user123"
7137
+ username: "sasjsuser",
7138
+ password: "Orion123"
6751
7139
  }
6752
7140
  },
6753
7141
  expect: {
@@ -6763,7 +7151,11 @@ var SASjsApi = (() => {
6763
7151
  request: {
6764
7152
  token: RESTRICTED2,
6765
7153
  params: { uid: ADMIN_UID },
6766
- body: { displayName: "Hijacked", username: "admin", password: "admin123" }
7154
+ body: {
7155
+ displayName: "Hijacked",
7156
+ username: "sasjsadmin",
7157
+ password: "Orion123"
7158
+ }
6767
7159
  },
6768
7160
  expect: { status: 401, error: "Admin account required" }
6769
7161
  },
@@ -6806,7 +7198,11 @@ var SASjsApi = (() => {
6806
7198
  request: {
6807
7199
  token: ADMIN3,
6808
7200
  params: { uid: RESTRICTED_UID },
6809
- body: { username: "admin", displayName: "Demo User", password: "user123" }
7201
+ body: {
7202
+ username: "sasjsadmin",
7203
+ displayName: "Demo User",
7204
+ password: "Orion123"
7205
+ }
6810
7206
  },
6811
7207
  expect: { status: 409, error: "Username already exists." }
6812
7208
  },
@@ -6817,15 +7213,15 @@ var SASjsApi = (() => {
6817
7213
  identity: ADMIN_SIGNED_IN,
6818
7214
  request: {
6819
7215
  token: ADMIN3,
6820
- params: { username: "user2" },
7216
+ params: { username: "sasjsuser" },
6821
7217
  body: {
6822
7218
  isActive: false,
6823
- username: "user2",
7219
+ username: "sasjsuser",
6824
7220
  displayName: "Demo User",
6825
- password: "user123"
7221
+ password: "Orion123"
6826
7222
  }
6827
7223
  },
6828
- expect: { status: 200, partial: { username: "user2", isActive: false } }
7224
+ expect: { status: 200, partial: { username: "sasjsuser", isActive: false } }
6829
7225
  },
6830
7226
  {
6831
7227
  id: "update-user-by-username-not-admin",
@@ -6834,8 +7230,12 @@ var SASjsApi = (() => {
6834
7230
  identity: ADMIN_SIGNED_IN,
6835
7231
  request: {
6836
7232
  token: RESTRICTED2,
6837
- params: { username: "admin" },
6838
- body: { displayName: "Hijacked", username: "admin", password: "admin123" }
7233
+ params: { username: "sasjsadmin" },
7234
+ body: {
7235
+ displayName: "Hijacked",
7236
+ username: "sasjsadmin",
7237
+ password: "Orion123"
7238
+ }
6839
7239
  },
6840
7240
  expect: { status: 401, error: "Admin account required" }
6841
7241
  },
@@ -6873,8 +7273,12 @@ var SASjsApi = (() => {
6873
7273
  identity: ADMIN_SIGNED_IN,
6874
7274
  request: {
6875
7275
  token: ADMIN3,
6876
- params: { username: "user2" },
6877
- body: { username: "admin", displayName: "Demo User", password: "user123" }
7276
+ params: { username: "sasjsuser" },
7277
+ body: {
7278
+ username: "sasjsadmin",
7279
+ displayName: "Demo User",
7280
+ password: "Orion123"
7281
+ }
6878
7282
  },
6879
7283
  expect: { status: 409, error: "Username already exists." }
6880
7284
  },
@@ -6909,7 +7313,7 @@ var SASjsApi = (() => {
6909
7313
  identity: ADMIN_SIGNED_IN,
6910
7314
  request: {
6911
7315
  token: ADMIN3,
6912
- params: { username: "user2" },
7316
+ params: { username: "sasjsuser" },
6913
7317
  body: {}
6914
7318
  },
6915
7319
  expect: { status: 200, body: "Account Deleted!" }
@@ -6921,7 +7325,7 @@ var SASjsApi = (() => {
6921
7325
  identity: ADMIN_SIGNED_IN,
6922
7326
  request: {
6923
7327
  token: RESTRICTED2,
6924
- params: { username: "user2" },
7328
+ params: { username: "sasjsuser" },
6925
7329
  body: { password: "wrong123" }
6926
7330
  },
6927
7331
  expect: { status: 401, error: "Invalid password." }
@@ -6972,7 +7376,7 @@ var SASjsApi = (() => {
6972
7376
  users: [
6973
7377
  {
6974
7378
  uid: ADMIN_UID,
6975
- username: "admin",
7379
+ username: "sasjsadmin",
6976
7380
  displayName: "Demo Admin",
6977
7381
  isAdmin: true
6978
7382
  }
@@ -7359,765 +7763,395 @@ var SASjsApi = (() => {
7359
7763
  }
7360
7764
  },
7361
7765
  {
7362
- id: "list-permissions-unauthenticated",
7363
- route: "GET /SASjsApi/permission",
7364
- description: "refuses the list with no caller",
7365
- identity: ADMIN_SIGNED_IN,
7366
- request: {},
7367
- expect: { status: 401, error: "Unauthorized" }
7368
- },
7369
- {
7370
- id: "create-permission-user",
7371
- route: "POST /SASjsApi/permission",
7372
- description: "creates a rule for a user",
7373
- identity: ADMIN_SIGNED_IN,
7374
- request: {
7375
- token: ADMIN3,
7376
- body: {
7377
- path: "/SASjsApi/drive/folder",
7378
- type: "Route",
7379
- setting: "Grant",
7380
- principalType: "user",
7381
- principalId: RESTRICTED_UID
7382
- }
7383
- },
7384
- expect: {
7385
- status: 200,
7386
- partial: { path: "/SASjsApi/drive/folder", setting: "Grant" }
7387
- }
7388
- },
7389
- {
7390
- id: "create-permission-group",
7391
- route: "POST /SASjsApi/permission",
7392
- description: "creates a rule for a group",
7393
- identity: ADMIN_SIGNED_IN,
7394
- request: {
7395
- token: ADMIN3,
7396
- body: {
7397
- path: "/SASjsApi/drive/rename",
7398
- type: "Route",
7399
- setting: "Grant",
7400
- principalType: "group",
7401
- principalId: "group-data-controller"
7402
- }
7403
- },
7404
- expect: {
7405
- status: 200,
7406
- partial: {
7407
- path: "/SASjsApi/drive/rename",
7408
- setting: "Grant",
7409
- group: "group-data-controller"
7410
- }
7411
- }
7412
- },
7413
- {
7414
- id: "create-permission-invalid-principal-type",
7415
- route: "POST /SASjsApi/permission",
7416
- description: "refuses a principal type that is neither a user nor a group",
7417
- identity: ADMIN_SIGNED_IN,
7418
- request: {
7419
- token: ADMIN3,
7420
- body: {
7421
- path: "/SASjsApi/drive/deploy",
7422
- type: "Route",
7423
- setting: "Grant",
7424
- principalType: "role",
7425
- principalId: "anything"
7426
- }
7427
- },
7428
- expect: {
7429
- status: 400,
7430
- error: "Invalid principal type. Valid types are user or group."
7431
- }
7432
- },
7433
- {
7434
- id: "create-permission-admin-principal",
7435
- route: "POST /SASjsApi/permission",
7436
- description: "refuses a rule assigned to an administrator",
7437
- identity: ADMIN_SIGNED_IN,
7438
- request: {
7439
- token: ADMIN3,
7440
- body: {
7441
- path: "/SASjsApi/drive/folder",
7442
- type: "Route",
7443
- setting: "Grant",
7444
- principalType: "user",
7445
- principalId: ADMIN_UID
7446
- }
7447
- },
7448
- expect: {
7449
- status: 400,
7450
- error: "Can not add permission for admin user."
7451
- }
7452
- },
7453
- {
7454
- id: "create-permission-not-admin",
7455
- route: "POST /SASjsApi/permission",
7456
- description: "refuses a creation by a non-administrator",
7457
- identity: ADMIN_SIGNED_IN,
7458
- request: {
7459
- token: RESTRICTED2,
7460
- body: {
7461
- path: "/SASjsApi/drive/folder",
7462
- type: "Route",
7463
- setting: "Grant",
7464
- principalType: "user",
7465
- principalId: RESTRICTED_UID
7466
- }
7467
- },
7468
- expect: { status: 401, error: "Admin account required" }
7469
- },
7470
- {
7471
- id: "create-permission-missing-principal",
7472
- route: "POST /SASjsApi/permission",
7473
- description: "answers 404 for a principal that does not exist",
7474
- identity: ADMIN_SIGNED_IN,
7475
- request: {
7476
- token: ADMIN3,
7477
- body: {
7478
- path: "/SASjsApi/drive/rename",
7479
- type: "Route",
7480
- setting: "Grant",
7481
- principalType: "group",
7482
- principalId: "group-none"
7483
- }
7484
- },
7485
- expect: { status: 404, error: "Group not found." }
7486
- },
7487
- {
7488
- id: "create-permission-duplicate-group",
7489
- route: "POST /SASjsApi/permission",
7490
- description: "refuses a group rule that already exists",
7491
- identity: ADMIN_SIGNED_IN,
7492
- request: {
7493
- token: ADMIN3,
7494
- body: {
7495
- path: "/SASjsApi/drive/file",
7496
- type: "Route",
7497
- setting: "Grant",
7498
- principalType: "group",
7499
- principalId: "group-data-controller"
7500
- }
7501
- },
7502
- expect: {
7503
- status: 409,
7504
- error: "Permission already exists with provided Path, Type and Group."
7505
- }
7506
- },
7507
- {
7508
- id: "create-permission-duplicate",
7509
- route: "POST /SASjsApi/permission",
7510
- description: "refuses a rule that already exists",
7511
- identity: ADMIN_SIGNED_IN,
7512
- request: {
7513
- token: ADMIN3,
7514
- body: {
7515
- path: "/SASjsApi/code/execute",
7516
- type: "Route",
7517
- setting: "Deny",
7518
- principalType: "user",
7519
- principalId: RESTRICTED_UID
7520
- }
7521
- },
7522
- expect: {
7523
- status: 409,
7524
- error: "Permission already exists with provided Path, Type and User."
7525
- }
7526
- },
7527
- {
7528
- id: "update-permission",
7529
- route: "PATCH /SASjsApi/permission/{uid}",
7530
- description: "flips a rule from Deny to Grant",
7531
- identity: ADMIN_SIGNED_IN,
7532
- request: {
7533
- token: ADMIN3,
7534
- params: { uid: "rule-code" },
7535
- body: { setting: "Grant" }
7536
- },
7537
- expect: { status: 200, partial: { uid: "rule-code", setting: "Grant" } }
7538
- },
7539
- {
7540
- id: "update-permission-not-admin",
7541
- route: "PATCH /SASjsApi/permission/{uid}",
7542
- description: "refuses a change by a non-administrator",
7543
- identity: ADMIN_SIGNED_IN,
7544
- request: {
7545
- token: RESTRICTED2,
7546
- params: { uid: "rule-code" },
7547
- body: { setting: "Grant" }
7548
- },
7549
- expect: { status: 401, error: "Admin account required" }
7550
- },
7551
- {
7552
- id: "update-permission-missing",
7553
- route: "PATCH /SASjsApi/permission/{uid}",
7554
- description: "answers 404 for a rule that does not exist",
7555
- identity: ADMIN_SIGNED_IN,
7556
- request: {
7557
- token: ADMIN3,
7558
- params: { uid: "rule-none" },
7559
- body: { setting: "Grant" }
7560
- },
7561
- expect: { status: 404, error: "Permission not found." }
7562
- },
7563
- {
7564
- id: "delete-permission",
7565
- route: "DELETE /SASjsApi/permission/{uid}",
7566
- description: "deletes a rule",
7567
- identity: ADMIN_SIGNED_IN,
7568
- request: { token: ADMIN3, params: { uid: "rule-code" } },
7569
- expect: { status: 200, body: "Permission Deleted!" }
7570
- },
7571
- {
7572
- id: "delete-permission-not-admin",
7573
- route: "DELETE /SASjsApi/permission/{uid}",
7574
- description: "refuses a deletion by a non-administrator",
7575
- identity: ADMIN_SIGNED_IN,
7576
- request: { token: RESTRICTED2, params: { uid: "rule-code" } },
7577
- expect: { status: 401, error: "Admin account required" }
7578
- },
7579
- {
7580
- id: "delete-permission-missing",
7581
- route: "DELETE /SASjsApi/permission/{uid}",
7582
- description: "answers 404 for a rule that does not exist",
7583
- identity: ADMIN_SIGNED_IN,
7584
- request: { token: ADMIN3, params: { uid: "rule-none" } },
7585
- expect: { status: 404, error: "Permission not found." }
7586
- },
7587
- // --------------------------------------------------------------- clients
7588
- {
7589
- id: "list-clients",
7590
- route: "GET /SASjsApi/client",
7591
- description: "lists the registered clients",
7592
- identity: ADMIN_SIGNED_IN,
7593
- request: { token: ADMIN3 },
7594
- expect: {
7595
- status: 200,
7596
- body: [
7597
- {
7598
- clientId: "web_app",
7599
- clientSecret: "web_app",
7600
- accessTokenExpiration: 86400,
7601
- refreshTokenExpiration: 2592e3
7602
- },
7603
- {
7604
- clientId: "sasjs",
7605
- clientSecret: "sasjs",
7606
- accessTokenExpiration: 3600,
7607
- refreshTokenExpiration: 86400
7608
- }
7609
- ]
7610
- }
7611
- },
7612
- {
7613
- id: "list-clients-not-admin",
7614
- route: "GET /SASjsApi/client",
7615
- description: "refuses the list to a caller who is not an administrator",
7766
+ id: "list-permissions-unauthenticated",
7767
+ route: "GET /SASjsApi/permission",
7768
+ description: "refuses the list with no caller",
7616
7769
  identity: ADMIN_SIGNED_IN,
7617
- request: { token: RESTRICTED2 },
7618
- expect: { status: 401, error: "Admin account required" }
7770
+ request: {},
7771
+ expect: { status: 401, error: "Unauthorized" }
7619
7772
  },
7620
7773
  {
7621
- id: "create-client",
7622
- route: "POST /SASjsApi/client",
7623
- description: "registers a client",
7774
+ id: "create-permission-user",
7775
+ route: "POST /SASjsApi/permission",
7776
+ description: "creates a rule for a user",
7624
7777
  identity: ADMIN_SIGNED_IN,
7625
7778
  request: {
7626
7779
  token: ADMIN3,
7627
7780
  body: {
7628
- clientId: "new_app",
7629
- clientSecret: "new_secret",
7630
- accessTokenExpiration: 3600,
7631
- refreshTokenExpiration: 86400
7781
+ path: "/SASjsApi/drive/folder",
7782
+ type: "Route",
7783
+ setting: "Grant",
7784
+ principalType: "user",
7785
+ principalId: RESTRICTED_UID
7632
7786
  }
7633
7787
  },
7634
7788
  expect: {
7635
7789
  status: 200,
7636
- body: {
7637
- clientId: "new_app",
7638
- clientSecret: "new_secret",
7639
- accessTokenExpiration: 3600,
7640
- refreshTokenExpiration: 86400
7641
- }
7790
+ partial: { path: "/SASjsApi/drive/folder", setting: "Grant" }
7642
7791
  }
7643
7792
  },
7644
7793
  {
7645
- id: "create-client-defaults",
7646
- route: "POST /SASjsApi/client",
7647
- description: "applies the schema defaults when the lifetimes are omitted",
7794
+ id: "create-permission-group",
7795
+ route: "POST /SASjsApi/permission",
7796
+ description: "creates a rule for a group",
7648
7797
  identity: ADMIN_SIGNED_IN,
7649
7798
  request: {
7650
7799
  token: ADMIN3,
7651
- body: { clientId: "default_app", clientSecret: "default_secret" }
7800
+ body: {
7801
+ path: "/SASjsApi/drive/rename",
7802
+ type: "Route",
7803
+ setting: "Grant",
7804
+ principalType: "group",
7805
+ principalId: "group-data-controller"
7806
+ }
7652
7807
  },
7653
7808
  expect: {
7654
7809
  status: 200,
7655
- body: {
7656
- clientId: "default_app",
7657
- clientSecret: "default_secret",
7658
- accessTokenExpiration: 86400,
7659
- refreshTokenExpiration: 2592e3
7810
+ partial: {
7811
+ path: "/SASjsApi/drive/rename",
7812
+ setting: "Grant",
7813
+ group: "group-data-controller"
7660
7814
  }
7661
7815
  }
7662
7816
  },
7663
7817
  {
7664
- id: "create-client-not-admin",
7665
- route: "POST /SASjsApi/client",
7666
- description: "refuses a registration by a non-administrator",
7818
+ id: "create-permission-invalid-principal-type",
7819
+ route: "POST /SASjsApi/permission",
7820
+ description: "refuses a principal type that is neither a user nor a group",
7667
7821
  identity: ADMIN_SIGNED_IN,
7668
7822
  request: {
7669
- token: RESTRICTED2,
7823
+ token: ADMIN3,
7670
7824
  body: {
7671
- clientId: "new_app",
7672
- clientSecret: "new_secret",
7673
- accessTokenExpiration: 3600,
7674
- refreshTokenExpiration: 86400
7825
+ path: "/SASjsApi/drive/deploy",
7826
+ type: "Route",
7827
+ setting: "Grant",
7828
+ principalType: "role",
7829
+ principalId: "anything"
7675
7830
  }
7676
7831
  },
7677
- expect: { status: 401, error: "Admin account required" }
7832
+ expect: {
7833
+ status: 400,
7834
+ error: "Invalid principal type. Valid types are user or group."
7835
+ }
7678
7836
  },
7679
7837
  {
7680
- id: "create-client-duplicate",
7681
- route: "POST /SASjsApi/client",
7682
- description: "refuses a client id that is registered, with the 403 the server sends",
7838
+ id: "create-permission-admin-principal",
7839
+ route: "POST /SASjsApi/permission",
7840
+ description: "refuses a rule assigned to an administrator",
7683
7841
  identity: ADMIN_SIGNED_IN,
7684
7842
  request: {
7685
7843
  token: ADMIN3,
7686
7844
  body: {
7687
- clientId: "web_app",
7688
- clientSecret: "other",
7689
- accessTokenExpiration: 3600,
7690
- refreshTokenExpiration: 86400
7845
+ path: "/SASjsApi/drive/folder",
7846
+ type: "Route",
7847
+ setting: "Grant",
7848
+ principalType: "user",
7849
+ principalId: ADMIN_UID
7691
7850
  }
7692
7851
  },
7693
- expect: { status: 403, error: "Error: Client ID already exists." }
7852
+ expect: {
7853
+ status: 400,
7854
+ error: "Can not add permission for admin user."
7855
+ }
7694
7856
  },
7695
- // -------------------------------------------------------------- passwords
7696
7857
  {
7697
- id: "update-password",
7698
- route: "PATCH /SASjsApi/auth/updatePassword",
7699
- description: "changes the caller’s own password",
7858
+ id: "create-permission-not-admin",
7859
+ route: "POST /SASjsApi/permission",
7860
+ description: "refuses a creation by a non-administrator",
7700
7861
  identity: ADMIN_SIGNED_IN,
7701
7862
  request: {
7702
7863
  token: RESTRICTED2,
7703
- body: { currentPassword: "user123", newPassword: "changed123" }
7864
+ body: {
7865
+ path: "/SASjsApi/drive/folder",
7866
+ type: "Route",
7867
+ setting: "Grant",
7868
+ principalType: "user",
7869
+ principalId: RESTRICTED_UID
7870
+ }
7704
7871
  },
7705
- expect: { status: 204 }
7706
- },
7707
- {
7708
- id: "update-password-missing-field",
7709
- route: "PATCH /SASjsApi/auth/updatePassword",
7710
- description: "refuses a body without the current password",
7711
- identity: ADMIN_SIGNED_IN,
7712
- request: { token: RESTRICTED2, body: { newPassword: "changed123" } },
7713
- expect: { status: 400, error: '"currentPassword" is required' }
7872
+ expect: { status: 401, error: "Admin account required" }
7714
7873
  },
7715
7874
  {
7716
- id: "update-password-unauthenticated",
7717
- route: "PATCH /SASjsApi/auth/updatePassword",
7718
- description: "refuses the change with no caller",
7875
+ id: "create-permission-missing-principal",
7876
+ route: "POST /SASjsApi/permission",
7877
+ description: "answers 404 for a principal that does not exist",
7719
7878
  identity: ADMIN_SIGNED_IN,
7720
7879
  request: {
7721
- body: { currentPassword: "user123", newPassword: "changed123" }
7880
+ token: ADMIN3,
7881
+ body: {
7882
+ path: "/SASjsApi/drive/rename",
7883
+ type: "Route",
7884
+ setting: "Grant",
7885
+ principalType: "group",
7886
+ principalId: "group-none"
7887
+ }
7722
7888
  },
7723
- expect: { status: 401, error: "Unauthorized" }
7889
+ expect: { status: 404, error: "Group not found." }
7724
7890
  },
7725
7891
  {
7726
- id: "update-password-wrong-current",
7727
- route: "PATCH /SASjsApi/auth/updatePassword",
7728
- description: "refuses a change whose current password is wrong",
7892
+ id: "create-permission-duplicate-group",
7893
+ route: "POST /SASjsApi/permission",
7894
+ description: "refuses a group rule that already exists",
7729
7895
  identity: ADMIN_SIGNED_IN,
7730
7896
  request: {
7731
- token: RESTRICTED2,
7732
- body: { currentPassword: "wrong", newPassword: "changed123" }
7733
- },
7734
- expect: { status: 403, error: "Invalid current password!" }
7735
- },
7736
- {
7737
- id: "update-password-provider",
7738
- route: "PATCH /SASjsApi/auth/updatePassword",
7739
- description: "refuses a password change on a provider-managed account",
7740
- identity: PROVIDER_MANAGED,
7741
- request: {
7742
- token: "dir-access",
7743
- body: { currentPassword: "dir123", newPassword: "changed123" }
7897
+ token: ADMIN3,
7898
+ body: {
7899
+ path: "/SASjsApi/drive/file",
7900
+ type: "Route",
7901
+ setting: "Grant",
7902
+ principalType: "group",
7903
+ principalId: "group-data-controller"
7904
+ }
7744
7905
  },
7745
7906
  expect: {
7746
- status: 405,
7747
- error: "Can not update password of user that is created by an external auth provider."
7907
+ status: 409,
7908
+ error: "Permission already exists with provided Path, Type and Group."
7748
7909
  }
7749
- }
7750
- ];
7751
-
7752
- // src/authconfig/service.ts
7753
- var LDAP_FIELDS = [
7754
- "url",
7755
- "bindDn",
7756
- "usersBaseDn",
7757
- "groupsBaseDn",
7758
- "bindPasswordSet"
7759
- ];
7760
- var OIDC_FIELDS = [
7761
- "providerName",
7762
- "issuerUrl",
7763
- "clientId",
7764
- "redirectUri",
7765
- "scope",
7766
- "signingAlg",
7767
- "usernameClaim",
7768
- "jitProvision",
7769
- "clientSecretSet"
7770
- ];
7771
- var SECRET = /(password|secret|passwd|token)/i;
7772
- var checkProvider = (name, block, fields, booleans) => {
7773
- if (!block || typeof block !== "object")
7774
- throw new Error(
7775
- `The auth configuration states \`${name}\` as ${JSON.stringify(block)}; a provider is an object, or absent when it is not enabled.`
7776
- );
7777
- for (const key of Object.keys(block)) {
7778
- if (!fields.includes(key))
7779
- throw new Error(
7780
- SECRET.test(key) ? `The auth configuration states \`${name}.${key}\`, which looks like a secret. Secrets are never echoed by this route: pass \`${key}Set: true\` instead, so the answer carries whether one is configured and not the value.` : `The auth configuration carries \`${name}.${key}\`, which the document's example does not state. Remove it, or add it to the provider's fields here and to the document.`
7781
- );
7782
- }
7783
- for (const key of fields) {
7784
- if (!(key in block))
7785
- throw new Error(
7786
- `The auth configuration does not state \`${name}.${key}\`, which the administration interface reads. State the empty string when the host has no value for it.`
7787
- );
7788
- const value = block[key];
7789
- if (booleans.includes(key)) {
7790
- if (typeof value !== "boolean")
7791
- throw new Error(
7792
- `The auth configuration states \`${name}.${key}\` as ${JSON.stringify(value)}; it says whether the secret is configured, so it is a boolean.`
7793
- );
7794
- } else if (typeof value !== "string")
7795
- throw new Error(
7796
- `The auth configuration states \`${name}.${key}\` as ${JSON.stringify(value)}; the document states a string.`
7797
- );
7798
- }
7799
- };
7800
- var normaliseAuthConfig = (config) => {
7801
- if (!config || typeof config !== "object")
7802
- throw new Error("The auth configuration is not an object.");
7803
- for (const key of Object.keys(config))
7804
- if (key !== "ldap" && key !== "oidc")
7805
- throw new Error(
7806
- SECRET.test(key) ? `The auth configuration states \`${key}\` at the top level, which looks like a secret. Secrets are never echoed by this route; put the provider under \`ldap\` or \`oidc\` and report whether the secret is set.` : `The auth configuration carries \`${key}\`, which is not a provider this API has. The document states \`ldap\` and \`oidc\`.`
7807
- );
7808
- const answer = {};
7809
- if (config.ldap !== void 0) {
7810
- checkProvider("ldap", config.ldap, LDAP_FIELDS, ["bindPasswordSet"]);
7811
- answer.ldap = {
7812
- LDAP_URL: config.ldap.url,
7813
- LDAP_BIND_DN: config.ldap.bindDn,
7814
- LDAP_USERS_BASE_DN: config.ldap.usersBaseDn,
7815
- LDAP_GROUPS_BASE_DN: config.ldap.groupsBaseDn,
7816
- LDAP_BIND_PASSWORD_SET: config.ldap.bindPasswordSet
7817
- };
7818
- }
7819
- if (config.oidc !== void 0) {
7820
- checkProvider("oidc", config.oidc, OIDC_FIELDS, ["clientSecretSet"]);
7821
- answer.oidc = {
7822
- OIDC_PROVIDER_NAME: config.oidc.providerName,
7823
- OIDC_ISSUER_URL: config.oidc.issuerUrl,
7824
- OIDC_CLIENT_ID: config.oidc.clientId,
7825
- OIDC_REDIRECT_URI: config.oidc.redirectUri,
7826
- OIDC_SCOPE: config.oidc.scope,
7827
- OIDC_SIGNING_ALG: config.oidc.signingAlg,
7828
- OIDC_USERNAME_CLAIM: config.oidc.usernameClaim,
7829
- OIDC_JIT_PROVISION: config.oidc.jitProvision,
7830
- OIDC_CLIENT_SECRET_SET: config.oidc.clientSecretSet
7831
- };
7832
- }
7833
- return answer;
7834
- };
7835
- var createAuthConfigService = (config) => {
7836
- const read = () => typeof config === "function" ? config() : config;
7837
- return {
7838
- async authConfig() {
7839
- return normaliseAuthConfig(read());
7910
+ },
7911
+ {
7912
+ id: "create-permission-duplicate",
7913
+ route: "POST /SASjsApi/permission",
7914
+ description: "refuses a rule that already exists",
7915
+ identity: ADMIN_SIGNED_IN,
7916
+ request: {
7917
+ token: ADMIN3,
7918
+ body: {
7919
+ path: "/SASjsApi/code/execute",
7920
+ type: "Route",
7921
+ setting: "Deny",
7922
+ principalType: "user",
7923
+ principalId: RESTRICTED_UID
7924
+ }
7925
+ },
7926
+ expect: {
7927
+ status: 409,
7928
+ error: "Permission already exists with provided Path, Type and User."
7929
+ }
7930
+ },
7931
+ {
7932
+ id: "update-permission",
7933
+ route: "PATCH /SASjsApi/permission/{uid}",
7934
+ description: "flips a rule from Deny to Grant",
7935
+ identity: ADMIN_SIGNED_IN,
7936
+ request: {
7937
+ token: ADMIN3,
7938
+ params: { uid: "rule-code" },
7939
+ body: { setting: "Grant" }
7940
+ },
7941
+ expect: { status: 200, partial: { uid: "rule-code", setting: "Grant" } }
7942
+ },
7943
+ {
7944
+ id: "update-permission-not-admin",
7945
+ route: "PATCH /SASjsApi/permission/{uid}",
7946
+ description: "refuses a change by a non-administrator",
7947
+ identity: ADMIN_SIGNED_IN,
7948
+ request: {
7949
+ token: RESTRICTED2,
7950
+ params: { uid: "rule-code" },
7951
+ body: { setting: "Grant" }
7952
+ },
7953
+ expect: { status: 401, error: "Admin account required" }
7954
+ },
7955
+ {
7956
+ id: "update-permission-missing",
7957
+ route: "PATCH /SASjsApi/permission/{uid}",
7958
+ description: "answers 404 for a rule that does not exist",
7959
+ identity: ADMIN_SIGNED_IN,
7960
+ request: {
7961
+ token: ADMIN3,
7962
+ params: { uid: "rule-none" },
7963
+ body: { setting: "Grant" }
7964
+ },
7965
+ expect: { status: 404, error: "Permission not found." }
7966
+ },
7967
+ {
7968
+ id: "delete-permission",
7969
+ route: "DELETE /SASjsApi/permission/{uid}",
7970
+ description: "deletes a rule",
7971
+ identity: ADMIN_SIGNED_IN,
7972
+ request: { token: ADMIN3, params: { uid: "rule-code" } },
7973
+ expect: { status: 200, body: "Permission Deleted!" }
7974
+ },
7975
+ {
7976
+ id: "delete-permission-not-admin",
7977
+ route: "DELETE /SASjsApi/permission/{uid}",
7978
+ description: "refuses a deletion by a non-administrator",
7979
+ identity: ADMIN_SIGNED_IN,
7980
+ request: { token: RESTRICTED2, params: { uid: "rule-code" } },
7981
+ expect: { status: 401, error: "Admin account required" }
7982
+ },
7983
+ {
7984
+ id: "delete-permission-missing",
7985
+ route: "DELETE /SASjsApi/permission/{uid}",
7986
+ description: "answers 404 for a rule that does not exist",
7987
+ identity: ADMIN_SIGNED_IN,
7988
+ request: { token: ADMIN3, params: { uid: "rule-none" } },
7989
+ expect: { status: 404, error: "Permission not found." }
7990
+ },
7991
+ // --------------------------------------------------------------- clients
7992
+ {
7993
+ id: "list-clients",
7994
+ route: "GET /SASjsApi/client",
7995
+ description: "lists the registered clients",
7996
+ identity: ADMIN_SIGNED_IN,
7997
+ request: { token: ADMIN3 },
7998
+ expect: {
7999
+ status: 200,
8000
+ body: [
8001
+ {
8002
+ clientId: "web_app",
8003
+ clientSecret: "web_app",
8004
+ accessTokenExpiration: 86400,
8005
+ refreshTokenExpiration: 2592e3
8006
+ },
8007
+ {
8008
+ clientId: "sasjs",
8009
+ clientSecret: "sasjs",
8010
+ accessTokenExpiration: 3600,
8011
+ refreshTokenExpiration: 86400
8012
+ }
8013
+ ]
7840
8014
  }
7841
- };
7842
- };
7843
-
7844
- // src/admin/service.ts
7845
- var DEFAULT_LOG_LINES = 200;
7846
- var MAX_LOG_LINES = 5e3;
7847
- var isObject = (value) => !!value && typeof value === "object" && !Array.isArray(value);
7848
- var isNumber = (value) => typeof value === "number" && Number.isFinite(value);
7849
- var isString = (value) => typeof value === "string";
7850
- var requireString = (holder, key, where) => {
7851
- if (!isString(holder[key]))
7852
- throw new Error(
7853
- `The ${where} report states \`${key}\` as ${JSON.stringify(holder[key])}; the document states a string, and a client that renders it would print the value as it stands.`
7854
- );
7855
- };
7856
- var requireNumber = (holder, key, where) => {
7857
- if (!isNumber(holder[key]))
7858
- throw new Error(
7859
- `The ${where} report states \`${key}\` as ${JSON.stringify(holder[key])}; the document states a number, and a client that renders it would print NaN.`
7860
- );
7861
- };
7862
- var requireObject = (holder, key, where) => {
7863
- const value = holder[key];
7864
- if (!isObject(value))
7865
- throw new Error(
7866
- `The ${where} report states \`${key}\` as ${JSON.stringify(value)}; the document states an object.`
7867
- );
7868
- return value;
7869
- };
7870
- var normaliseDiagnostics = (report) => {
7871
- if (!isObject(report))
7872
- throw new Error("The diagnostics report is not an object.");
7873
- const build = requireObject(
7874
- report,
7875
- "build",
7876
- "diagnostics"
7877
- );
7878
- requireString(build, "version", "diagnostics build");
7879
- requireString(build, "gitHash", "diagnostics build");
7880
- if (!(build.buildDate === null || isString(build.buildDate)))
7881
- throw new Error(
7882
- `The diagnostics build states \`buildDate\` as ${JSON.stringify(build.buildDate)}; the document states an ISO timestamp or null.`
7883
- );
7884
- const server = requireObject(
7885
- report,
7886
- "server",
7887
- "diagnostics"
7888
- );
7889
- requireString(server, "mode", "diagnostics server");
7890
- requireString(server, "startedAt", "diagnostics server");
7891
- requireString(server, "nodeVersion", "diagnostics server");
7892
- requireString(server, "platform", "diagnostics server");
7893
- requireString(server, "arch", "diagnostics server");
7894
- requireString(server, "cpuModel", "diagnostics server");
7895
- requireString(server, "sasjsRoot", "diagnostics server");
7896
- requireNumber(server, "uptimeSeconds", "diagnostics server");
7897
- requireNumber(server, "pid", "diagnostics server");
7898
- requireNumber(server, "cpuCount", "diagnostics server");
7899
- if (!Array.isArray(server.loadAverage) || !server.loadAverage.every(isNumber))
7900
- throw new Error(
7901
- "The diagnostics server report states `loadAverage` as something other than an array of numbers."
7902
- );
7903
- if (!Array.isArray(server.runTimes) || !server.runTimes.every(isString))
7904
- throw new Error(
7905
- "The diagnostics server report states `runTimes` as something other than an array of strings."
7906
- );
7907
- const memory = requireObject(
7908
- report,
7909
- "memory",
7910
- "diagnostics"
7911
- );
7912
- for (const key of [
7913
- "rssBytes",
7914
- "heapTotalBytes",
7915
- "heapUsedBytes",
7916
- "externalBytes",
7917
- "systemTotalBytes",
7918
- "systemFreeBytes"
7919
- ])
7920
- requireNumber(memory, key, "diagnostics memory");
7921
- const filesystem = report.filesystem;
7922
- if (filesystem !== null) {
7923
- if (!isObject(filesystem))
7924
- throw new Error(
7925
- `The diagnostics report states \`filesystem\` as ${JSON.stringify(filesystem)}; the document states an object or null.`
7926
- );
7927
- requireString(
7928
- filesystem,
7929
- "path",
7930
- "diagnostics filesystem"
7931
- );
7932
- for (const key of ["totalBytes", "freeBytes", "usedBytes", "usedPercent"])
7933
- requireNumber(
7934
- filesystem,
7935
- key,
7936
- "diagnostics filesystem"
7937
- );
7938
- }
7939
- if (!Array.isArray(report.folders))
7940
- throw new Error(
7941
- "The diagnostics report states `folders` as something other than an array."
7942
- );
7943
- for (const folder of report.folders) {
7944
- if (!isObject(folder))
7945
- throw new Error(
7946
- "The diagnostics report carries a folder that is not an object."
7947
- );
7948
- const entry = folder;
7949
- requireString(entry, "label", "diagnostics folder");
7950
- requireString(entry, "path", "diagnostics folder");
7951
- requireNumber(entry, "bytes", "diagnostics folder");
7952
- requireNumber(entry, "files", "diagnostics folder");
7953
- if (typeof entry.exists !== "boolean" || typeof entry.truncated !== "boolean")
7954
- throw new Error(
7955
- "The diagnostics folder report states `exists` or `truncated` as something other than a boolean."
7956
- );
7957
- }
7958
- const logs = requireObject(
7959
- report,
7960
- "logs",
7961
- "diagnostics"
7962
- );
7963
- requireString(logs, "folder", "diagnostics logs");
7964
- requireNumber(logs, "fileCount", "diagnostics logs");
7965
- requireNumber(logs, "totalBytes", "diagnostics logs");
7966
- for (const key of ["newestFile", "newestModified"])
7967
- if (!(logs[key] === null || isString(logs[key])))
7968
- throw new Error(
7969
- `The diagnostics logs summary states \`${key}\` as ${JSON.stringify(logs[key])}; the document states a string or null.`
7970
- );
7971
- return report;
7972
- };
7973
- var normaliseLogFiles = (files) => {
7974
- if (!Array.isArray(files))
7975
- throw new Error("The log report is not an array of files.");
7976
- return files.map((file) => {
7977
- if (!isObject(file))
7978
- throw new Error("The log report carries an entry that is not an object.");
7979
- const entry = file;
7980
- requireString(entry, "name", "logs");
7981
- requireString(entry, "modified", "logs");
7982
- requireNumber(entry, "sizeBytes", "logs");
7983
- return file;
7984
- });
7985
- };
7986
- var checkLogFileName = (fileName) => {
7987
- if (!fileName || fileName.includes("/") || fileName.includes("\\") || fileName.split(/[\\/]/).pop() !== fileName || !fileName.toLowerCase().endsWith(".log"))
7988
- throw new ApiError(400, "Invalid log file name.");
7989
- return fileName;
7990
- };
7991
- var logLines = (lines) => {
7992
- if (lines === void 0 || lines === null || lines === "")
7993
- return DEFAULT_LOG_LINES;
7994
- const wanted = Number(lines);
7995
- if (!Number.isFinite(wanted)) return DEFAULT_LOG_LINES;
7996
- return Math.min(Math.max(Math.trunc(wanted), 1), MAX_LOG_LINES);
7997
- };
7998
- var normaliseLogTail = (tail) => {
7999
- if (!isObject(tail)) throw new Error("The log tail report is not an object.");
8000
- const entry = tail;
8001
- requireString(entry, "fileName", "log tail");
8002
- requireString(entry, "content", "log tail");
8003
- requireNumber(entry, "lines", "log tail");
8004
- requireNumber(entry, "bytesRead", "log tail");
8005
- if (typeof entry.truncated !== "boolean")
8006
- throw new Error(
8007
- "The log tail report states `truncated` as something other than a boolean."
8008
- );
8009
- return tail;
8010
- };
8011
- var createAdminService = (reports) => ({
8012
- async diagnostics() {
8013
- return normaliseDiagnostics(await reports.diagnostics());
8014
8015
  },
8015
- async logs() {
8016
- return normaliseLogFiles(await reports.logs());
8016
+ {
8017
+ id: "list-clients-not-admin",
8018
+ route: "GET /SASjsApi/client",
8019
+ description: "refuses the list to a caller who is not an administrator",
8020
+ identity: ADMIN_SIGNED_IN,
8021
+ request: { token: RESTRICTED2 },
8022
+ expect: { status: 401, error: "Admin account required" }
8017
8023
  },
8018
- async logTail(fileName, lines) {
8019
- const name = checkLogFileName(fileName);
8020
- const tail = await reports.logTail(name, logLines(lines));
8021
- if (tail === void 0) throw new ApiError(404, "Log file not found.");
8022
- return normaliseLogTail(tail);
8023
- }
8024
- });
8025
-
8026
- // src/directory/service.ts
8027
- var isNonEmptyString3 = (value) => typeof value === "string" && value.length > 0;
8028
- var usersOf = (users) => {
8029
- if (!Array.isArray(users))
8030
- throw new Error("The directory answer has no users array.");
8031
- const seen = /* @__PURE__ */ new Set();
8032
- for (const user3 of users) {
8033
- if (!isNonEmptyString3(user3?.username) || !isNonEmptyString3(user3?.displayName))
8034
- throw new Error(
8035
- `The directory answer carries a user without a username or displayName: ${JSON.stringify(user3)}. Both are what the API keys an account on, so the import cannot guess them.`
8036
- );
8037
- if (seen.has(user3.username))
8038
- throw new Error(
8039
- `The directory answer names ${user3.username} twice. A directory that returns one account twice is a filter problem, and importing it would hide that.`
8040
- );
8041
- seen.add(user3.username);
8042
- }
8043
- return users;
8044
- };
8045
- var groupsOf = (groups) => {
8046
- if (!Array.isArray(groups))
8047
- throw new Error("The directory answer has no groups array.");
8048
- const seen = /* @__PURE__ */ new Set();
8049
- for (const group of groups) {
8050
- if (!isNonEmptyString3(group?.name))
8051
- throw new Error(
8052
- `The directory answer carries a group without a name: ${JSON.stringify(group)}.`
8053
- );
8054
- if (seen.has(group.name))
8055
- throw new Error(
8056
- `The directory answer names the group ${group.name} twice, which would apply its members twice.`
8057
- );
8058
- seen.add(group.name);
8059
- }
8060
- return groups;
8061
- };
8062
- var createDirectoryService = (store, source, options = {}) => {
8063
- const provider = options.provider || "ldap";
8064
- return {
8065
- async synchronise() {
8066
- const directoryUsers = usersOf(await source.users());
8067
- const directoryGroups = groupsOf(await source.groups());
8068
- const existingUsers = await store.users();
8069
- const existingGroups = await store.groups();
8070
- const userByName = new Map(
8071
- existingUsers.map((user3) => [user3.username, user3])
8072
- );
8073
- const groupByName = new Map(
8074
- existingGroups.map((group) => [group.name, group])
8075
- );
8076
- const imported = [];
8077
- for (const user3 of directoryUsers) {
8078
- if (userByName.has(user3.username)) continue;
8079
- const created = await store.createUser({
8080
- username: user3.username,
8081
- displayName: user3.displayName,
8082
- isAdmin: false,
8083
- isActive: true,
8084
- authProvider: provider
8085
- });
8086
- userByName.set(created.username, created);
8087
- imported.push(created);
8024
+ {
8025
+ id: "create-client",
8026
+ route: "POST /SASjsApi/client",
8027
+ description: "registers a client",
8028
+ identity: ADMIN_SIGNED_IN,
8029
+ request: {
8030
+ token: ADMIN3,
8031
+ body: {
8032
+ clientId: "new_app",
8033
+ clientSecret: "new_secret",
8034
+ accessTokenExpiration: 3600,
8035
+ refreshTokenExpiration: 86400
8088
8036
  }
8089
- const importedGroups = [];
8090
- for (const group of directoryGroups) {
8091
- if (groupByName.has(group.name)) continue;
8092
- const created = await store.createGroup({
8093
- name: group.name,
8094
- description: "",
8095
- isActive: true,
8096
- authProvider: provider
8097
- });
8098
- groupByName.set(created.name, created);
8099
- importedGroups.push(created);
8037
+ },
8038
+ expect: {
8039
+ status: 200,
8040
+ body: {
8041
+ clientId: "new_app",
8042
+ clientSecret: "new_secret",
8043
+ accessTokenExpiration: 3600,
8044
+ refreshTokenExpiration: 86400
8100
8045
  }
8101
- const membersOf = /* @__PURE__ */ new Map();
8102
- const note = (groupName, username) => {
8103
- const members = membersOf.get(groupName) || /* @__PURE__ */ new Set();
8104
- members.add(username);
8105
- membersOf.set(groupName, members);
8106
- };
8107
- for (const group of directoryGroups)
8108
- for (const member of group.members || []) note(group.name, member);
8109
- for (const user3 of directoryUsers)
8110
- for (const groupName of user3.groups || [])
8111
- note(groupName, user3.username);
8112
- for (const group of importedGroups)
8113
- for (const username of membersOf.get(group.name) || []) {
8114
- const user3 = userByName.get(username);
8115
- if (user3) await store.addToGroup(group.uid, user3.uid);
8116
- }
8117
- return { userCount: imported.length, groupCount: importedGroups.length };
8118
8046
  }
8119
- };
8120
- };
8047
+ },
8048
+ {
8049
+ id: "create-client-defaults",
8050
+ route: "POST /SASjsApi/client",
8051
+ description: "applies the schema defaults when the lifetimes are omitted",
8052
+ identity: ADMIN_SIGNED_IN,
8053
+ request: {
8054
+ token: ADMIN3,
8055
+ body: { clientId: "default_app", clientSecret: "default_secret" }
8056
+ },
8057
+ expect: {
8058
+ status: 200,
8059
+ body: {
8060
+ clientId: "default_app",
8061
+ clientSecret: "default_secret",
8062
+ accessTokenExpiration: 86400,
8063
+ refreshTokenExpiration: 2592e3
8064
+ }
8065
+ }
8066
+ },
8067
+ {
8068
+ id: "create-client-not-admin",
8069
+ route: "POST /SASjsApi/client",
8070
+ description: "refuses a registration by a non-administrator",
8071
+ identity: ADMIN_SIGNED_IN,
8072
+ request: {
8073
+ token: RESTRICTED2,
8074
+ body: {
8075
+ clientId: "new_app",
8076
+ clientSecret: "new_secret",
8077
+ accessTokenExpiration: 3600,
8078
+ refreshTokenExpiration: 86400
8079
+ }
8080
+ },
8081
+ expect: { status: 401, error: "Admin account required" }
8082
+ },
8083
+ {
8084
+ id: "create-client-duplicate",
8085
+ route: "POST /SASjsApi/client",
8086
+ description: "refuses a client id that is registered, with the 403 the server sends",
8087
+ identity: ADMIN_SIGNED_IN,
8088
+ request: {
8089
+ token: ADMIN3,
8090
+ body: {
8091
+ clientId: "web_app",
8092
+ clientSecret: "other",
8093
+ accessTokenExpiration: 3600,
8094
+ refreshTokenExpiration: 86400
8095
+ }
8096
+ },
8097
+ expect: { status: 403, error: "Error: Client ID already exists." }
8098
+ },
8099
+ // -------------------------------------------------------------- passwords
8100
+ {
8101
+ id: "update-password",
8102
+ route: "PATCH /SASjsApi/auth/updatePassword",
8103
+ description: "changes the caller’s own password",
8104
+ identity: ADMIN_SIGNED_IN,
8105
+ request: {
8106
+ token: RESTRICTED2,
8107
+ body: { currentPassword: "Orion123", newPassword: "changed123" }
8108
+ },
8109
+ expect: { status: 204 }
8110
+ },
8111
+ {
8112
+ id: "update-password-missing-field",
8113
+ route: "PATCH /SASjsApi/auth/updatePassword",
8114
+ description: "refuses a body without the current password",
8115
+ identity: ADMIN_SIGNED_IN,
8116
+ request: { token: RESTRICTED2, body: { newPassword: "changed123" } },
8117
+ expect: { status: 400, error: '"currentPassword" is required' }
8118
+ },
8119
+ {
8120
+ id: "update-password-unauthenticated",
8121
+ route: "PATCH /SASjsApi/auth/updatePassword",
8122
+ description: "refuses the change with no caller",
8123
+ identity: ADMIN_SIGNED_IN,
8124
+ request: {
8125
+ body: { currentPassword: "Orion123", newPassword: "changed123" }
8126
+ },
8127
+ expect: { status: 401, error: "Unauthorized" }
8128
+ },
8129
+ {
8130
+ id: "update-password-wrong-current",
8131
+ route: "PATCH /SASjsApi/auth/updatePassword",
8132
+ description: "refuses a change whose current password is wrong",
8133
+ identity: ADMIN_SIGNED_IN,
8134
+ request: {
8135
+ token: RESTRICTED2,
8136
+ body: { currentPassword: "wrong", newPassword: "changed123" }
8137
+ },
8138
+ expect: { status: 403, error: "Invalid current password!" }
8139
+ },
8140
+ {
8141
+ id: "update-password-provider",
8142
+ route: "PATCH /SASjsApi/auth/updatePassword",
8143
+ description: "refuses a password change on a provider-managed account",
8144
+ identity: PROVIDER_MANAGED,
8145
+ request: {
8146
+ token: "dir-access",
8147
+ body: { currentPassword: "dir123", newPassword: "changed123" }
8148
+ },
8149
+ expect: {
8150
+ status: 405,
8151
+ error: "Can not update password of user that is created by an external auth provider."
8152
+ }
8153
+ }
8154
+ ];
8121
8155
 
8122
8156
  // src/corpus/runner.ts
8123
8157
  var servicesFor = (testCase) => {