Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-gross committed May 10, 2016
1 parent 19b0462 commit a88ccb0
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 37 deletions.
38 changes: 36 additions & 2 deletions spec/ValidationAndPasswordsReset.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use strict";

var request = require('request');
var Config = require("../src/Config");
let MockEmailAdapterWithOptions = require('./MockEmailAdapterWithOptions');
let request = require('request');
let Config = require("../src/Config");

describe("Custom Pages Configuration", () => {
it("should set the custom pages", (done) => {
setServerConfiguration({
Expand Down Expand Up @@ -282,6 +284,38 @@ describe("Email Verification", () => {
});
});

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 => {
setServerConfiguration({
serverURL: 'http://localhost:8378/1',
appId: 'test',
appName: 'unused',
javascriptKey: 'test',
dotNetKey: 'windows',
clientKey: 'client',
restAPIKey: 'rest',
masterKey: 'test',
collectionPrefix: 'test_',
fileKey: 'test',
verifyUserEmails: false,
emailAdapter: MockEmailAdapterWithOptions({
fromAddress: '[email protected]',
apiKey: 'k',
domain: 'd',
}),
})

let user = new Parse.User();
user.setPassword("asdf");
user.setUsername("zxcv");
user.set("email", "[email protected]");
user.signUp(null)
.then(user => Parse.User.requestPasswordReset("[email protected]"))
.catch(error => {
expect(error.message).toEqual('An appName, publicServerURL, and emailAdapter are required for password reset functionality.')
done();
});
});

it('does not send verification email if email verification is disabled', done => {
var emailAdapter = {
sendVerificationEmail: () => Promise.resolve(),
Expand Down
22 changes: 0 additions & 22 deletions spec/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,26 +361,4 @@ describe('server', () => {
expect(() => setServerConfiguration({ revokeSessionOnPasswordReset: 'non-bool' })).toThrow();
done();
});

it('fails if you set verifyUserEmails to true without setting an app ID or publicServerURL (regression test for #1649)', done => {
expect(() => setServerConfiguration({
serverURL: 'http://localhost:8378/1',
appId: 'test',
appName: 'unused',
javascriptKey: 'test',
dotNetKey: 'windows',
clientKey: 'client',
restAPIKey: 'rest',
masterKey: 'test',
collectionPrefix: 'test_',
fileKey: 'test',
verifyUserEmails: true,
emailAdapter: MockEmailAdapterWithOptions({
fromAddress: '[email protected]',
apiKey: 'k',
domain: 'd',
}),
})).toThrow('A public server url is required when using email verification.');
done();
});
});
38 changes: 25 additions & 13 deletions src/Routers/UsersRouter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// These methods handle the User-related routes.

import deepcopy from 'deepcopy';

import Config from '../Config';
import ClassesRouter from './ClassesRouter';
import PromiseRouter from '../PromiseRouter';
import rest from '../rest';
Expand Down Expand Up @@ -155,19 +155,31 @@ export class UsersRouter extends ClassesRouter {
}

handleResetRequest(req) {
let { email } = req.body;
if (!email) {
throw new Parse.Error(Parse.Error.EMAIL_MISSING, "you must provide an email");
}
let userController = req.config.userController;

try {
Config.validateEmailConfiguration({
verifyUserEmails: true, //A bit of a hack, as this isn't the intended purpose of this parameter
appName: req.config.appName,
publicServerURL: req.config.publicServerURL,
});
} catch (e) {
if (typeof e === 'string') {
throw new Parse.Error(Parse.Error.INTERNAL_SERVER_ERROR, 'An appName, publicServerURL, and emailAdapter are required for password reset functionality.');
} else {
throw e;
}
}
let { email } = req.body;
if (!email) {
throw new Parse.Error(Parse.Error.EMAIL_MISSING, "you must provide an email");
}
let userController = req.config.userController;
return userController.sendPasswordResetEmail(email).then((token) => {
return Promise.resolve({
response: {}
});
}, (err) => {
throw new Parse.Error(Parse.Error.EMAIL_NOT_FOUND, `no user found with email ${email}`);
});
return Promise.resolve({
response: {}
});
}, (err) => {
throw new Parse.Error(Parse.Error.EMAIL_NOT_FOUND, `no user found with email ${email}`);
});
}


Expand Down

0 comments on commit a88ccb0

Please sign in to comment.