@umituz/react-native-auth 3.4.22 → 3.4.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.
- package/package.json +1 -1
- package/src/__tests__/services/AnonymousModeService.test.ts +22 -153
- package/src/__tests__/services/AuthCoreInitialization.test.ts +45 -0
- package/src/__tests__/services/AuthCoreOperations.test.ts +71 -0
- package/src/__tests__/services/AuthPackage.test.ts +24 -171
- package/src/__tests__/utils/AuthDisplayNameValidation.test.ts +44 -0
- package/src/__tests__/utils/AuthEmailValidation.test.ts +38 -0
- package/src/__tests__/utils/AuthPasswordValidation.test.ts +90 -0
- package/src/index.ts +11 -95
- package/src/infrastructure/services/UserDocument.types.ts +44 -0
- package/src/infrastructure/services/UserDocumentService.ts +33 -106
- package/src/infrastructure/utils/AuthValidation.ts +37 -156
- package/src/__tests__/services/AuthCoreService.test.ts +0 -247
- package/src/__tests__/utils/AuthValidation.test.ts +0 -270
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AuthValidation Tests
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
validateEmail,
|
|
7
|
-
validatePasswordForLogin,
|
|
8
|
-
validatePasswordForRegister,
|
|
9
|
-
validatePasswordConfirmation,
|
|
10
|
-
validateDisplayName,
|
|
11
|
-
} from '../../../src/infrastructure/utils/AuthValidation';
|
|
12
|
-
import { DEFAULT_PASSWORD_CONFIG } from '../../../src/domain/value-objects/AuthConfig';
|
|
13
|
-
import { initializeAuthPackage } from '../../../src/infrastructure/services/AuthPackage';
|
|
14
|
-
|
|
15
|
-
describe('AuthValidation', () => {
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
// Reset package config before each test
|
|
18
|
-
initializeAuthPackage();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe('validateEmail', () => {
|
|
22
|
-
it('should reject empty email', () => {
|
|
23
|
-
const result = validateEmail('');
|
|
24
|
-
expect(result.isValid).toBe(false);
|
|
25
|
-
expect(result.error).toBe('Email is required');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should reject whitespace-only email', () => {
|
|
29
|
-
const result = validateEmail(' ');
|
|
30
|
-
expect(result.isValid).toBe(false);
|
|
31
|
-
expect(result.error).toBe('Email is required');
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should reject invalid email format', () => {
|
|
35
|
-
const result = validateEmail('invalid-email');
|
|
36
|
-
expect(result.isValid).toBe(false);
|
|
37
|
-
expect(result.error).toBe('Please enter a valid email address');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('should accept valid email format', () => {
|
|
41
|
-
const result = validateEmail('test@example.com');
|
|
42
|
-
expect(result.isValid).toBe(true);
|
|
43
|
-
expect(result.error).toBeUndefined();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('should accept valid email with subdomain', () => {
|
|
47
|
-
const result = validateEmail('test@mail.example.com');
|
|
48
|
-
expect(result.isValid).toBe(true);
|
|
49
|
-
expect(result.error).toBeUndefined();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should trim whitespace', () => {
|
|
53
|
-
const result = validateEmail(' test@example.com ');
|
|
54
|
-
expect(result.isValid).toBe(true);
|
|
55
|
-
expect(result.error).toBeUndefined();
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('validatePasswordForLogin', () => {
|
|
60
|
-
it('should reject empty password', () => {
|
|
61
|
-
const result = validatePasswordForLogin('');
|
|
62
|
-
expect(result.isValid).toBe(false);
|
|
63
|
-
expect(result.error).toBe('Password is required');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('should accept any non-empty password', () => {
|
|
67
|
-
const result = validatePasswordForLogin('any');
|
|
68
|
-
expect(result.isValid).toBe(true);
|
|
69
|
-
expect(result.error).toBeUndefined();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should accept password with spaces', () => {
|
|
73
|
-
const result = validatePasswordForLogin(' password ');
|
|
74
|
-
expect(result.isValid).toBe(true);
|
|
75
|
-
expect(result.error).toBeUndefined();
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe('validatePasswordForRegister', () => {
|
|
80
|
-
const config = DEFAULT_PASSWORD_CONFIG;
|
|
81
|
-
|
|
82
|
-
it('should reject empty password', () => {
|
|
83
|
-
const result = validatePasswordForRegister('', config);
|
|
84
|
-
expect(result.isValid).toBe(false);
|
|
85
|
-
expect(result.error).toBe('Password is required');
|
|
86
|
-
expect(result.requirements.hasMinLength).toBe(false);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('should reject password that is too short', () => {
|
|
90
|
-
const result = validatePasswordForRegister('123', config);
|
|
91
|
-
expect(result.isValid).toBe(false);
|
|
92
|
-
expect(result.error).toBe(`Password must be at least ${config.minLength} characters`);
|
|
93
|
-
expect(result.requirements.hasMinLength).toBe(false);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should accept password that meets minimum length', () => {
|
|
97
|
-
const result = validatePasswordForRegister('12345678', config);
|
|
98
|
-
expect(result.requirements.hasMinLength).toBe(true);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should validate uppercase requirement', () => {
|
|
102
|
-
const configWithUppercase = {
|
|
103
|
-
...config,
|
|
104
|
-
requireUppercase: true,
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
const result = validatePasswordForRegister('password', configWithUppercase);
|
|
108
|
-
expect(result.isValid).toBe(false);
|
|
109
|
-
expect(result.error).toBe('Password must contain at least one uppercase letter');
|
|
110
|
-
expect(result.requirements.hasUppercase).toBe(false);
|
|
111
|
-
|
|
112
|
-
const validResult = validatePasswordForRegister('Password', configWithUppercase);
|
|
113
|
-
expect(validResult.requirements.hasUppercase).toBe(true);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should validate lowercase requirement', () => {
|
|
117
|
-
const configWithLowercase = {
|
|
118
|
-
...config,
|
|
119
|
-
requireLowercase: true,
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const result = validatePasswordForRegister('PASSWORD', configWithLowercase);
|
|
123
|
-
expect(result.isValid).toBe(false);
|
|
124
|
-
expect(result.error).toBe('Password must contain at least one lowercase letter');
|
|
125
|
-
expect(result.requirements.hasLowercase).toBe(false);
|
|
126
|
-
|
|
127
|
-
const validResult = validatePasswordForRegister('Password', configWithLowercase);
|
|
128
|
-
expect(validResult.requirements.hasLowercase).toBe(true);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('should validate number requirement', () => {
|
|
132
|
-
const configWithNumber = {
|
|
133
|
-
...config,
|
|
134
|
-
requireNumber: true,
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const result = validatePasswordForRegister('Password', configWithNumber);
|
|
138
|
-
expect(result.isValid).toBe(false);
|
|
139
|
-
expect(result.error).toBe('Password must contain at least one number');
|
|
140
|
-
expect(result.requirements.hasNumber).toBe(false);
|
|
141
|
-
|
|
142
|
-
const validResult = validatePasswordForRegister('Password1', configWithNumber);
|
|
143
|
-
expect(validResult.requirements.hasNumber).toBe(true);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('should validate special character requirement', () => {
|
|
147
|
-
const configWithSpecial = {
|
|
148
|
-
...config,
|
|
149
|
-
requireSpecialChar: true,
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const result = validatePasswordForRegister('Password1', configWithSpecial);
|
|
153
|
-
expect(result.isValid).toBe(false);
|
|
154
|
-
expect(result.error).toBe('Password must contain at least one special character');
|
|
155
|
-
expect(result.requirements.hasSpecialChar).toBe(false);
|
|
156
|
-
|
|
157
|
-
const validResult = validatePasswordForRegister('Password1!', configWithSpecial);
|
|
158
|
-
expect(validResult.requirements.hasSpecialChar).toBe(true);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('should accept password that meets all requirements', () => {
|
|
162
|
-
const strictConfig = {
|
|
163
|
-
...config,
|
|
164
|
-
requireUppercase: true,
|
|
165
|
-
requireLowercase: true,
|
|
166
|
-
requireNumber: true,
|
|
167
|
-
requireSpecialChar: true,
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
const result = validatePasswordForRegister('Password1!', strictConfig);
|
|
171
|
-
expect(result.isValid).toBe(true);
|
|
172
|
-
expect(result.requirements).toEqual({
|
|
173
|
-
hasMinLength: true,
|
|
174
|
-
hasUppercase: true,
|
|
175
|
-
hasLowercase: true,
|
|
176
|
-
hasNumber: true,
|
|
177
|
-
hasSpecialChar: true,
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('should skip requirements when disabled', () => {
|
|
182
|
-
const lenientConfig = {
|
|
183
|
-
...config,
|
|
184
|
-
requireUppercase: false,
|
|
185
|
-
requireLowercase: false,
|
|
186
|
-
requireNumber: false,
|
|
187
|
-
requireSpecialChar: false,
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
const result = validatePasswordForRegister('password', lenientConfig);
|
|
191
|
-
expect(result.requirements).toEqual({
|
|
192
|
-
hasMinLength: true,
|
|
193
|
-
hasUppercase: true, // Should be true when requirement is disabled
|
|
194
|
-
hasLowercase: true, // Should be true when requirement is disabled
|
|
195
|
-
hasNumber: true, // Should be true when requirement is disabled
|
|
196
|
-
hasSpecialChar: true, // Should be true when requirement is disabled
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
describe('validatePasswordConfirmation', () => {
|
|
202
|
-
it('should reject empty confirmation', () => {
|
|
203
|
-
const result = validatePasswordConfirmation('password', '');
|
|
204
|
-
expect(result.isValid).toBe(false);
|
|
205
|
-
expect(result.error).toBe('Please confirm your password');
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('should reject mismatched passwords', () => {
|
|
209
|
-
const result = validatePasswordConfirmation('password', 'different');
|
|
210
|
-
expect(result.isValid).toBe(false);
|
|
211
|
-
expect(result.error).toBe('Passwords do not match');
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it('should accept matching passwords', () => {
|
|
215
|
-
const result = validatePasswordConfirmation('password', 'password');
|
|
216
|
-
expect(result.isValid).toBe(true);
|
|
217
|
-
expect(result.error).toBeUndefined();
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('should handle empty passwords that match', () => {
|
|
221
|
-
const result = validatePasswordConfirmation('', '');
|
|
222
|
-
expect(result.isValid).toBe(true);
|
|
223
|
-
expect(result.error).toBeUndefined();
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
describe('validateDisplayName', () => {
|
|
228
|
-
it('should reject empty name', () => {
|
|
229
|
-
const result = validateDisplayName('');
|
|
230
|
-
expect(result.isValid).toBe(false);
|
|
231
|
-
expect(result.error).toBe('Name is required');
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it('should reject whitespace-only name', () => {
|
|
235
|
-
const result = validateDisplayName(' ');
|
|
236
|
-
expect(result.isValid).toBe(false);
|
|
237
|
-
expect(result.error).toBe('Name is required');
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it('should reject name that is too short', () => {
|
|
241
|
-
const result = validateDisplayName('A');
|
|
242
|
-
expect(result.isValid).toBe(false);
|
|
243
|
-
expect(result.error).toBe('Name must be at least 2 characters');
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it('should accept name that meets minimum length', () => {
|
|
247
|
-
const result = validateDisplayName('Al');
|
|
248
|
-
expect(result.isValid).toBe(true);
|
|
249
|
-
expect(result.error).toBeUndefined();
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it('should use custom minimum length', () => {
|
|
253
|
-
const result = validateDisplayName('Al', 3);
|
|
254
|
-
expect(result.isValid).toBe(false);
|
|
255
|
-
expect(result.error).toBe('Name must be at least 3 characters');
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
it('should trim whitespace', () => {
|
|
259
|
-
const result = validateDisplayName(' John Doe ');
|
|
260
|
-
expect(result.isValid).toBe(true);
|
|
261
|
-
expect(result.error).toBeUndefined();
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it('should accept name with special characters', () => {
|
|
265
|
-
const result = validateDisplayName('John-O\'Connor');
|
|
266
|
-
expect(result.isValid).toBe(true);
|
|
267
|
-
expect(result.error).toBeUndefined();
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
});
|