Better e-mail adapter testing (#2208)
This commit is contained in:
@@ -393,6 +393,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: 'parse@example.com',
|
||||
apiKey: 'k',
|
||||
domain: 'd',
|
||||
}),
|
||||
})
|
||||
.then(() => {
|
||||
let user = new Parse.User();
|
||||
user.setPassword("asdf");
|
||||
user.setUsername("zxcv");
|
||||
user.set("email", "testInvalidConfig@parse.com");
|
||||
user.signUp(null)
|
||||
.then(user => Parse.User.requestPasswordReset("testInvalidConfig@parse.com"))
|
||||
.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", "testInvalidConfig@parse.com");
|
||||
user.signUp(null)
|
||||
.then(user => Parse.User.requestPasswordReset("testInvalidConfig@parse.com"))
|
||||
.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: 'parse@example.com',
|
||||
apiKey: 'k',
|
||||
domain: 'd',
|
||||
}),
|
||||
})
|
||||
.then(() => {
|
||||
let user = new Parse.User();
|
||||
user.setPassword("asdf");
|
||||
user.setUsername("zxcv");
|
||||
user.set("email", "testInvalidConfig@parse.com");
|
||||
user.signUp(null)
|
||||
.then(user => Parse.User.requestPasswordReset("testInvalidConfig@parse.com"))
|
||||
.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(),
|
||||
|
||||
@@ -83,13 +83,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.';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +163,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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user