@tomei/sso 0.15.3 → 0.15.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -430,7 +430,7 @@ describe('login-user', () => {
430
430
  .spyOn(SystemRepository.prototype, 'findOne')
431
431
  .mockResolvedValue(system as any);
432
432
 
433
- jest.spyOn(SMTPMailer.prototype, 'send').mockImplementation(async () => {});
433
+ jest.spyOn(SMTPMailer.prototype, 'send').mockImplementation(async () => { });
434
434
 
435
435
  const getUserGroupFromDBMock = jest.spyOn(
436
436
  LoginUser.prototype as any,
@@ -503,7 +503,7 @@ describe('login-user', () => {
503
503
 
504
504
  it('should able to do login process when no session is already available', async () => {
505
505
  const sessionService = await SessionService.init();
506
- const loginUser = await LoginUser.init(sessionService, '755');
506
+ const loginUser = await LoginUser.init(sessionService, 755);
507
507
  const result = await loginUser.login(
508
508
  'EZC',
509
509
  'ezcash+florence@tomei.com.my',
@@ -515,7 +515,7 @@ describe('login-user', () => {
515
515
 
516
516
  it('should able to do login process when session is already available', async () => {
517
517
  const sessionService = await SessionService.init();
518
- const loginUser = await LoginUser.init(sessionService, '755');
518
+ const loginUser = await LoginUser.init(sessionService, 755);
519
519
  const result = await loginUser.login(
520
520
  'EZC',
521
521
  'ezcash+florence@tomei.com.my',
@@ -533,7 +533,7 @@ describe('login-user', () => {
533
533
 
534
534
  it('should be able to login when user only have one user group with level 1 or higher', async () => {
535
535
  const sessionService = await SessionService.init();
536
- const loginUser = await LoginUser.init(sessionService, '755');
536
+ const loginUser = await LoginUser.init(sessionService, 755);
537
537
  const result = await loginUser['getPrivileges']('EZC');
538
538
  expect(getUserGroupFromDBMock).toBeCalledTimes(2);
539
539
  expect(result).toEqual([
@@ -556,7 +556,7 @@ describe('login-user', () => {
556
556
  userUserGroups.push(userUserGroups[0]);
557
557
 
558
558
  const sessionService = await SessionService.init();
559
- const loginUser = await LoginUser.init(sessionService, '755');
559
+ const loginUser = await LoginUser.init(sessionService, 755);
560
560
  const result = await loginUser['getPrivileges']('EZC');
561
561
  expect(getUserUserGroupFromDBMock).toBeCalledTimes(1);
562
562
  expect(getUserGroupFromDBMock).toBeCalledTimes(4);
@@ -582,7 +582,7 @@ describe('login-user', () => {
582
582
  userUserGroups = [];
583
583
 
584
584
  const sessionService = await SessionService.init();
585
- const loginUser = await LoginUser.init(sessionService, '755');
585
+ const loginUser = await LoginUser.init(sessionService, 755);
586
586
  const result = await loginUser['getPrivileges']('EZC');
587
587
  expect(getUserGroupFromDBMock).toBeCalledTimes(0);
588
588
  expect(result).toEqual(['Terminate Data']);
@@ -597,7 +597,7 @@ describe('login-user', () => {
597
597
  user.SystemPrivileges = [];
598
598
 
599
599
  const sessionService = await SessionService.init();
600
- const loginUser = await LoginUser.init(sessionService, '755');
600
+ const loginUser = await LoginUser.init(sessionService, 755);
601
601
  const result = await loginUser['getPrivileges']('EZC');
602
602
  expect(getUserGroupFromDBMock).toBeCalledTimes(0);
603
603
  expect(result).toEqual([
@@ -619,7 +619,7 @@ describe('login-user', () => {
619
619
  user.SystemPrivileges = [];
620
620
 
621
621
  const sessionService = await SessionService.init();
622
- const loginUser = await LoginUser.init(sessionService, '755');
622
+ const loginUser = await LoginUser.init(sessionService, 755);
623
623
  const result = await loginUser['getPrivileges']('EZC');
624
624
  expect(getUserGroupFromDBMock).toBeCalledTimes(0);
625
625
  expect(result).toEqual([
@@ -640,7 +640,7 @@ describe('login-user', () => {
640
640
  userUserGroups = [];
641
641
 
642
642
  const sessionService = await SessionService.init();
643
- const loginUser = await LoginUser.init(sessionService, '755');
643
+ const loginUser = await LoginUser.init(sessionService, 755);
644
644
  const result = await loginUser['getPrivileges']('EZC');
645
645
  expect(getUserGroupFromDBMock).toBeCalledTimes(0);
646
646
  expect(result).toEqual([]);
@@ -658,7 +658,7 @@ describe('login-user', () => {
658
658
  it('should return false if user session not found', async () => {
659
659
  isSessionExist = false;
660
660
  const sessionService = await SessionService.init();
661
- const loginUser = await LoginUser.init(sessionService, '755');
661
+ const loginUser = await LoginUser.init(sessionService, 755);
662
662
  const result = await loginUser.checkPrivileges('EZC', 'Terminate');
663
663
  expect(result).toEqual(false);
664
664
  });
@@ -666,7 +666,7 @@ describe('login-user', () => {
666
666
  it('should return false if system login not found', async () => {
667
667
  isSessionExist = false;
668
668
  const sessionService = await SessionService.init();
669
- const loginUser = await LoginUser.init(sessionService, '755');
669
+ const loginUser = await LoginUser.init(sessionService, 755);
670
670
  const result = await loginUser.checkPrivileges('EZC', 'Terminate');
671
671
  expect(result).toEqual(false);
672
672
  });
@@ -674,14 +674,14 @@ describe('login-user', () => {
674
674
  it('should return false if privilege not found', async () => {
675
675
  isSessionExist = false;
676
676
  const sessionService = await SessionService.init();
677
- const loginUser = await LoginUser.init(sessionService, '755');
677
+ const loginUser = await LoginUser.init(sessionService, 755);
678
678
  const result = await loginUser.checkPrivileges('EZC', 'Not Terminate');
679
679
  expect(result).toEqual(false);
680
680
  });
681
681
 
682
682
  it('should return true if privilege found', async () => {
683
683
  const sessionService = await SessionService.init();
684
- const loginUser = await LoginUser.init(sessionService, '755');
684
+ const loginUser = await LoginUser.init(sessionService, 755);
685
685
  const result = await loginUser.checkPrivileges('EZC', 'Terminate');
686
686
  expect(result).toEqual(true);
687
687
  });
@@ -696,7 +696,7 @@ describe('login-user', () => {
696
696
  try {
697
697
  isSessionExist = false;
698
698
  const sessionService = await SessionService.init();
699
- const loginUser = await LoginUser.init(sessionService, '755');
699
+ const loginUser = await LoginUser.init(sessionService, 755);
700
700
  await loginUser.checkSession(
701
701
  'EZC',
702
702
  session.systemLogins[0].sessionId,
@@ -710,7 +710,7 @@ describe('login-user', () => {
710
710
  it('it should returns session expired if sessionId not matched', async () => {
711
711
  try {
712
712
  const sessionService = await SessionService.init();
713
- const loginUser = await LoginUser.init(sessionService, '755');
713
+ const loginUser = await LoginUser.init(sessionService, 755);
714
714
  await loginUser.checkSession(
715
715
  'NOTEZC',
716
716
  session.systemLogins[0].sessionId,
@@ -730,7 +730,7 @@ describe('login-user', () => {
730
730
  }
731
731
  });
732
732
  const sessionService = await SessionService.init();
733
- const loginUser = await LoginUser.init(sessionService, '755');
733
+ const loginUser = await LoginUser.init(sessionService, 755);
734
734
  const result = await loginUser.checkSession(
735
735
  'EZC',
736
736
  session.systemLogins[0].sessionId,
@@ -0,0 +1,108 @@
1
+ 'use strict';
2
+
3
+ /** @type {import('sequelize-cli').Migration} */
4
+ module.exports = {
5
+ async up(queryInterface, Sequelize) {
6
+ await queryInterface.createTable('sso_User', {
7
+ UserId: {
8
+ primaryKey: true,
9
+ type: Sequelize.INTEGER,
10
+ allowNull: false,
11
+ autoIncrement: true,
12
+ },
13
+ Email: {
14
+ type: Sequelize.STRING,
15
+ allowNull: false,
16
+ unique: true,
17
+ },
18
+ Password: {
19
+ type: Sequelize.STRING,
20
+ allowNull: false,
21
+ },
22
+ Status: {
23
+ type: Sequelize.STRING,
24
+ allowNull: false,
25
+ },
26
+ DefaultPasswordChangedYN: {
27
+ type: Sequelize.CHAR(1),
28
+ allowNull: true,
29
+ },
30
+ FirstLoginAt: {
31
+ type: Sequelize.DATE,
32
+ allowNull: true,
33
+ },
34
+ LastLoginAt: {
35
+ type: Sequelize.DATE,
36
+ allowNull: true,
37
+ },
38
+ MFAEnabled: {
39
+ type: Sequelize.TINYINT,
40
+ allowNull: true,
41
+ },
42
+ MFAConfig: {
43
+ type: Sequelize.TEXT,
44
+ allowNull: true,
45
+ },
46
+ RecoveryEmail: {
47
+ type: Sequelize.STRING,
48
+ allowNull: true,
49
+ },
50
+ FailedLoginAttemptCount: {
51
+ type: Sequelize.INTEGER,
52
+ allowNull: false,
53
+ },
54
+ LastFailedLoginAt: {
55
+ type: Sequelize.DATE,
56
+ allowNull: true,
57
+ },
58
+ LastPasswordChangedAt: {
59
+ type: Sequelize.DATE,
60
+ allowNull: true,
61
+ },
62
+ NeedToChangePasswordYN: {
63
+ type: Sequelize.CHAR(1),
64
+ allowNull: true,
65
+ },
66
+ CreatedAt: {
67
+ allowNull: false,
68
+ defaultValue: Sequelize.literal('CURRENT_TIMESTAMP(3)'),
69
+ type: Sequelize.DATE,
70
+ },
71
+ CreatedById: {
72
+ type: Sequelize.INTEGER,
73
+ allowNull: true,
74
+ references: {
75
+ model: 'sso_User',
76
+ key: 'UserId',
77
+ },
78
+ onDelete: 'CASCADE',
79
+ onUpdate: 'CASCADE',
80
+ },
81
+ UpdatedAt: {
82
+ allowNull: false,
83
+ defaultValue: Sequelize.literal('CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)'),
84
+ type: Sequelize.DATE,
85
+ },
86
+ UpdatedById: {
87
+ type: Sequelize.INTEGER,
88
+ allowNull: true,
89
+ references: {
90
+ model: 'sso_User',
91
+ key: 'UserId',
92
+ },
93
+ onDelete: 'CASCADE',
94
+ onUpdate: 'CASCADE',
95
+ },
96
+
97
+ });
98
+ },
99
+
100
+ async down(queryInterface, Sequelize) {
101
+ /**
102
+ * Add reverting commands here.
103
+ *
104
+ * Example:
105
+ * await queryInterface.dropTable('users');
106
+ */
107
+ }
108
+ };
@@ -8,7 +8,7 @@ module.exports = {
8
8
  type: Sequelize.INTEGER,
9
9
  allowNull: false,
10
10
  references: {
11
- model: 'sso_users',
11
+ model: 'sso_User',
12
12
  key: 'id',
13
13
  },
14
14
  onDelete: 'CASCADE',
@@ -14,7 +14,7 @@ module.exports = {
14
14
  type: Sequelize.INTEGER,
15
15
  allowNull: false,
16
16
  references: {
17
- model: 'sso_users',
17
+ model: 'sso_User',
18
18
  key: 'id',
19
19
  },
20
20
  onDelete: 'CASCADE',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/sso",
3
- "version": "0.15.3",
3
+ "version": "0.15.5",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -46,6 +46,7 @@
46
46
  "prettier": "^2.7.1",
47
47
  "prisma": "^4.14.0",
48
48
  "redis-mock": "^0.56.3",
49
+ "sequelize-cli": "^6.6.2",
49
50
  "ts-jest": "^29.1.0",
50
51
  "ts-node": "^10.9.1",
51
52
  "tsc-watch": "^5.0.3",
@@ -1,9 +1,29 @@
1
- export interface IUserInfo {
2
- FullName: string;
3
- IDNo: string;
4
- Email: string;
5
- ContactNo: string;
6
- ObjectId: string;
7
- Password: string;
8
- staffs?: any;
9
- }
1
+ import { YN } from '../../../enum';
2
+
3
+ export interface IUserInfo {
4
+ FullName: string;
5
+ IDNo: string;
6
+ Email: string;
7
+ ContactNo: string;
8
+ UserId: number;
9
+ Password: string;
10
+ staffs?: any;
11
+ }
12
+
13
+ export interface IUserAttr extends IUserInfo {
14
+ Status: string;
15
+ DefaultPasswordChangedYN: YN;
16
+ FirstLoginAt: Date;
17
+ LastLoginAt: Date;
18
+ MFAEnabled: number;
19
+ MFAConfig: string;
20
+ RecoveryEmail: string;
21
+ FailedLoginAttemptCount: number;
22
+ LastFailedLoginAt: Date;
23
+ LastPasswordChangedAt: Date;
24
+ NeedToChangePasswordYN: YN;
25
+ CreatedById: number;
26
+ CreatedAt: Date;
27
+ UpdatedById: number;
28
+ UpdatedAt: Date;
29
+ }