-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathPasswordResetLink.spec.js
More file actions
82 lines (69 loc) · 2.74 KB
/
Copy pathPasswordResetLink.spec.js
File metadata and controls
82 lines (69 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
'use strict';
describe('Password Reset Link', () => {
it('should generate a password reset link with actual appId, not {appId} or undefined', async () => {
let emailLinkReceived = null;
const emailAdapter = {
sendVerificationEmail: () => Promise.resolve(),
sendPasswordResetEmail: options => {
emailLinkReceived = options.link;
// Check that the link contains the actual appId ('test'), not the literal string '{appId}'
expect(options.link).toBeDefined();
expect(options.link).not.toContain('{appId}');
expect(options.link).toContain('/test/');
return Promise.resolve();
},
sendMail: () => Promise.resolve(),
};
await reconfigureServer({
appId: 'test',
appName: 'Test App',
verifyUserEmails: true,
emailAdapter: emailAdapter,
publicServerURL: 'http://localhost:8378/1',
});
const user = new Parse.User();
user.setPassword('password');
user.setUsername('testuser');
user.set('email', 'test@example.com');
await user.signUp();
await Parse.User.requestPasswordReset('test@example.com');
// Verify the link was generated correctly
expect(emailLinkReceived).not.toBeNull();
expect(emailLinkReceived).toMatch(/\/test\/request_password_reset\?token=/);
});
it('should render password reset page with actual appId in form action', async () => {
const emailAdapter = {
sendVerificationEmail: () => Promise.resolve(),
sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => Promise.resolve(),
};
await reconfigureServer({
appId: 'test',
appName: 'Test App',
verifyUserEmails: true,
emailAdapter: emailAdapter,
publicServerURL: 'http://localhost:8378/1',
});
const user = new Parse.User();
user.setPassword('password');
user.setUsername('testuser2');
user.set('email', 'test2@example.com');
await user.signUp();
// Trigger password reset to get a token
await Parse.User.requestPasswordReset('test2@example.com');
// Find the user to get the reset token
const results = await new Parse.Query('_User')
.equalTo('email', 'test2@example.com')
.find({ useMasterKey: true });
const resetToken = results[0].get('_perishable_token');
// Request the password reset page
const response = await request({
url: `http://localhost:8378/1/apps/test/request_password_reset?token=${resetToken}`,
followRedirects: false,
});
expect(response.status).toBe(200);
// The form action should contain the actual appId 'test', not '{appId}'
expect(response.text).toContain('/apps/test/request_password_reset');
expect(response.text).not.toContain('{appId}');
});
});