@oneuptime/common 12.0.21 → 12.0.23

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.
Files changed (94) hide show
  1. package/Models/DatabaseModels/Index.ts +4 -0
  2. package/Models/DatabaseModels/NetworkDevice.ts +44 -0
  3. package/Models/DatabaseModels/NetworkDeviceAutoImportRule.ts +564 -0
  4. package/Models/DatabaseModels/NetworkDeviceDiscoveryScan.ts +38 -0
  5. package/Models/DatabaseModels/UserTwoFactorBackupCode.ts +262 -0
  6. package/Server/API/UserTwoFactorBackupCodeAPI.ts +258 -0
  7. package/Server/Infrastructure/Postgres/SchemaMigrations/1789100000000-AddNetworkDeviceAutoImportRule.ts +60 -0
  8. package/Server/Infrastructure/Postgres/SchemaMigrations/1789100000000-AddUserTwoFactorBackupCode.ts +63 -0
  9. package/Server/Infrastructure/Postgres/SchemaMigrations/1789200000000-AddSysObjectIdPatternToAutoImportRule.ts +26 -0
  10. package/Server/Infrastructure/Postgres/SchemaMigrations/1789300000000-AddAutoApplyVendorHealthTemplate.ts +26 -0
  11. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +8 -0
  12. package/Server/Services/Index.ts +4 -0
  13. package/Server/Services/NetworkDeviceAutoImportRuleEngineService.ts +917 -0
  14. package/Server/Services/NetworkDeviceAutoImportRuleService.ts +181 -0
  15. package/Server/Services/UserService.ts +42 -0
  16. package/Server/Services/UserTwoFactorBackupCodeService.ts +355 -0
  17. package/Server/Utils/Monitor/NetworkInventoryUtil.ts +39 -1
  18. package/Server/Utils/TwoFactorBackupCode.ts +266 -0
  19. package/Tests/Server/API/UserAuthenticationAPI.test.ts +16 -3
  20. package/Tests/Server/API/UserTwoFactorAuthAdminAPI.test.ts +18 -2
  21. package/Tests/Server/API/UserTwoFactorBackupCodeAPI.test.ts +1390 -0
  22. package/Tests/Server/Services/AutoImportScanCredentialSelect.test.ts +205 -0
  23. package/Tests/Server/Services/NetworkDeviceAutoImportRuleEngineService.test.ts +933 -0
  24. package/Tests/Server/Services/UserAuthenticationService.test.ts +23 -1
  25. package/Tests/Server/Services/UserTwoFactorAuthAdmin.test.ts +21 -0
  26. package/Tests/Server/Services/UserTwoFactorBackupCodeAdminSurface.test.ts +919 -0
  27. package/Tests/Server/Services/UserTwoFactorBackupCodeService.test.ts +862 -0
  28. package/Tests/Server/Utils/Monitor/NetworkInventoryUtil.test.ts +97 -1
  29. package/Tests/Server/Utils/TwoFactorBackupCode.test.ts +475 -0
  30. package/Tests/Utils/NetworkDiscovery/AutoImportRuleMatcher.test.ts +516 -0
  31. package/Tests/Utils/NetworkDiscovery/DiscoveredDeviceBuilder.test.ts +272 -0
  32. package/Tests/Utils/NetworkDiscovery/ScanTargetUtil.test.ts +164 -0
  33. package/Types/Email/EmailTemplateType.ts +2 -0
  34. package/Types/NetworkAutomation/RuleRunResult.ts +84 -0
  35. package/Types/Permission.ts +47 -0
  36. package/Types/UserAuthenticationStatus.ts +16 -0
  37. package/Utils/NetworkDiscovery/AutoImportRuleMatcher.ts +257 -0
  38. package/Utils/NetworkDiscovery/DiscoveredDeviceBuilder.ts +183 -0
  39. package/Utils/NetworkDiscovery/DiscoveredHostUtil.ts +95 -0
  40. package/Utils/NetworkDiscovery/DiscoveryImportEligibility.ts +66 -0
  41. package/Utils/NetworkDiscovery/ScanTargetUtil.ts +82 -0
  42. package/build/dist/Models/DatabaseModels/Index.js +4 -0
  43. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  44. package/build/dist/Models/DatabaseModels/NetworkDevice.js +45 -0
  45. package/build/dist/Models/DatabaseModels/NetworkDevice.js.map +1 -1
  46. package/build/dist/Models/DatabaseModels/NetworkDeviceAutoImportRule.js +589 -0
  47. package/build/dist/Models/DatabaseModels/NetworkDeviceAutoImportRule.js.map +1 -0
  48. package/build/dist/Models/DatabaseModels/NetworkDeviceDiscoveryScan.js +28 -0
  49. package/build/dist/Models/DatabaseModels/NetworkDeviceDiscoveryScan.js.map +1 -1
  50. package/build/dist/Models/DatabaseModels/UserTwoFactorBackupCode.js +277 -0
  51. package/build/dist/Models/DatabaseModels/UserTwoFactorBackupCode.js.map +1 -0
  52. package/build/dist/Server/API/UserTwoFactorBackupCodeAPI.js +201 -0
  53. package/build/dist/Server/API/UserTwoFactorBackupCodeAPI.js.map +1 -0
  54. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1789100000000-AddNetworkDeviceAutoImportRule.js +35 -0
  55. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1789100000000-AddNetworkDeviceAutoImportRule.js.map +1 -0
  56. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1789100000000-AddUserTwoFactorBackupCode.js +46 -0
  57. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1789100000000-AddUserTwoFactorBackupCode.js.map +1 -0
  58. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1789200000000-AddSysObjectIdPatternToAutoImportRule.js +19 -0
  59. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1789200000000-AddSysObjectIdPatternToAutoImportRule.js.map +1 -0
  60. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1789300000000-AddAutoApplyVendorHealthTemplate.js +19 -0
  61. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1789300000000-AddAutoApplyVendorHealthTemplate.js.map +1 -0
  62. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +8 -0
  63. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  64. package/build/dist/Server/Services/Index.js +4 -0
  65. package/build/dist/Server/Services/Index.js.map +1 -1
  66. package/build/dist/Server/Services/NetworkDeviceAutoImportRuleEngineService.js +711 -0
  67. package/build/dist/Server/Services/NetworkDeviceAutoImportRuleEngineService.js.map +1 -0
  68. package/build/dist/Server/Services/NetworkDeviceAutoImportRuleService.js +155 -0
  69. package/build/dist/Server/Services/NetworkDeviceAutoImportRuleService.js.map +1 -0
  70. package/build/dist/Server/Services/UserService.js +39 -0
  71. package/build/dist/Server/Services/UserService.js.map +1 -1
  72. package/build/dist/Server/Services/UserTwoFactorBackupCodeService.js +327 -0
  73. package/build/dist/Server/Services/UserTwoFactorBackupCodeService.js.map +1 -0
  74. package/build/dist/Server/Utils/Monitor/NetworkInventoryUtil.js +26 -0
  75. package/build/dist/Server/Utils/Monitor/NetworkInventoryUtil.js.map +1 -1
  76. package/build/dist/Server/Utils/TwoFactorBackupCode.js +269 -0
  77. package/build/dist/Server/Utils/TwoFactorBackupCode.js.map +1 -0
  78. package/build/dist/Types/Email/EmailTemplateType.js +2 -0
  79. package/build/dist/Types/Email/EmailTemplateType.js.map +1 -1
  80. package/build/dist/Types/NetworkAutomation/RuleRunResult.js +24 -0
  81. package/build/dist/Types/NetworkAutomation/RuleRunResult.js.map +1 -1
  82. package/build/dist/Types/Permission.js +41 -0
  83. package/build/dist/Types/Permission.js.map +1 -1
  84. package/build/dist/Utils/NetworkDiscovery/AutoImportRuleMatcher.js +149 -0
  85. package/build/dist/Utils/NetworkDiscovery/AutoImportRuleMatcher.js.map +1 -0
  86. package/build/dist/Utils/NetworkDiscovery/DiscoveredDeviceBuilder.js +121 -0
  87. package/build/dist/Utils/NetworkDiscovery/DiscoveredDeviceBuilder.js.map +1 -0
  88. package/build/dist/Utils/NetworkDiscovery/DiscoveredHostUtil.js +75 -0
  89. package/build/dist/Utils/NetworkDiscovery/DiscoveredHostUtil.js.map +1 -0
  90. package/build/dist/Utils/NetworkDiscovery/DiscoveryImportEligibility.js +59 -0
  91. package/build/dist/Utils/NetworkDiscovery/DiscoveryImportEligibility.js.map +1 -0
  92. package/build/dist/Utils/NetworkDiscovery/ScanTargetUtil.js +60 -0
  93. package/build/dist/Utils/NetworkDiscovery/ScanTargetUtil.js.map +1 -1
  94. package/package.json +1 -1
