Skip to content

Fix password reset, email verification for custom endpoint #7236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dc9f90d
Merge commit 'ccb045b68c5b4d983a90fa125513fc476e4e2387'
mtrezza Nov 19, 2020
4d72525
Merge remote-tracking branch 'upstream/master'
mtrezza Dec 4, 2020
65a6bdb
Merge remote-tracking branch 'upstream/master'
mtrezza Dec 5, 2020
50274b8
Merge remote-tracking branch 'upstream/master'
mtrezza Dec 8, 2020
3b337cd
Merge remote-tracking branch 'upstream/master'
mtrezza Dec 15, 2020
073f0fc
Merge remote-tracking branch 'upstream/master'
mtrezza Dec 18, 2020
2ee5907
Merge remote-tracking branch 'upstream/master'
mtrezza Dec 19, 2020
241a1d8
Merge remote-tracking branch 'upstream/master'
mtrezza Dec 26, 2020
4f097ce
Merge remote-tracking branch 'upstream/master'
mtrezza Jan 14, 2021
8f3ea1c
Merge remote-tracking branch 'upstream/master'
mtrezza Jan 23, 2021
4743cbc
Merge remote-tracking branch 'upstream/master'
mtrezza Jan 28, 2021
59de429
Merge remote-tracking branch 'upstream/master'
mtrezza Feb 1, 2021
ed2944f
Merge remote-tracking branch 'upstream/master'
mtrezza Feb 2, 2021
3ff82c8
Merge commit '7f47b0427ea56214d9b0199f0fcfa4af38794e02'
mtrezza Feb 9, 2021
19d7556
Merge remote-tracking branch 'upstream/master'
mtrezza Feb 12, 2021
935b913
Merge remote-tracking branch 'upstream/master'
mtrezza Feb 13, 2021
38f3739
Merge remote-tracking branch 'upstream/master'
mtrezza Feb 16, 2021
098a5c3
Merge remote-tracking branch 'upstream/master'
mtrezza Feb 21, 2021
669766a
Merge remote-tracking branch 'upstream/master'
mtrezza Feb 22, 2021
dcb91ee
Merge remote-tracking branch 'upstream/master'
mtrezza Feb 24, 2021
093af98
Merge remote-tracking branch 'upstream/master'
mtrezza Mar 2, 2021
bc3c9ba
fixed incorrect endpoint for password reset and email verification
mtrezza Mar 2, 2021
118320c
added tests
mtrezza Mar 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 78 additions & 1 deletion spec/PagesRouter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('Pages Router', () => {
expect(response.status).toBe(200);
});

it('responds with 404 if publicServerURL is not confgured', async () => {
it('responds with 404 if publicServerURL is not configured', async () => {
await reconfigureServer({
appName: 'unused',
pages: { enableRouter: true },
Expand Down Expand Up @@ -971,5 +971,82 @@ describe('Pages Router', () => {
expect(response.text).toBe('Not found.');
});
});

describe('custom endpoint', () => {
it('password reset works with custom endpoint', async () => {
config.pages.pagesEndpoint = 'customEndpoint';
await reconfigureServer(config);
const sendPasswordResetEmail = spyOn(
config.emailAdapter,
'sendPasswordResetEmail'
).and.callThrough();
const user = new Parse.User();
user.setUsername('exampleUsername');
user.setPassword('examplePassword');
user.set('email', '[email protected]');
await user.signUp();
await Parse.User.requestPasswordReset(user.getEmail());

const link = sendPasswordResetEmail.calls.all()[0].args[0].link;
const linkResponse = await request({
url: link,
followRedirects: false,
});
expect(linkResponse.status).toBe(200);

const appId = linkResponse.headers['x-parse-page-param-appid'];
const token = linkResponse.headers['x-parse-page-param-token'];
const username = linkResponse.headers['x-parse-page-param-username'];
const publicServerUrl = linkResponse.headers['x-parse-page-param-publicserverurl'];
const passwordResetPagePath = pageResponse.calls.all()[0].args[0];
expect(appId).toBeDefined();
expect(token).toBeDefined();
expect(username).toBeDefined();
expect(publicServerUrl).toBeDefined();
expect(passwordResetPagePath).toMatch(new RegExp(`\/${pages.passwordReset.defaultFile}`));
pageResponse.calls.reset();

const formUrl = `${publicServerUrl}/${config.pages.pagesEndpoint}/${appId}/request_password_reset`;
const formResponse = await request({
url: formUrl,
method: 'POST',
body: {
token,
username,
new_password: 'newPassword',
},
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
followRedirects: false,
});
expect(formResponse.status).toEqual(200);
expect(pageResponse.calls.all()[0].args[0]).toContain(
`/${pages.passwordResetSuccess.defaultFile}`
);
});

it('email verification works with custom endpoint', async () => {
config.pages.pagesEndpoint = 'customEndpoint';
await reconfigureServer(config);
const sendVerificationEmail = spyOn(
config.emailAdapter,
'sendVerificationEmail'
).and.callThrough();
const user = new Parse.User();
user.setUsername('exampleUsername');
user.setPassword('examplePassword');
user.set('email', '[email protected]');
await user.signUp();

const link = sendVerificationEmail.calls.all()[0].args[0].link;
const linkResponse = await request({
url: link,
followRedirects: false,
});
expect(linkResponse.status).toBe(200);

const pagePath = pageResponse.calls.all()[0].args[0];
expect(pagePath).toMatch(new RegExp(`\/${pages.emailVerificationSuccess.defaultFile}`));
});
});
});
});
12 changes: 10 additions & 2 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export class Config {
}

get requestResetPasswordURL() {
return `${this.publicServerURL}/apps/${this.applicationId}/request_password_reset`;
return `${this.publicServerURL}/${this.pagesEndpoint}/${this.applicationId}/request_password_reset`;
}

get passwordResetSuccessURL() {
Expand All @@ -466,7 +466,15 @@ export class Config {
}

get verifyEmailURL() {
return `${this.publicServerURL}/apps/${this.applicationId}/verify_email`;
return `${this.publicServerURL}/${this.pagesEndpoint}/${this.applicationId}/verify_email`;
}

// TODO: Remove this function once PagesRouter replaces the PublicAPIRouter;
// the (default) endpoint has to be defined in PagesRouter only.
get pagesEndpoint() {
return this.pages && this.pages.enableRouter && this.pages.pagesEndpoint
? this.pages.pagesEndpoint
: 'apps';
}
}

Expand Down