Skip to content

Commit 83b6f6c

Browse files
committed
Require a verified email after 2019-03-01 00:00 UTC
Because that's at least on 2019-02-28 (the date we announced) in all timezones, and should definitely be after the release scheduled for that day. As per the plan at rust-lang/crates-io-cargo-teams#8
1 parent 8935dcd commit 83b6f6c

File tree

4 files changed

+113
-10
lines changed

4 files changed

+113
-10
lines changed

Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ reqwest = "0.9.1"
6464
tempdir = "0.3.7"
6565
parking_lot = "0.7.1"
6666

67+
# This can be moved back to a dev dependency after 2019-02-28, when the
68+
# VERIFIED_EMAIL_REQUIRED_DATE is removed from src/controllers/krate/publish.rs.
69+
lazy_static = "1.0"
70+
6771
lettre = {git = "https://github.com/lettre/lettre", version = "0.9"}
6872
lettre_email = {git = "https://github.com/lettre/lettre", version = "0.9"}
6973

@@ -82,7 +86,6 @@ conduit-test = "0.8"
8286
hyper = "0.12"
8387
hyper-tls = "0.3"
8488
futures = "0.1"
85-
lazy_static = "1.0"
8689
tokio-core = "0.1"
8790
tokio-service = "0.1"
8891

src/controllers/krate/publish.rs

+105-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
use std::collections::HashMap;
44
use std::sync::Arc;
55

6+
use chrono::offset::TimeZone;
7+
use chrono::{DateTime, Utc};
68
use hex::ToHex;
79

810
use crate::git;
@@ -67,13 +69,12 @@ pub fn publish(req: &mut dyn Request) -> CargoResult<Response> {
6769

6870
let mut other_warnings = vec![];
6971
let verified_email_address = user.verified_email(&conn)?;
70-
if verified_email_address.is_none() {
71-
other_warnings.push(String::from(
72-
"You do not currently have a verified email address associated with your crates.io \
73-
account. Starting 2019-02-28, a verified email will be required to publish crates. \
74-
Visit https://crates.io/me to set and verify your email address.",
75-
));
76-
}
72+
73+
// This function can be inlined (with only the error-returning functionality) and its unit
74+
// tests deleted after 2019-02-28; it was created to make injecting the date for tests easier.
75+
// The integration tests in src/tests/krate.rs cover the current production behavior (and will
76+
// need to be updated at that time)
77+
verified_email_check(&mut other_warnings, &verified_email_address, Utc::now())?;
7778

7879
// Create a transaction on the database, if there are no errors,
7980
// commit the transactions to record a new or updated crate.
@@ -267,3 +268,100 @@ fn parse_new_headers(req: &mut dyn Request) -> CargoResult<(EncodableCrateUpload
267268
let user = req.user()?;
268269
Ok((new, user.clone()))
269270
}
271+
272+
lazy_static! {
273+
static ref VERIFIED_EMAIL_REQUIRED_DATE: DateTime<Utc> =
274+
{ Utc.ymd(2019, 3, 1).and_hms(0, 0, 0) };
275+
}
276+
277+
fn verified_email_check(
278+
other_warnings: &mut Vec<String>,
279+
verified_email_address: &Option<String>,
280+
now: DateTime<Utc>,
281+
) -> CargoResult<()> {
282+
match verified_email_address {
283+
Some(_) => Ok(()),
284+
None => {
285+
if now < *VERIFIED_EMAIL_REQUIRED_DATE {
286+
other_warnings.push(String::from(
287+
"You do not currently have a verified email address associated with your \
288+
crates.io account. Starting 2019-02-28, a verified email will be required to \
289+
publish crates. Visit https://crates.io/me to set and verify your email \
290+
address.",
291+
));
292+
Ok(())
293+
} else {
294+
Err(human("A verified email address is required to publish crates to crates.io. \
295+
Visit https://crates.io/me to set and verify your email address."))
296+
}
297+
}
298+
}
299+
}
300+
301+
// These tests should be deleted after 2018-02-28; this functionality will then be covered by
302+
// integration tests in src/tests/krate.rs.
303+
#[cfg(test)]
304+
mod tests {
305+
use super::*;
306+
use chrono::offset::TimeZone;
307+
308+
#[test]
309+
fn allow_publish_with_verified_email_without_warning_before_2018_02_28() {
310+
let mut warnings = vec![];
311+
312+
let fake_current_date = Utc.ymd(2019, 2, 27).and_hms(0, 0, 0);
313+
let result = verified_email_check(
314+
&mut warnings,
315+
&Some("[email protected]".into()),
316+
fake_current_date,
317+
);
318+
319+
assert!(result.is_ok());
320+
assert_eq!(warnings.len(), 0);
321+
}
322+
323+
#[test]
324+
fn allow_publish_with_verified_email_without_error_after_2018_02_28() {
325+
let mut warnings = vec![];
326+
327+
let fake_current_date = Utc.ymd(2019, 3, 1).and_hms(0, 0, 0);
328+
let result = verified_email_check(
329+
&mut warnings,
330+
&Some("[email protected]".into()),
331+
fake_current_date,
332+
);
333+
334+
assert!(result.is_ok());
335+
assert_eq!(warnings.len(), 0);
336+
}
337+
338+
#[test]
339+
fn warn_without_verified_email_before_2018_02_28() {
340+
let mut warnings = vec![];
341+
342+
let fake_current_date = Utc.ymd(2019, 2, 27).and_hms(0, 0, 0);
343+
let result = verified_email_check(&mut warnings, &None, fake_current_date);
344+
345+
assert!(result.is_ok());
346+
assert_eq!(warnings.len(), 1);
347+
assert_eq!(warnings[0], "You do not currently have a verified email address associated \
348+
with your crates.io account. Starting 2019-02-28, a verified email will be required to \
349+
publish crates. Visit https://crates.io/me to set and verify your email address.");
350+
}
351+
352+
#[test]
353+
fn error_without_verified_email_after_2018_02_28() {
354+
let mut warnings = vec![];
355+
356+
let fake_current_date = Utc.ymd(2019, 3, 1).and_hms(0, 0, 0);
357+
let result = verified_email_check(&mut warnings, &None, fake_current_date);
358+
359+
assert!(result.is_err());
360+
assert_eq!(
361+
result.err().unwrap().description(),
362+
"A verified email address is required to \
363+
publish crates to crates.io. Visit https://crates.io/me to set and verify your email \
364+
address."
365+
);
366+
}
367+
}

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ extern crate log;
1818
extern crate serde_derive;
1919
#[macro_use]
2020
extern crate serde_json;
21+
#[macro_use]
22+
extern crate lazy_static;
2123

2224
pub use crate::{app::App, config::Config, uploaders::Uploader};
2325
use std::sync::Arc;

src/tests/krate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ fn new_krate_with_readme() {
10731073
assert_eq!(json.krate.max_version, "1.0.0");
10741074
}
10751075

1076-
// This warning will soon become a hard error.
1076+
// This test will start failing on 2019-02-28 and should be updated at that time.
10771077
// See https://github.com/rust-lang/crates-io-cargo-teams/issues/8
10781078
#[test]
10791079
fn new_krate_without_any_email_warns() {
@@ -1096,7 +1096,7 @@ fn new_krate_without_any_email_warns() {
10961096
});
10971097
}
10981098

1099-
// This warning will soon become a hard error.
1099+
// This test will start failing on 2019-02-28 and should be updated at that time.
11001100
// See https://github.com/rust-lang/crates-io-cargo-teams/issues/8
11011101
#[test]
11021102
fn new_krate_with_unverified_email_warns() {

0 commit comments

Comments
 (0)