@tomei/sso 0.65.1-test.1 → 0.65.1
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/.gitlab-ci.yml +33 -214
- package/__tests__/unit/components/group/group.spec.ts +0 -6
- package/__tests__/unit/components/group-reporting-user/group-reporting-user.spec.ts +1 -9
- package/__tests__/unit/components/login-user/login.spec.ts +5 -1199
- package/__tests__/unit/components/login-user/password-expiry.spec.ts +87 -0
- package/__tests__/unit/components/system/system.spec.ts +0 -1
- package/dist/__tests__/unit/components/group/group.spec.js +0 -4
- package/dist/__tests__/unit/components/group/group.spec.js.map +1 -1
- package/dist/__tests__/unit/components/group-reporting-user/group-reporting-user.spec.js +1 -9
- package/dist/__tests__/unit/components/group-reporting-user/group-reporting-user.spec.js.map +1 -1
- package/dist/__tests__/unit/components/login-user/login.spec.js +0 -703
- package/dist/__tests__/unit/components/login-user/login.spec.js.map +1 -1
- package/dist/__tests__/unit/components/login-user/password-expiry.spec.js +86 -0
- package/dist/__tests__/unit/components/login-user/password-expiry.spec.js.map +1 -0
- package/dist/__tests__/unit/components/system/system.spec.js +0 -1
- package/dist/__tests__/unit/components/system/system.spec.js.map +1 -1
- package/dist/src/components/login-user/user.d.ts +5 -0
- package/dist/src/components/login-user/user.js +44 -0
- package/dist/src/components/login-user/user.js.map +1 -1
- package/dist/src/components/user-password-history/user-password-history.d.ts +1 -0
- package/dist/src/components/user-password-history/user-password-history.js +41 -2
- package/dist/src/components/user-password-history/user-password-history.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/jest.config.js +0 -2
- package/package.json +2 -2
- package/src/components/login-user/user.ts +78 -0
- package/src/components/user-password-history/user-password-history.ts +57 -6
- package/__tests__/unit/components/api-key/api-key.spec.ts +0 -201
- package/__tests__/unit/components/user-password-history/user-password-history.spec.ts +0 -165
- package/__tests__/unit/components/user-reporting-hierarchy/user-reporting-hierarchy.spec.ts +0 -233
- package/coverage/cobertura-coverage.xml +0 -6837
- package/coverage/test-report.xml +0 -161
- package/dist/__tests__/unit/components/api-key/api-key.spec.js +0 -158
- package/dist/__tests__/unit/components/api-key/api-key.spec.js.map +0 -1
- package/dist/__tests__/unit/components/user-password-history/user-password-history.spec.d.ts +0 -1
- package/dist/__tests__/unit/components/user-password-history/user-password-history.spec.js +0 -138
- package/dist/__tests__/unit/components/user-password-history/user-password-history.spec.js.map +0 -1
- package/dist/__tests__/unit/components/user-reporting-hierarchy/user-reporting-hierarchy.spec.d.ts +0 -1
- package/dist/__tests__/unit/components/user-reporting-hierarchy/user-reporting-hierarchy.spec.js +0 -182
- package/dist/__tests__/unit/components/user-reporting-hierarchy/user-reporting-hierarchy.spec.js.map +0 -1
- package/migrations/20250805085707-add-bulk-approval-code-to-sso-user.js +0 -29
- /package/dist/__tests__/unit/components/{api-key/api-key.spec.d.ts → login-user/password-expiry.spec.d.ts} +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { User } from '../../../../src/components/login-user/user';
|
|
2
|
+
import { UserPasswordHistory } from '../../../../src/components/user-password-history/user-password-history';
|
|
3
|
+
import { YN } from '../../../../src/enum/yn.enum';
|
|
4
|
+
|
|
5
|
+
// User and LoginUser import each other; this test exercises only User's expiry policy.
|
|
6
|
+
jest.mock('../../../../src/components/login-user/login-user', () => ({
|
|
7
|
+
LoginUser: class {},
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
describe('User.getPasswordExpiryStatus', () => {
|
|
11
|
+
const originalExpiryMonths = process.env.PASSWORD_EXPIRY_MONTHS;
|
|
12
|
+
const originalWarningDays = process.env.PASSWORD_EXPIRY_WARNING_DAYS;
|
|
13
|
+
|
|
14
|
+
const user = (password: string | null) =>
|
|
15
|
+
Object.assign(Object.create(User.prototype), {
|
|
16
|
+
ObjectId: '123',
|
|
17
|
+
_Password: password,
|
|
18
|
+
_NeedToChangePasswordYN: YN.No,
|
|
19
|
+
}) as User;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
process.env.PASSWORD_EXPIRY_MONTHS = '1';
|
|
23
|
+
process.env.PASSWORD_EXPIRY_WARNING_DAYS = '14';
|
|
24
|
+
jest.useFakeTimers().setSystemTime(new Date('2026-02-20T12:00:00Z'));
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
jest.restoreAllMocks();
|
|
29
|
+
jest.useRealTimers();
|
|
30
|
+
if (originalExpiryMonths === undefined)
|
|
31
|
+
delete process.env.PASSWORD_EXPIRY_MONTHS;
|
|
32
|
+
else process.env.PASSWORD_EXPIRY_MONTHS = originalExpiryMonths;
|
|
33
|
+
if (originalWarningDays === undefined)
|
|
34
|
+
delete process.env.PASSWORD_EXPIRY_WARNING_DAYS;
|
|
35
|
+
else process.env.PASSWORD_EXPIRY_WARNING_DAYS = originalWarningDays;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('disables expiry when the period is zero', async () => {
|
|
39
|
+
process.env.PASSWORD_EXPIRY_MONTHS = '0';
|
|
40
|
+
const lookup = jest.spyOn(UserPasswordHistory, 'getLatestByUserId');
|
|
41
|
+
|
|
42
|
+
expect(await user('hash').getPasswordExpiryStatus()).toEqual({
|
|
43
|
+
expired: false,
|
|
44
|
+
expiringSoon: false,
|
|
45
|
+
expiresInDays: null,
|
|
46
|
+
});
|
|
47
|
+
expect(lookup).not.toHaveBeenCalled();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('skips an account without a local password', async () => {
|
|
51
|
+
const lookup = jest.spyOn(UserPasswordHistory, 'getLatestByUserId');
|
|
52
|
+
|
|
53
|
+
expect(await user(null).getPasswordExpiryStatus()).toEqual({
|
|
54
|
+
expired: false,
|
|
55
|
+
expiringSoon: false,
|
|
56
|
+
expiresInDays: null,
|
|
57
|
+
});
|
|
58
|
+
expect(lookup).not.toHaveBeenCalled();
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('expires an account without password history', async () => {
|
|
62
|
+
jest
|
|
63
|
+
.spyOn(UserPasswordHistory, 'getLatestByUserId')
|
|
64
|
+
.mockResolvedValue(null);
|
|
65
|
+
|
|
66
|
+
expect(await user('hash').getPasswordExpiryStatus()).toEqual({
|
|
67
|
+
expired: true,
|
|
68
|
+
expiringSoon: false,
|
|
69
|
+
expiresInDays: null,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('warns before expiry and clamps month-end dates', async () => {
|
|
74
|
+
jest.spyOn(UserPasswordHistory, 'getLatestByUserId').mockResolvedValue({
|
|
75
|
+
CreatedAt: new Date('2026-01-31T12:00:00Z'),
|
|
76
|
+
} as UserPasswordHistory);
|
|
77
|
+
|
|
78
|
+
expect(await user('hash').getPasswordExpiryStatus()).toEqual({
|
|
79
|
+
expired: false,
|
|
80
|
+
expiringSoon: true,
|
|
81
|
+
expiresInDays: 8,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
jest.setSystemTime(new Date('2026-02-28T12:00:00Z'));
|
|
85
|
+
expect((await user('hash').getPasswordExpiryStatus()).expired).toBe(true);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -243,7 +243,6 @@ describe('System', () => {
|
|
|
243
243
|
const result = await System.findAll(dbTransaction, loginUser);
|
|
244
244
|
|
|
245
245
|
expect(findAllWithPaginationSpy).toHaveBeenCalledWith({
|
|
246
|
-
distinct: true,
|
|
247
246
|
where: {},
|
|
248
247
|
order: [['CreatedAt', 'DESC']],
|
|
249
248
|
transaction: dbTransaction,
|
|
@@ -14,10 +14,6 @@ const group_repository_1 = require("../../../../src/components/group/group.repos
|
|
|
14
14
|
const general_1 = require("@tomei/general");
|
|
15
15
|
const group_type_enum_1 = require("../../../../src/enum/group-type.enum");
|
|
16
16
|
describe('Group', () => {
|
|
17
|
-
beforeAll(() => {
|
|
18
|
-
process.env.REDIS_HOST = 'localhost';
|
|
19
|
-
process.env.REDIS_PORT = '6379';
|
|
20
|
-
});
|
|
21
17
|
afterEach(() => {
|
|
22
18
|
jest.clearAllMocks();
|
|
23
19
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group.spec.js","sourceRoot":"","sources":["../../../../../__tests__/unit/components/group/group.spec.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,kEAA+D;AAC/D,wFAAoF;AACpF,4CAA4C;AAC5C,0EAAqE;
|
|
1
|
+
{"version":3,"file":"group.spec.js","sourceRoot":"","sources":["../../../../../__tests__/unit/components/group/group.spec.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,kEAA+D;AAC/D,wFAAoF;AACpF,4CAA4C;AAC5C,0EAAqE;AAGrE,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gDAAgD,EAAE,GAAS,EAAE;QAC9D,MAAM,SAAS,GAAG;YAChB,SAAS,EAAE,QAAQ;YACnB,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,iBAAiB;YAC9B,IAAI,EAAE,+BAAa,CAAC,IAAI;YACxB,eAAe,EAAE,cAAc;YAC/B,wBAAwB,EAAE,GAAG;YAC7B,2BAA2B,EAAE,GAAG;YAChC,MAAM,EAAE,QAAQ;YAChB,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,WAAW,EAAE,CAAC;YACd,SAAS,EAAE,IAAI,IAAI,EAAE;SACtB,CAAC;QAEF,MAAM,mBAAmB,GAAG,IAAI,CAAC,KAAK,CAAC,kCAAe,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,qBAAqB,CAAC,gCAC/F,SAAS,KACZ,GAAG,EAAE,GAAG,EAAE,CAAC,SAAS,GACd,CAAC,CAAC;QAEV,MAAM,MAAM,GAAG,MAAM,aAAK,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAEhD,MAAM,CAAC,MAAM,CAA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ACL,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -9,14 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
jest.mock('../../../../src/components/login-user/login-user', () => ({
|
|
13
|
-
LoginUser: class MockLoginUser {
|
|
14
|
-
},
|
|
15
|
-
}));
|
|
16
|
-
jest.mock('../../../../src/components/login-user/user', () => ({
|
|
17
|
-
User: class MockUser {
|
|
18
|
-
},
|
|
19
|
-
}));
|
|
20
12
|
const group_reporting_user_1 = require("../../../../src/components/group-reporting-user/group-reporting-user");
|
|
21
13
|
const group_reporting_user_repository_1 = require("../../../../src/components/group-reporting-user/group-reporting-user.repository");
|
|
22
14
|
const general_1 = require("@tomei/general");
|
|
@@ -59,7 +51,7 @@ describe('GroupReportingUser', () => {
|
|
|
59
51
|
}));
|
|
60
52
|
it('should throw ClassError when failed to initialize GroupReportingUser', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
53
|
jest.spyOn(group_reporting_user_repository_1.GroupReportingUserRepository.prototype, 'findByPk').mockRejectedValue(new Error());
|
|
62
|
-
yield expect(group_reporting_user_1.GroupReportingUser.init(mockDbTransaction, '1')).rejects.toThrow(
|
|
54
|
+
yield expect(group_reporting_user_1.GroupReportingUser.init(mockDbTransaction, '1')).rejects.toThrow(general_1.ClassError);
|
|
63
55
|
}));
|
|
64
56
|
});
|
|
65
57
|
});
|
package/dist/__tests__/unit/components/group-reporting-user/group-reporting-user.spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-reporting-user.spec.js","sourceRoot":"","sources":["../../../../../__tests__/unit/components/group-reporting-user/group-reporting-user.spec.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"group-reporting-user.spec.js","sourceRoot":"","sources":["../../../../../__tests__/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