Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"files": [
"bin/",
"lib/",
"public_html/",
"public/",
"views/",
"LICENSE",
"NOTICE",
Expand Down
55 changes: 55 additions & 0 deletions spec/PagesRouter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,61 @@ describe('Pages Router', () => {
});
});

describe('async publicServerURL', () => {
it('resolves async publicServerURL for password reset page', async () => {
const emailAdapter = {
sendVerificationEmail: () => Promise.resolve(),
sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => {},
};
await reconfigureServer({
appId: 'test',
appName: 'exampleAppname',
verifyUserEmails: true,
emailAdapter,
publicServerURL: () => 'http://localhost:8378/1',
pages: { enableRouter: true },
});

const user = new Parse.User();
user.setUsername('asyncUrlUser');
user.setPassword('examplePassword');
user.set('email', 'async-url@example.com');
await user.signUp();
await Parse.User.requestPasswordReset('async-url@example.com');

const response = await request({
url: 'http://localhost:8378/1/apps/test/request_password_reset?token=invalidToken',
followRedirects: false,
}).catch(e => e);
expect(response.status).toBe(200);
expect(response.text).toContain('Invalid password reset link!');
});

it('resolves async publicServerURL for email verification page', async () => {
const emailAdapter = {
sendVerificationEmail: () => Promise.resolve(),
sendPasswordResetEmail: () => Promise.resolve(),
sendMail: () => {},
};
await reconfigureServer({
appId: 'test',
appName: 'exampleAppname',
verifyUserEmails: true,
emailAdapter,
publicServerURL: () => 'http://localhost:8378/1',
pages: { enableRouter: true },
});

const response = await request({
url: 'http://localhost:8378/1/apps/test/verify_email?token=invalidToken',
followRedirects: false,
}).catch(e => e);
expect(response.status).toBe(200);
expect(response.text).toContain('Invalid verification link!');
});
});

describe('XSS Protection', () => {
beforeEach(async () => {
await reconfigureServer({
Expand Down
20 changes: 11 additions & 9 deletions src/Routers/PagesRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,20 +624,22 @@ export class PagesRouter extends PromiseRouter {
* @param {Boolean} failGracefully Is true if failing to set the config should
* not result in an invalid request response. Default is `false`.
*/
setConfig(req, failGracefully = false) {
async setConfig(req, failGracefully = false) {
req.config = Config.get(req.params.appId || req.query.appId);
if (!req.config && !failGracefully) {
this.invalidRequest();
}
return Promise.resolve();
if (req.config) {
await req.config.loadKeys();
}
}

mountPagesRoutes() {
this.route(
'GET',
`/${this.pagesEndpoint}/:appId/verify_email`,
req => {
this.setConfig(req);
return this.setConfig(req);
},
req => {
return this.verifyEmail(req);
Expand All @@ -648,7 +650,7 @@ export class PagesRouter extends PromiseRouter {
'POST',
`/${this.pagesEndpoint}/:appId/resend_verification_email`,
req => {
this.setConfig(req);
return this.setConfig(req);
},
req => {
return this.resendVerificationEmail(req);
Expand All @@ -659,7 +661,7 @@ export class PagesRouter extends PromiseRouter {
'GET',
`/${this.pagesEndpoint}/choose_password`,
req => {
this.setConfig(req);
return this.setConfig(req);
},
req => {
return this.passwordReset(req);
Expand All @@ -670,7 +672,7 @@ export class PagesRouter extends PromiseRouter {
'POST',
`/${this.pagesEndpoint}/:appId/request_password_reset`,
req => {
this.setConfig(req);
return this.setConfig(req);
},
req => {
return this.resetPassword(req);
Expand All @@ -681,7 +683,7 @@ export class PagesRouter extends PromiseRouter {
'GET',
`/${this.pagesEndpoint}/:appId/request_password_reset`,
req => {
this.setConfig(req);
return this.setConfig(req);
},
req => {
return this.requestResetPassword(req);
Expand All @@ -695,7 +697,7 @@ export class PagesRouter extends PromiseRouter {
route.method,
`/${this.pagesEndpoint}/:appId/${route.path}`,
req => {
this.setConfig(req);
return this.setConfig(req);
},
async req => {
const { file, query = {} } = (await route.handler(req)) || {};
Expand All @@ -718,7 +720,7 @@ export class PagesRouter extends PromiseRouter {
'GET',
`/${this.pagesEndpoint}/*resource`,
req => {
this.setConfig(req, true);
return this.setConfig(req, true);
},
req => {
return this.staticRoute(req);
Expand Down
Loading