-
Notifications
You must be signed in to change notification settings - Fork 649
Invalid emails from GitHub #1622
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
bors
merged 8 commits into
rust-lang:master
from
integer32llc:invalid_emails_from_github
Feb 14, 2019
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d08de9f
Don't require a valid email address to sign in
sgrif 6e37194
Merge remote-tracking branch 'upstream/master' into sg-dont-require-e…
carols10cents 604ac34
Update email error ignoring to work with master
carols10cents 723025d
Add unit tests to clarify send_email behavior
carols10cents b119287
Extract a method for testability
carols10cents b4c4a88
Write a failing test for getting an invalid email from GitHub
carols10cents 8212f56
Use NEXT_GH_ID rather than setting gh_id to 1 in multiple tests
carols10cents 8dae597
Merge branch 'sg-dont-require-emails' into invalid_emails_from_github
carols10cents 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,22 @@ fn build_email( | |
Ok(email.into()) | ||
} | ||
|
||
pub fn send_user_confirm_email(email: &str, user_name: &str, token: &str) -> CargoResult<()> { | ||
/// Attempts to send a confirmation email. Swallows all errors. | ||
/// | ||
/// This function swallows any errors that occur while attempting to send the email. Some users | ||
/// have an invalid email set in their GitHub profile, and we should let them sign in even though | ||
/// we're trying to silently use their invalid address during signup and can't send them an email. | ||
/// Use `try_send_user_confirm_email` when the user is directly trying to set their email. | ||
pub fn send_user_confirm_email(email: &str, user_name: &str, token: &str) { | ||
let _ = try_send_user_confirm_email(email, user_name, token); | ||
} | ||
|
||
/// Attempts to send a confirmation email and returns errors. | ||
/// | ||
/// For use in cases where we want to fail if an email is bad because the user is directly trying | ||
/// to set their email correctly, as opposed to us silently trying to use the email from their | ||
/// GitHub profile during signup. | ||
pub fn try_send_user_confirm_email(email: &str, user_name: &str, token: &str) -> CargoResult<()> { | ||
// Create a URL with token string as path to send to user | ||
// If user clicks on path, look email/user up in database, | ||
// make sure tokens match | ||
|
@@ -100,3 +115,24 @@ fn send_email(recipient: &str, subject: &str, body: &str) -> CargoResult<()> { | |
|
||
Ok(()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn sending_to_invalid_email_fails() { | ||
let result = send_email( | ||
"String.Format(\"{0}.{1}@live.com\", FirstName, LastName)", | ||
"test", | ||
"test", | ||
); | ||
assert!(result.is_err()); | ||
} | ||
|
||
#[test] | ||
fn sending_to_valid_email_succeeds() { | ||
let result = send_email("[email protected]", "test", "test"); | ||
assert!(result.is_ok()); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -270,10 +270,7 @@ fn test_github_login_does_not_overwrite_email() { | |
let mut req = req(Method::Get, "/api/v1/me"); | ||
let user = { | ||
let conn = app.diesel_database.get().unwrap(); | ||
let user = NewUser { | ||
gh_id: 1, | ||
..new_user("apricot") | ||
}; | ||
let user = new_user("apricot"); | ||
|
||
let user = user.create_or_update(&conn).unwrap(); | ||
sign_in_as(&mut req, &user); | ||
|
@@ -299,7 +296,7 @@ fn test_github_login_does_not_overwrite_email() { | |
{ | ||
let conn = app.diesel_database.get().unwrap(); | ||
let user = NewUser { | ||
gh_id: 1, | ||
gh_id: user.gh_id, | ||
..new_user("apricot") | ||
}; | ||
|
||
|
@@ -449,17 +446,17 @@ fn test_this_user_cannot_change_that_user_email() { | |
fn test_insert_into_email_table() { | ||
let (_b, app, middle) = app(); | ||
let mut req = req(Method::Get, "/me"); | ||
{ | ||
let user = { | ||
let conn = app.diesel_database.get().unwrap(); | ||
let user = NewUser { | ||
gh_id: 1, | ||
email: Some("[email protected]"), | ||
..new_user("apple") | ||
}; | ||
|
||
let user = user.create_or_update(&conn).unwrap(); | ||
sign_in_as(&mut req, &user); | ||
} | ||
user | ||
}; | ||
|
||
let mut response = ok_resp!(middle.call(req.with_path("/api/v1/me").with_method(Method::Get),)); | ||
let r = crate::json::<UserShowPrivateResponse>(&mut response); | ||
|
@@ -472,7 +469,7 @@ fn test_insert_into_email_table() { | |
{ | ||
let conn = app.diesel_database.get().unwrap(); | ||
let user = NewUser { | ||
gh_id: 1, | ||
gh_id: user.gh_id, | ||
email: Some("[email protected]"), | ||
..new_user("apple") | ||
}; | ||
|
@@ -499,7 +496,6 @@ fn test_insert_into_email_table_with_email_change() { | |
let user = { | ||
let conn = app.diesel_database.get().unwrap(); | ||
let user = NewUser { | ||
gh_id: 1, | ||
email: Some("[email protected]"), | ||
..new_user("potato") | ||
}; | ||
|
@@ -531,7 +527,7 @@ fn test_insert_into_email_table_with_email_change() { | |
{ | ||
let conn = app.diesel_database.get().unwrap(); | ||
let user = NewUser { | ||
gh_id: 1, | ||
gh_id: user.gh_id, | ||
email: Some("[email protected]"), | ||
..new_user("potato") | ||
}; | ||
|
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.
Does this require having a valid mailgun config locally in order to run?
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.
Ah I guess we're just writing to a tempfile. I'm wondering if we could make it a bit more specific that this is only testing the lettre part of our stack, but I guess at the end of the day that really is just the whole thing and we can trust that it's behaving the same in the file sender vs smtp