-
Notifications
You must be signed in to change notification settings - Fork 649
Add an option for disabling the requirement to verify email before publishing #3048
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
Closed
JWorthe
wants to merge
3
commits into
rust-lang:master
from
caeg-industries:email-verification-check
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -55,14 +55,25 @@ pub fn publish(req: &mut dyn RequestExt) -> EndpointResult { | |
let api_token_id = ids.api_token_id(); | ||
let user = ids.user(); | ||
|
||
let verified_email_address = user.verified_email(&conn)?; | ||
let verified_email_address = verified_email_address.ok_or_else(|| { | ||
cargo_err(&format!( | ||
"A verified email address is required to publish crates to crates.io. \ | ||
Visit https://{}/me to set and verify your email address.", | ||
app.config.domain_name, | ||
)) | ||
})?; | ||
let email_address = if app.config.require_email_verification { | ||
let verified_email_address = user.verified_email(&conn)?; | ||
verified_email_address.ok_or_else(|| { | ||
cargo_err(&format!( | ||
"A verified email address is required to publish crates to crates.io. \ | ||
Visit https://{}/me to set and verify your email address.", | ||
app.config.domain_name, | ||
)) | ||
})? | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I think what I would expect is that if |
||
let email_address = user.email(&conn)?; | ||
email_address.ok_or_else(|| { | ||
cargo_err(&format!( | ||
"An email address is required to publish crates to crates.io. \ | ||
Visit https://{}/me to set and verify your email address.", | ||
app.config.domain_name, | ||
)) | ||
})? | ||
}; | ||
|
||
// Create a transaction on the database, if there are no errors, | ||
// commit the transactions to record a new or updated crate. | ||
|
@@ -152,7 +163,7 @@ pub fn publish(req: &mut dyn RequestExt) -> EndpointResult { | |
file_length as i32, | ||
user.id, | ||
)? | ||
.save(&conn, &new_crate.authors, &verified_email_address)?; | ||
.save(&conn, &new_crate.authors, &email_address)?; | ||
|
||
insert_version_owner_action( | ||
&conn, | ||
|
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
69 changes: 69 additions & 0 deletions
69
...data/krate_publish_new_krate_records_with_unverified_email_if_email_verification_disabled
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
[ | ||
{ | ||
"request": { | ||
"uri": "http://alexcrichton-test.s3.amazonaws.com/crates/foo_unverified_email/foo_unverified_email-1.0.0.crate", | ||
"method": "PUT", | ||
"headers": [ | ||
[ | ||
"accept", | ||
"*/*" | ||
], | ||
[ | ||
"content-length", | ||
"35" | ||
], | ||
[ | ||
"host", | ||
"alexcrichton-test.s3.amazonaws.com" | ||
], | ||
[ | ||
"accept-encoding", | ||
"gzip" | ||
], | ||
[ | ||
"content-type", | ||
"application/x-tar" | ||
], | ||
[ | ||
"authorization", | ||
"AWS AKIAICL5IWUZYWWKA7JA:uDc39eNdF6CcwB+q+JwKsoDLQc4=" | ||
], | ||
[ | ||
"date", | ||
"Fri, 15 Sep 2017 07:53:06 -0700" | ||
] | ||
], | ||
"body": "H4sIAAAAAAAA/+3AAQEAAACCIP+vbkhQwKsBLq+17wAEAAA=" | ||
}, | ||
"response": { | ||
"status": 200, | ||
"headers": [ | ||
[ | ||
"x-amz-request-id", | ||
"26589A5E52F8395C" | ||
], | ||
[ | ||
"ETag", | ||
"\"f9016ad360cebb4fe2e6e96e5949f022\"" | ||
], | ||
[ | ||
"date", | ||
"Fri, 15 Sep 2017 14:53:07 GMT" | ||
], | ||
[ | ||
"content-length", | ||
"0" | ||
], | ||
[ | ||
"x-amz-id-2", | ||
"JdIvnNTw53aqXjBIqBLNuN4kxf/w1XWX+xuIiGBDYy7yzOSDuAMtBSrTW4ZWetcCIdqCUHuQ51A=" | ||
], | ||
[ | ||
"Server", | ||
"AmazonS3" | ||
] | ||
], | ||
"body": "" | ||
} | ||
} | ||
] |
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 |
---|---|---|
|
@@ -618,6 +618,32 @@ fn new_krate_with_unverified_email_fails() { | |
); | ||
} | ||
|
||
#[test] | ||
fn new_krate_records_with_unverified_email_if_email_verification_disabled() { | ||
let (app, _, _, token) = TestApp::full() | ||
.with_config(|c| c.require_email_verification = false) | ||
.with_token(); | ||
|
||
app.db(|conn| { | ||
update(emails::table) | ||
.set((emails::verified.eq(false),)) | ||
.execute(conn) | ||
.unwrap(); | ||
}); | ||
|
||
let crate_to_publish = PublishBuilder::new("foo_unverified_email"); | ||
|
||
token.enqueue_publish(crate_to_publish).good(); | ||
|
||
app.db(|conn| { | ||
let email: String = versions_published_by::table | ||
.select(versions_published_by::email) | ||
.first(conn) | ||
.unwrap(); | ||
assert_eq!(email, "[email protected]"); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn new_krate_records_verified_email() { | ||
let (app, _, _, token) = TestApp::full().with_token(); | ||
|
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.
if one had
DISABLE_EMAIL_VERIFICATION_REQUIREMENT=0
, won't this give a surprising resultThere 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.
Yes, it would be surprising, but I think consistency with the other fields in the config is more important. There are a few others that follow this same pattern in this config, where it's just checking set or unset. For example, MIRROR and HEROKU.