Skip to content

Better e-mail adapter testing #2208

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
merged 1 commit into from
Jul 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
88 changes: 88 additions & 0 deletions spec/ValidationAndPasswordsReset.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,94 @@ describe("Custom Pages, Email Verification, Password Reset", () => {
});
});

it_exclude_dbs(['postgres'])('fails if you include an emailAdapter, have an appName, but have no publicServerURL and send a password reset email', done => {
reconfigureServer({
appName: undefined,
emailAdapter: MockEmailAdapterWithOptions({
fromAddress: '[email protected]',
apiKey: 'k',
domain: 'd',
}),
})
.then(() => {
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]"))
.then(result => {
console.log(result);
fail('sending password reset email should not have succeeded');
done();
}, error => {
expect(error.message).toEqual('An appName, publicServerURL, and emailAdapter are required for password reset functionality.')
done();
});
})
.catch(error => {
fail(JSON.stringify(error));
done();
});
});

it_exclude_dbs(['postgres'])('fails if you set a publicServerURL, have an appName, but no emailAdapter and send a password reset email', done => {
reconfigureServer({
appName: 'unused',
publicServerURL: 'http://localhost:1337/1',
emailAdapter: undefined,
})
.then(() => {
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]"))
.then(result => {
console.log(result);
fail('sending password reset email should not have succeeded');
done();
}, error => {
expect(error.message).toEqual('An appName, publicServerURL, and emailAdapter are required for password reset functionality.')
done();
});
})
.catch(error => {
fail(JSON.stringify(error));
done();
});
});

it_exclude_dbs(['postgres'])('succeeds sending a password reset email if appName, publicServerURL, and email adapter are prodvided', done => {
reconfigureServer({
appName: 'coolapp',
publicServerURL: 'http://localhost:1337/1',
emailAdapter: MockEmailAdapterWithOptions({
fromAddress: '[email protected]',
apiKey: 'k',
domain: 'd',
}),
})
.then(() => {
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]"))
.then(result => {
done();
}, error => {
done(error);
});
})
.catch(error => {
fail(JSON.stringify(error));
done();
});
});

it('does not send verification email if email verification is disabled', done => {
var emailAdapter = {
sendVerificationEmail: () => Promise.resolve(),
Expand Down
15 changes: 8 additions & 7 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ export class Config {
}

static validateEmailConfiguration({emailAdapter, appName, publicServerURL}) {
if (emailAdapter) {
if (typeof appName !== 'string') {
throw 'An app name is required for e-mail verification and password resets.';
}
if (typeof publicServerURL !== 'string') {
throw 'A public server url is required for e-mail verification and password resets.';
}
if (!emailAdapter) {
throw 'An emailAdapter is required for e-mail verification and password resets.';
}
if (typeof appName !== 'string') {
throw 'An app name is required for e-mail verification and password resets.';
}
if (typeof publicServerURL !== 'string') {
throw 'A public server url is required for e-mail verification and password resets.';
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Routers/UsersRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class UsersRouter extends ClassesRouter {
handleResetRequest(req) {
try {
Config.validateEmailConfiguration({
emailAdapter: req.config.userController,
emailAdapter: req.config.userController.adapter,
appName: req.config.appName,
publicServerURL: req.config.publicServerURL,
});
Expand Down