-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Resend Verification Email Endpoint #3543
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
"use strict"; | ||
|
||
const request = require('request'); | ||
const requestp = require('request-promise'); | ||
const Config = require('../src/Config'); | ||
|
||
describe("Email Verification Token Expiration: ", () => { | ||
|
@@ -482,6 +483,257 @@ describe("Email Verification Token Expiration: ", () => { | |
}); | ||
}); | ||
|
||
it('should send a new verification email when a resend is requested and the user is UNVERIFIED', done => { | ||
var user = new Parse.User(); | ||
var sendEmailOptions; | ||
var sendVerificationEmailCallCount = 0; | ||
var emailAdapter = { | ||
sendVerificationEmail: options => { | ||
sendEmailOptions = options; | ||
sendVerificationEmailCallCount++; | ||
}, | ||
sendPasswordResetEmail: () => Promise.resolve(), | ||
sendMail: () => {} | ||
} | ||
reconfigureServer({ | ||
appName: 'emailVerifyToken', | ||
verifyUserEmails: true, | ||
emailAdapter: emailAdapter, | ||
emailVerifyTokenValidityDuration: 5, // 5 seconds | ||
publicServerURL: 'http://localhost:8378/1' | ||
}) | ||
.then(() => { | ||
user.setUsername('resends_verification_token'); | ||
user.setPassword('expiringToken'); | ||
user.set('email', '[email protected]'); | ||
return user.signUp(); | ||
}) | ||
.then(() => { | ||
expect(sendVerificationEmailCallCount).toBe(1); | ||
|
||
return requestp.post({ | ||
uri: 'http://localhost:8378/1/verificationEmailRequest', | ||
body: { | ||
email: '[email protected]' | ||
}, | ||
headers: { | ||
'X-Parse-Application-Id': Parse.applicationId, | ||
'X-Parse-REST-API-Key': 'rest', | ||
}, | ||
json: true, | ||
resolveWithFullResponse: true, | ||
simple: false // this promise is only rejected if the call itself failed | ||
}) | ||
.then((response) => { | ||
expect(response.statusCode).toBe(200); | ||
expect(sendVerificationEmailCallCount).toBe(2); | ||
expect(sendEmailOptions).toBeDefined(); | ||
done(); | ||
}); | ||
}) | ||
.catch(error => { | ||
jfail(error); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should not send a new verification email when a resend is requested and the user is VERIFIED', done => { | ||
var user = new Parse.User(); | ||
var sendEmailOptions; | ||
var sendVerificationEmailCallCount = 0; | ||
var emailAdapter = { | ||
sendVerificationEmail: options => { | ||
sendEmailOptions = options; | ||
sendVerificationEmailCallCount++; | ||
}, | ||
sendPasswordResetEmail: () => Promise.resolve(), | ||
sendMail: () => {} | ||
} | ||
reconfigureServer({ | ||
appName: 'emailVerifyToken', | ||
verifyUserEmails: true, | ||
emailAdapter: emailAdapter, | ||
emailVerifyTokenValidityDuration: 5, // 5 seconds | ||
publicServerURL: 'http://localhost:8378/1' | ||
}) | ||
.then(() => { | ||
user.setUsername('no_new_verification_token_once_verified'); | ||
user.setPassword('expiringToken'); | ||
user.set('email', '[email protected]'); | ||
return user.signUp(); | ||
}) | ||
.then(() => { | ||
return requestp.get({ | ||
url: sendEmailOptions.link, | ||
followRedirect: false, | ||
resolveWithFullResponse: true, | ||
simple: false | ||
}) | ||
.then((response) => { | ||
expect(response.statusCode).toEqual(302); | ||
}); | ||
}) | ||
.then(() => { | ||
expect(sendVerificationEmailCallCount).toBe(1); | ||
|
||
return requestp.post({ | ||
uri: 'http://localhost:8378/1/verificationEmailRequest', | ||
body: { | ||
email: '[email protected]' | ||
}, | ||
headers: { | ||
'X-Parse-Application-Id': Parse.applicationId, | ||
'X-Parse-REST-API-Key': 'rest', | ||
}, | ||
json: true, | ||
resolveWithFullResponse: true, | ||
simple: false // this promise is only rejected if the call itself failed | ||
}) | ||
.then((response) => { | ||
expect(response.statusCode).toBe(400); | ||
expect(sendVerificationEmailCallCount).toBe(1); | ||
done(); | ||
}); | ||
}) | ||
.catch(error => { | ||
jfail(error); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should not send a new verification email if this user does not exist', done => { | ||
var sendEmailOptions; | ||
var sendVerificationEmailCallCount = 0; | ||
var emailAdapter = { | ||
sendVerificationEmail: options => { | ||
sendEmailOptions = options; | ||
sendVerificationEmailCallCount++; | ||
}, | ||
sendPasswordResetEmail: () => Promise.resolve(), | ||
sendMail: () => {} | ||
} | ||
reconfigureServer({ | ||
appName: 'emailVerifyToken', | ||
verifyUserEmails: true, | ||
emailAdapter: emailAdapter, | ||
emailVerifyTokenValidityDuration: 5, // 5 seconds | ||
publicServerURL: 'http://localhost:8378/1' | ||
}) | ||
.then(() => { | ||
return requestp.post({ | ||
uri: 'http://localhost:8378/1/verificationEmailRequest', | ||
body: { | ||
email: '[email protected]' | ||
}, | ||
headers: { | ||
'X-Parse-Application-Id': Parse.applicationId, | ||
'X-Parse-REST-API-Key': 'rest', | ||
}, | ||
json: true, | ||
resolveWithFullResponse: true, | ||
simple: false | ||
}) | ||
.then(response => { | ||
expect(response.statusCode).toBe(400); | ||
expect(sendVerificationEmailCallCount).toBe(0); | ||
expect(sendEmailOptions).not.toBeDefined(); | ||
done(); | ||
}); | ||
}) | ||
.catch(error => { | ||
jfail(error); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should fail if no email is supplied', done => { | ||
var sendEmailOptions; | ||
var sendVerificationEmailCallCount = 0; | ||
var emailAdapter = { | ||
sendVerificationEmail: options => { | ||
sendEmailOptions = options; | ||
sendVerificationEmailCallCount++; | ||
}, | ||
sendPasswordResetEmail: () => Promise.resolve(), | ||
sendMail: () => {} | ||
} | ||
reconfigureServer({ | ||
appName: 'emailVerifyToken', | ||
verifyUserEmails: true, | ||
emailAdapter: emailAdapter, | ||
emailVerifyTokenValidityDuration: 5, // 5 seconds | ||
publicServerURL: 'http://localhost:8378/1' | ||
}) | ||
.then(() => { | ||
request.post({ | ||
uri: 'http://localhost:8378/1/verificationEmailRequest', | ||
body: {}, | ||
headers: { | ||
'X-Parse-Application-Id': Parse.applicationId, | ||
'X-Parse-REST-API-Key': 'rest', | ||
}, | ||
json: true, | ||
resolveWithFullResponse: true, | ||
simple: false | ||
}, (err, response) => { | ||
expect(response.statusCode).toBe(400); | ||
expect(response.body.code).toBe(Parse.Error.EMAIL_MISSING); | ||
expect(response.body.error).toBe('you must provide an email'); | ||
expect(sendVerificationEmailCallCount).toBe(0); | ||
expect(sendEmailOptions).not.toBeDefined(); | ||
done(); | ||
}); | ||
}) | ||
.catch(error => { | ||
jfail(error); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should fail if email is not a string', done => { | ||
var sendEmailOptions; | ||
var sendVerificationEmailCallCount = 0; | ||
var emailAdapter = { | ||
sendVerificationEmail: options => { | ||
sendEmailOptions = options; | ||
sendVerificationEmailCallCount++; | ||
}, | ||
sendPasswordResetEmail: () => Promise.resolve(), | ||
sendMail: () => {} | ||
} | ||
reconfigureServer({ | ||
appName: 'emailVerifyToken', | ||
verifyUserEmails: true, | ||
emailAdapter: emailAdapter, | ||
emailVerifyTokenValidityDuration: 5, // 5 seconds | ||
publicServerURL: 'http://localhost:8378/1' | ||
}) | ||
.then(() => { | ||
request.post({ | ||
uri: 'http://localhost:8378/1/verificationEmailRequest', | ||
body: {email: 3}, | ||
headers: { | ||
'X-Parse-Application-Id': Parse.applicationId, | ||
'X-Parse-REST-API-Key': 'rest', | ||
}, | ||
json: true, | ||
resolveWithFullResponse: true, | ||
simple: false | ||
}, (err, response) => { | ||
expect(response.statusCode).toBe(400); | ||
expect(response.body.code).toBe(Parse.Error.INVALID_EMAIL_ADDRESS); | ||
expect(response.body.error).toBe('you must provide a valid email string'); | ||
expect(sendVerificationEmailCallCount).toBe(0); | ||
expect(sendEmailOptions).not.toBeDefined(); | ||
done(); | ||
}); | ||
}) | ||
.catch(error => { | ||
jfail(error); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('client should not see the _email_verify_token_expires_at field', done => { | ||
var user = new Parse.User(); | ||
var sendEmailOptions; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe try and make this available and useful? https://github.com/ParsePlatform/parse-server/blob/0e900cbefda1ce1803e0bd78839afffdcfa01765/src/RestWrite.js#L415
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a natural place for this kind of utility code? I couldn't find one, and I'm not sure it makes sense to create one just to de-dup this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good question... @flovilmart, any thoughts/wisdom for us?