@tomei/sso 0.66.1-test.1 → 0.66.1-test.2
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/__tests__/unit/components/group-reporting-user/group-reporting-user.spec.ts +8 -12
- package/__tests__/unit/components/login-user/login.spec.ts +75 -44
- package/coverage/cobertura-coverage.xml +6647 -47
- package/coverage/test-report.xml +153 -25
- package/dist/__tests__/unit/components/group-reporting-user/group-reporting-user.spec.js +2 -6
- 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 +72 -33
- package/dist/__tests__/unit/components/login-user/login.spec.js.map +1 -1
- package/dist/src/components/login-user/login-user.js +62 -61
- package/dist/src/components/login-user/login-user.js.map +1 -1
- package/dist/src/components/login-user/user.d.ts +5 -0
- package/dist/src/components/login-user/user.js +39 -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/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -1
- package/dist/src/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -2
- package/src/components/login-user/login-user.ts +87 -88
- package/src/components/login-user/user.ts +68 -0
- package/src/components/user-password-history/user-password-history.ts +57 -6
- package/src/index.ts +0 -1
|
@@ -27,12 +27,12 @@ describe('GroupReportingUser', () => {
|
|
|
27
27
|
jest.clearAllMocks();
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
+
|
|
30
31
|
describe('init', () => {
|
|
31
32
|
const mockDbTransaction = {};
|
|
32
33
|
|
|
33
34
|
it('should initialize GroupReportingUser without GroupReportingUserId', async () => {
|
|
34
|
-
const initGroupReportingUser =
|
|
35
|
-
await GroupReportingUser.init(mockDbTransaction);
|
|
35
|
+
const initGroupReportingUser = await GroupReportingUser.init(mockDbTransaction);
|
|
36
36
|
expect(initGroupReportingUser).toBeDefined();
|
|
37
37
|
expect(initGroupReportingUser).toBeInstanceOf(GroupReportingUser);
|
|
38
38
|
});
|
|
@@ -47,7 +47,7 @@ describe('GroupReportingUser', () => {
|
|
|
47
47
|
|
|
48
48
|
const initGroupReportingUser = await GroupReportingUser.init(
|
|
49
49
|
mockDbTransaction,
|
|
50
|
-
'1'
|
|
50
|
+
'1'
|
|
51
51
|
);
|
|
52
52
|
expect(initGroupReportingUser).toBeDefined();
|
|
53
53
|
expect(initGroupReportingUser).toBeInstanceOf(GroupReportingUser);
|
|
@@ -57,23 +57,19 @@ describe('GroupReportingUser', () => {
|
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
it('should throw ClassError when GroupReportingUser is not found', async () => {
|
|
60
|
-
jest
|
|
61
|
-
.spyOn(GroupReportingUserRepository.prototype, 'findByPk')
|
|
62
|
-
.mockResolvedValue(null);
|
|
60
|
+
jest.spyOn(GroupReportingUserRepository.prototype, 'findByPk').mockResolvedValue(null);
|
|
63
61
|
|
|
64
62
|
await expect(
|
|
65
|
-
GroupReportingUser.init(mockDbTransaction, '1')
|
|
63
|
+
GroupReportingUser.init(mockDbTransaction, '1')
|
|
66
64
|
).rejects.toThrow(ClassError);
|
|
67
65
|
});
|
|
68
66
|
|
|
69
67
|
it('should throw ClassError when failed to initialize GroupReportingUser', async () => {
|
|
70
|
-
jest
|
|
71
|
-
.spyOn(GroupReportingUserRepository.prototype, 'findByPk')
|
|
72
|
-
.mockRejectedValue(new Error());
|
|
68
|
+
jest.spyOn(GroupReportingUserRepository.prototype, 'findByPk').mockRejectedValue(new Error());
|
|
73
69
|
|
|
74
70
|
await expect(
|
|
75
|
-
GroupReportingUser.init(mockDbTransaction, '1')
|
|
71
|
+
GroupReportingUser.init(mockDbTransaction, '1')
|
|
76
72
|
).rejects.toThrow(Error);
|
|
77
73
|
});
|
|
78
74
|
});
|
|
79
|
-
});
|
|
75
|
+
});
|
|
@@ -9,7 +9,6 @@ import { YN } from '../../../../src/enum/yn.enum';
|
|
|
9
9
|
import SystemPrivilegeModel from '../../../../src/models/system-privilege.entity';
|
|
10
10
|
import { GroupSystemAccessRepository } from '../../../../src/components/group-system-access/group-system-access.repository';
|
|
11
11
|
import { GroupRepository } from '../../../../src/components/group/group.repository';
|
|
12
|
-
import axios from 'axios';
|
|
13
12
|
|
|
14
13
|
const mockUserData = {
|
|
15
14
|
UserId: 1,
|
|
@@ -59,19 +58,11 @@ describe('LoginUser', () => {
|
|
|
59
58
|
let sessionService: any;
|
|
60
59
|
let userId: number;
|
|
61
60
|
let dbTransaction: any;
|
|
62
|
-
const mockLoginApiEndpoint = {
|
|
63
|
-
baseUrl: 'http://sso-api',
|
|
64
|
-
getProfile: '/get-profile',
|
|
65
|
-
apiKey: 'test-api-key',
|
|
66
|
-
};
|
|
67
61
|
|
|
68
62
|
beforeEach(() => {
|
|
69
63
|
sessionService = {};
|
|
70
64
|
userId = 1;
|
|
71
65
|
dbTransaction = null;
|
|
72
|
-
jest
|
|
73
|
-
.spyOn(ComponentConfig, 'getComponentConfigValue')
|
|
74
|
-
.mockReturnValue(mockLoginApiEndpoint as any);
|
|
75
66
|
});
|
|
76
67
|
|
|
77
68
|
it('should initialize LoginUser with valid userId', async () => {
|
|
@@ -102,9 +93,9 @@ describe('LoginUser', () => {
|
|
|
102
93
|
},
|
|
103
94
|
};
|
|
104
95
|
|
|
105
|
-
const
|
|
106
|
-
.spyOn(
|
|
107
|
-
.mockResolvedValueOnce(
|
|
96
|
+
const findOneMock = jest
|
|
97
|
+
.spyOn(UserRepository.prototype, 'findOne')
|
|
98
|
+
.mockResolvedValueOnce(user as any);
|
|
108
99
|
|
|
109
100
|
const result = await LoginUser.init(
|
|
110
101
|
sessionService,
|
|
@@ -112,29 +103,63 @@ describe('LoginUser', () => {
|
|
|
112
103
|
dbTransaction,
|
|
113
104
|
);
|
|
114
105
|
|
|
115
|
-
expect(
|
|
116
|
-
expect(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
106
|
+
expect(findOneMock).toHaveBeenCalledTimes(1);
|
|
107
|
+
expect(findOneMock).toHaveBeenCalledWith({
|
|
108
|
+
where: {
|
|
109
|
+
UserId: userId,
|
|
110
|
+
},
|
|
111
|
+
include: [
|
|
112
|
+
{
|
|
113
|
+
model: expect.anything(),
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
transaction: dbTransaction,
|
|
117
|
+
});
|
|
121
118
|
expect(result).toBeInstanceOf(LoginUser);
|
|
122
119
|
expect(result.UserId).toBe(user.UserId);
|
|
123
120
|
expect(result.FullName).toBe(user.FullName);
|
|
124
121
|
expect(result.Email).toBe(user.Email);
|
|
122
|
+
expect(result.Password).toBe(user.Password);
|
|
125
123
|
expect(result.Status).toBe(user.Status);
|
|
124
|
+
expect(result.DefaultPasswordChangedYN).toBe(
|
|
125
|
+
user.DefaultPasswordChangedYN,
|
|
126
|
+
);
|
|
127
|
+
expect(result.FirstLoginAt).toBe(user.FirstLoginAt);
|
|
128
|
+
expect(result.LastLoginAt).toBe(user.LastLoginAt);
|
|
129
|
+
expect(result.MFAEnabled).toBe(user.MFAEnabled);
|
|
130
|
+
expect(result.MFAConfig).toBe(user.MFAConfig);
|
|
131
|
+
expect(result.RecoveryEmail).toBe(user.RecoveryEmail);
|
|
132
|
+
expect(result.FailedLoginAttemptCount).toBe(user.FailedLoginAttemptCount);
|
|
133
|
+
expect(result.LastFailedLoginAt).toBe(user.LastFailedLoginAt);
|
|
134
|
+
expect(result.LastPasswordChangedAt).toBe(user.LastPasswordChangedAt);
|
|
135
|
+
expect(result.NeedToChangePasswordYN).toBe(user.NeedToChangePasswordYN);
|
|
136
|
+
expect(result.CreatedById).toBe(user.CreatedById);
|
|
137
|
+
expect(result.CreatedAt).toBe(user.CreatedAt);
|
|
138
|
+
expect(result.UpdatedById).toBe(user.UpdatedById);
|
|
139
|
+
expect(result.UpdatedAt).toBe(user.UpdatedAt);
|
|
126
140
|
});
|
|
127
141
|
|
|
128
142
|
it('should throw an error when user is not found', async () => {
|
|
129
|
-
const
|
|
130
|
-
.spyOn(
|
|
131
|
-
.mockResolvedValueOnce(
|
|
143
|
+
const findOneMock = jest
|
|
144
|
+
.spyOn(UserRepository.prototype, 'findOne')
|
|
145
|
+
.mockResolvedValueOnce(null);
|
|
132
146
|
|
|
133
147
|
await expect(
|
|
134
148
|
LoginUser.init(sessionService, userId, dbTransaction),
|
|
135
149
|
).rejects.toThrow(Error);
|
|
136
150
|
|
|
137
|
-
expect(
|
|
151
|
+
expect(findOneMock).toHaveBeenCalledTimes(1);
|
|
152
|
+
expect(findOneMock).toHaveBeenCalledWith({
|
|
153
|
+
where: {
|
|
154
|
+
UserId: userId,
|
|
155
|
+
},
|
|
156
|
+
include: [
|
|
157
|
+
{
|
|
158
|
+
model: expect.anything(),
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
transaction: dbTransaction,
|
|
162
|
+
});
|
|
138
163
|
});
|
|
139
164
|
});
|
|
140
165
|
|
|
@@ -864,19 +889,10 @@ describe('LoginUser', () => {
|
|
|
864
889
|
});
|
|
865
890
|
|
|
866
891
|
describe('checkPrivileges', () => {
|
|
867
|
-
const mockLoginApiEndpoint = {
|
|
868
|
-
baseUrl: 'http://sso-api',
|
|
869
|
-
checkPrivileges: '/check-privileges',
|
|
870
|
-
apiKey: 'test-api-key',
|
|
871
|
-
};
|
|
872
|
-
|
|
873
892
|
beforeEach(() => {
|
|
874
893
|
jest
|
|
875
894
|
.spyOn(ApplicationConfig, 'getComponentConfigValue')
|
|
876
895
|
.mockReturnValue('test-session' as any);
|
|
877
|
-
jest
|
|
878
|
-
.spyOn(ComponentConfig, 'getComponentConfigValue')
|
|
879
|
-
.mockReturnValue(mockLoginApiEndpoint as any);
|
|
880
896
|
});
|
|
881
897
|
|
|
882
898
|
it('should return true if user has the specified privilege', async () => {
|
|
@@ -887,10 +903,19 @@ describe('LoginUser', () => {
|
|
|
887
903
|
const loginUser = await LoginUser.init(sessionService);
|
|
888
904
|
loginUser.ObjectId = '1';
|
|
889
905
|
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
.
|
|
893
|
-
|
|
906
|
+
// Mock the necessary methods
|
|
907
|
+
const rus = jest
|
|
908
|
+
.spyOn(SessionService.prototype, 'retrieveUserSession')
|
|
909
|
+
.mockResolvedValueOnce({
|
|
910
|
+
systemLogins: [
|
|
911
|
+
{
|
|
912
|
+
id: '1',
|
|
913
|
+
sessionId: 'sessionId',
|
|
914
|
+
code: systemCode,
|
|
915
|
+
privileges: [privilegeName],
|
|
916
|
+
},
|
|
917
|
+
],
|
|
918
|
+
});
|
|
894
919
|
// Act
|
|
895
920
|
const hasPrivilege = await loginUser.checkPrivileges(
|
|
896
921
|
systemCode,
|
|
@@ -899,11 +924,7 @@ describe('LoginUser', () => {
|
|
|
899
924
|
|
|
900
925
|
// Assert
|
|
901
926
|
expect(hasPrivilege).toBe(true);
|
|
902
|
-
expect(
|
|
903
|
-
`${mockLoginApiEndpoint.baseUrl}${mockLoginApiEndpoint.checkPrivileges}`,
|
|
904
|
-
{ SystemCode: systemCode, SessionName: 'test-session', PrivilegeName: privilegeName, UserId: '1' },
|
|
905
|
-
{ headers: { 'Content-Type': 'application/json', 'x-api-key': mockLoginApiEndpoint.apiKey } },
|
|
906
|
-
);
|
|
927
|
+
expect(rus).toHaveBeenCalledWith(loginUser.ObjectId, 'test-session');
|
|
907
928
|
});
|
|
908
929
|
|
|
909
930
|
it('should return false if user does not have the specified privilege', async () => {
|
|
@@ -914,10 +935,19 @@ describe('LoginUser', () => {
|
|
|
914
935
|
const loginUser = await LoginUser.init(sessionService);
|
|
915
936
|
loginUser.ObjectId = '1';
|
|
916
937
|
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
.
|
|
920
|
-
|
|
938
|
+
// Mock the necessary methods
|
|
939
|
+
const rus = jest
|
|
940
|
+
.spyOn(SessionService.prototype, 'retrieveUserSession')
|
|
941
|
+
.mockResolvedValueOnce({
|
|
942
|
+
systemLogins: [
|
|
943
|
+
{
|
|
944
|
+
id: '1',
|
|
945
|
+
sessionId: 'sessionId',
|
|
946
|
+
code: systemCode,
|
|
947
|
+
privileges: [],
|
|
948
|
+
},
|
|
949
|
+
],
|
|
950
|
+
});
|
|
921
951
|
// Act
|
|
922
952
|
const hasPrivilege = await loginUser.checkPrivileges(
|
|
923
953
|
systemCode,
|
|
@@ -926,6 +956,7 @@ describe('LoginUser', () => {
|
|
|
926
956
|
|
|
927
957
|
// Assert
|
|
928
958
|
expect(hasPrivilege).toBe(false);
|
|
959
|
+
expect(rus).toHaveBeenCalledWith(loginUser.ObjectId, 'test-session');
|
|
929
960
|
});
|
|
930
961
|
|
|
931
962
|
it('should throw an error if ObjectId is not set', async () => {
|