@@ -5,6 +5,7 @@ import UserService from "../../../Server/Services/UserService";
5
5
  import UserSessionService from "../../../Server/Services/UserSessionService";
6
6
  import UserTotpAuthService from "../../../Server/Services/UserTotpAuthService";
7
7
  import UserWebAuthnService from "../../../Server/Services/UserWebAuthnService";
8
+ import UserTwoFactorBackupCodeService from "../../../Server/Services/UserTwoFactorBackupCodeService";
8
9
  import logger from "../../../Server/Utils/Logger";
9
10
  import User from "../../../Models/DatabaseModels/User";
10
11
  import Hostname from "../../../Types/API/Hostname";
@@ -191,6 +192,25 @@ describe("UserService -- master-admin authentication management", () => {
191
192
  return new PositiveNumber(0);
192
193
  });
193
194
 
195
+ /*
196
+ * getAuthenticationStatus also reads the user's remaining two factor
197
+ * BACKUP codes, which is a third table and therefore a third stub. Without
198
+ * it the real service reaches a repository that is not connected in this
199
+ * suite, and every test here fails with "Database not connected" rather
200
+ * than anything to do with what it was checking.
201
+ *
202
+ * Deliberately NOT folded into the two counts above -- backup codes are a
203
+ * way back in to an account whose factor is unreachable, not a factor.
204
+ * Common/Tests/Server/Services/UserTwoFactorBackupCodeAdminSurface.test.ts
205
+ * is what pins that distinction; here it only has to be stubbed.
206
+ */
207
+ getJestSpyOn(
208
+ UserTwoFactorBackupCodeService,
209
+ "countUnusedForUser",
210
+ ).mockImplementation(async (): Promise<number> => {
211
+ return 0;
212
+ });
213
+
194
214
  getJestSpyOn(DatabaseConfig, "getHost").mockImplementation(
195
215
  async (): Promise<Hostname> => {
196
216
  return new Hostname(TEST_HOSTNAME);
@@ -402,7 +422,7 @@ describe("UserService -- master-admin authentication management", () => {
402
422
  expect(status.hasPendingPasswordResetLink).toBe(true);
403
423
  });
404
424
 
405
- test("returns only the four booleans -- never the password digest itself", async () => {
425
+ test("returns exactly the vetted fields -- never the password digest itself", async () => {
406
426
  /*
407
427
  * The whole reason this is a DTO rather than a selected row: the caller
408
428
  * is a master admin, whose props bypass column read permissions, so
@@ -433,6 +453,7 @@ describe("UserService -- master-admin authentication management", () => {
433
453
  "isEmailVerified",
434
454
  "isTwoFactorAuthEnabled",
435
455
  "twoFactorAuthStatus",
456
+ "unusedTwoFactorBackupCodeCount",
436
457
  "verifiedTwoFactorAuthMethodCount",
437
458
  ]);
438
459
 
@@ -452,6 +473,7 @@ describe("UserService -- master-admin authentication management", () => {
452
473
  expect(typeof status.hasPendingPasswordResetLink).toBe("boolean");
453
474
  expect(typeof status.twoFactorAuthStatus).toBe("string");
454
475
  expect(typeof status.verifiedTwoFactorAuthMethodCount).toBe("number");
476
+ expect(typeof status.unusedTwoFactorBackupCodeCount).toBe("number");
455
477
  });
456
478
 
457
479
  test("selects exactly the columns the row-derived fields come from", async () => {
@@ -3,6 +3,7 @@ import UserService from "../../../Server/Services/UserService";
3
3
  import UserSessionService from "../../../Server/Services/UserSessionService";
4
4
  import UserTotpAuthService from "../../../Server/Services/UserTotpAuthService";
5
5
  import UserWebAuthnService from "../../../Server/Services/UserWebAuthnService";
6
+ import UserTwoFactorBackupCodeService from "../../../Server/Services/UserTwoFactorBackupCodeService";
6
7
  import logger from "../../../Server/Utils/Logger";
7
8
  import User from "../../../Models/DatabaseModels/User";
8
9
  import ColumnLength from "../../../Types/Database/ColumnLength";
@@ -201,6 +202,26 @@ describe("UserService -- admin-controlled two factor auth", () => {
201
202
  return 0;
202
203
  });
203
204
 
205
+ /*
206
+ * resetTwoFactorAuth clears the user's two factor BACKUP codes as well as
207
+ * their authenticators -- a reset that left a printed list of recovery
208
+ * codes alive would not have revoked the second-factor material it exists
209
+ * to revoke. Un-stubbed, the real service reaches a repository this suite
210
+ * does not connect and every resetTwoFactorAuth test below fails with
211
+ * "Database not connected" rather than anything it was checking.
212
+ *
213
+ * That the delete HAPPENS, for the right user, and before the session
214
+ * revocation, is asserted in
215
+ * Common/Tests/Server/Services/UserTwoFactorBackupCodeAdminSurface.test.ts
216
+ * -- this file only has to let the method run.
217
+ */
218
+ getJestSpyOn(
219
+ UserTwoFactorBackupCodeService,
220
+ "deleteAllForUser",
221
+ ).mockImplementation(async (): Promise<void> => {
222
+ return undefined;
223
+ });
224
+
204
225
  /*
205
226
  * The two probes the DELETED guards used to make. They are stubbed rather
206
227
  * than left real so that "was this consulted at all?" is answerable, which