Skip to content

Commit aadb9c5

Browse files
committed
Address comments
1 parent fd217be commit aadb9c5

File tree

3 files changed

+61
-37
lines changed

3 files changed

+61
-37
lines changed

spec/ValidationAndPasswordsReset.spec.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"use strict";
22

3-
var request = require('request');
4-
var Config = require("../src/Config");
3+
let MockEmailAdapterWithOptions = require('./MockEmailAdapterWithOptions');
4+
let request = require('request');
5+
let Config = require("../src/Config");
6+
57
describe("Custom Pages Configuration", () => {
68
it("should set the custom pages", (done) => {
79
setServerConfiguration({
@@ -282,6 +284,38 @@ describe("Email Verification", () => {
282284
});
283285
});
284286

287+
it('fails if you set include an emailAdapter, set verifyUserEmails to false, dont set a publicServerURL, and try to send a password reset email (regression test for #1649)', done => {
288+
setServerConfiguration({
289+
serverURL: 'http://localhost:8378/1',
290+
appId: 'test',
291+
appName: 'unused',
292+
javascriptKey: 'test',
293+
dotNetKey: 'windows',
294+
clientKey: 'client',
295+
restAPIKey: 'rest',
296+
masterKey: 'test',
297+
collectionPrefix: 'test_',
298+
fileKey: 'test',
299+
verifyUserEmails: false,
300+
emailAdapter: MockEmailAdapterWithOptions({
301+
fromAddress: '[email protected]',
302+
apiKey: 'k',
303+
domain: 'd',
304+
}),
305+
})
306+
307+
let user = new Parse.User();
308+
user.setPassword("asdf");
309+
user.setUsername("zxcv");
310+
user.set("email", "[email protected]");
311+
user.signUp(null)
312+
.then(user => Parse.User.requestPasswordReset("[email protected]"))
313+
.catch(error => {
314+
expect(error.message).toEqual('An appName, publicServerURL, and emailAdapter are required for password reset functionality.')
315+
done();
316+
});
317+
});
318+
285319
it('does not send verification email if email verification is disabled', done => {
286320
var emailAdapter = {
287321
sendVerificationEmail: () => Promise.resolve(),

spec/index.spec.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -361,26 +361,4 @@ describe('server', () => {
361361
expect(() => setServerConfiguration({ revokeSessionOnPasswordReset: 'non-bool' })).toThrow();
362362
done();
363363
});
364-
365-
it('fails if you set verifyUserEmails to true without setting an app ID or publicServerURL (regression test for #1649)', done => {
366-
expect(() => setServerConfiguration({
367-
serverURL: 'http://localhost:8378/1',
368-
appId: 'test',
369-
appName: 'unused',
370-
javascriptKey: 'test',
371-
dotNetKey: 'windows',
372-
clientKey: 'client',
373-
restAPIKey: 'rest',
374-
masterKey: 'test',
375-
collectionPrefix: 'test_',
376-
fileKey: 'test',
377-
verifyUserEmails: true,
378-
emailAdapter: MockEmailAdapterWithOptions({
379-
fromAddress: '[email protected]',
380-
apiKey: 'k',
381-
domain: 'd',
382-
}),
383-
})).toThrow('A public server url is required when using email verification.');
384-
done();
385-
});
386364
});

src/Routers/UsersRouter.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// These methods handle the User-related routes.
22

33
import deepcopy from 'deepcopy';
4-
4+
import Config from '../Config';
55
import ClassesRouter from './ClassesRouter';
66
import PromiseRouter from '../PromiseRouter';
77
import rest from '../rest';
@@ -155,19 +155,31 @@ export class UsersRouter extends ClassesRouter {
155155
}
156156

157157
handleResetRequest(req) {
158-
let { email } = req.body;
159-
if (!email) {
160-
throw new Parse.Error(Parse.Error.EMAIL_MISSING, "you must provide an email");
161-
}
162-
let userController = req.config.userController;
163-
158+
try {
159+
Config.validateEmailConfiguration({
160+
verifyUserEmails: true, //A bit of a hack, as this isn't the intended purpose of this parameter
161+
appName: req.config.appName,
162+
publicServerURL: req.config.publicServerURL,
163+
});
164+
} catch (e) {
165+
if (typeof e === 'string') {
166+
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'An appName, publicServerURL, and emailAdapter are required for password reset functionality.');
167+
} else {
168+
throw e;
169+
}
170+
}
171+
let { email } = req.body;
172+
if (!email) {
173+
throw new Parse.Error(Parse.Error.EMAIL_MISSING, "you must provide an email");
174+
}
175+
let userController = req.config.userController;
164176
return userController.sendPasswordResetEmail(email).then((token) => {
165-
return Promise.resolve({
166-
response: {}
167-
});
168-
}, (err) => {
169-
throw new Parse.Error(Parse.Error.EMAIL_NOT_FOUND, `no user found with email ${email}`);
170-
});
177+
return Promise.resolve({
178+
response: {}
179+
});
180+
}, (err) => {
181+
throw new Parse.Error(Parse.Error.EMAIL_NOT_FOUND, `no user found with email ${email}`);
182+
});
171183
}
172184

173185

0 commit comments

Comments
 (0)