Skip to content
8 changes: 4 additions & 4 deletions src/controllers/user/resend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mod tests {

#[tokio::test(flavor = "multi_thread")]
async fn test_no_auth() {
let (app, anon, user) = TestApp::init().with_user();
let (app, anon, user) = TestApp::init().with_user().await;

let url = format!("/api/v1/users/{}/resend", user.as_model().id);
let response = anon.put::<()>(&url, "").await;
Expand All @@ -76,8 +76,8 @@ mod tests {

#[tokio::test(flavor = "multi_thread")]
async fn test_wrong_user() {
let (app, _anon, user) = TestApp::init().with_user();
let user2 = app.db_new_user("bar");
let (app, _anon, user) = TestApp::init().with_user().await;
let user2 = app.db_new_user("bar").await;

let url = format!("/api/v1/users/{}/resend", user2.as_model().id);
let response = user.put::<()>(&url, "").await;
Expand All @@ -89,7 +89,7 @@ mod tests {

#[tokio::test(flavor = "multi_thread")]
async fn test_happy_path() {
let (app, _anon, user) = TestApp::init().with_user();
let (app, _anon, user) = TestApp::init().with_user().await;

let url = format!("/api/v1/users/{}/resend", user.as_model().id);
let response = user.put::<()>(&url, "").await;
Expand Down
6 changes: 3 additions & 3 deletions src/tests/account_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async fn lock_account(app: &TestApp, user_id: i32, until: Option<NaiveDateTime>)

#[tokio::test(flavor = "multi_thread")]
async fn account_locked_indefinitely() {
let (app, _anon, user) = TestApp::init().with_user();
let (app, _anon, user) = TestApp::init().with_user().await;
lock_account(&app, user.as_model().id, None).await;

let response = user.get::<()>(URL).await;
Expand All @@ -41,7 +41,7 @@ async fn account_locked_with_future_expiry() {
.unwrap()
.naive_utc();

let (app, _anon, user) = TestApp::init().with_user();
let (app, _anon, user) = TestApp::init().with_user().await;
lock_account(&app, user.as_model().id, Some(until)).await;

let response = user.get::<()>(URL).await;
Expand All @@ -53,7 +53,7 @@ async fn account_locked_with_future_expiry() {
async fn expired_account_lock() {
let until = Utc::now().naive_utc() - Duration::days(1);

let (app, _anon, user) = TestApp::init().with_user();
let (app, _anon, user) = TestApp::init().with_user().await;
lock_account(&app, user.as_model().id, Some(until)).await;

user.get::<serde_json::Value>(URL).await.good();
Expand Down
6 changes: 3 additions & 3 deletions src/tests/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static URL: &str = "/api/v1/me/updates";

#[tokio::test(flavor = "multi_thread")]
async fn anonymous_user_unauthorized() {
let (_, anon) = TestApp::init().empty();
let (_, anon) = TestApp::init().empty().await;
let response: Response<()> = anon.get(URL).await;

assert_eq!(response.status(), StatusCode::FORBIDDEN);
Expand All @@ -18,7 +18,7 @@ async fn anonymous_user_unauthorized() {

#[tokio::test(flavor = "multi_thread")]
async fn token_auth_cannot_find_token() {
let (_, anon) = TestApp::init().empty();
let (_, anon) = TestApp::init().empty().await;
let mut request = anon.request_builder(Method::GET, URL);
request.header(header::AUTHORIZATION, "cio1tkfake-token");
let response: Response<()> = anon.run(request).await;
Expand All @@ -32,7 +32,7 @@ async fn token_auth_cannot_find_token() {
// the database, it is not possible to implement this same test for a token.
#[tokio::test(flavor = "multi_thread")]
async fn cookie_auth_cannot_find_user() {
let (app, anon) = TestApp::init().empty();
let (app, anon) = TestApp::init().empty().await;

let session_key = app.as_inner().session_key();
let cookie = encode_session_header(session_key, -1);
Expand Down
6 changes: 4 additions & 2 deletions src/tests/blocked_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ async fn test_non_blocked_download_route() {
.with_config(|config| {
config.blocked_routes.clear();
})
.with_user();
.with_user()
.await;

let mut conn = app.db_conn();

Expand All @@ -32,7 +33,8 @@ async fn test_blocked_download_route() {
.blocked_routes
.insert("/api/v1/crates/:crate_id/:version/download".into());
})
.with_user();
.with_user()
.await;

let mut conn = app.db_conn();

Expand Down
9 changes: 6 additions & 3 deletions src/tests/cors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ async fn test_with_matching_origin() {
.with_config(|server| {
server.allowed_origins = "https://crates.io".parse().unwrap();
})
.with_user();
.with_user()
.await;

let mut request = cookie.get_request("/api/v1/me");
request.header("Origin", "https://crates.io");
Expand All @@ -24,7 +25,8 @@ async fn test_with_unknown_origin() {
.with_config(|server| {
server.allowed_origins = "https://crates.io".parse().unwrap();
})
.with_user();
.with_user()
.await;

let mut request = cookie.get_request("/api/v1/me");
request.header("Origin", "https://evil.hacker.io");
Expand All @@ -40,7 +42,8 @@ async fn test_with_multiple_origins() {
.with_config(|server| {
server.allowed_origins = "https://crates.io".parse().unwrap();
})
.with_user();
.with_user()
.await;

let mut request = cookie.get_request("/api/v1/me");
request.header("Origin", "https://evil.hacker.io");
Expand Down
2 changes: 1 addition & 1 deletion src/tests/dump_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static PATH_DATE_RE: LazyLock<Regex> =

#[tokio::test(flavor = "multi_thread")]
async fn test_dump_db_job() {
let (app, _, _, token) = TestApp::full().with_token();
let (app, _, _, token) = TestApp::full().with_token().await;
let mut conn = app.db_conn();

CrateBuilder::new("test-crate", token.as_model().user_id).expect_build(&mut conn);
Expand Down
17 changes: 13 additions & 4 deletions src/tests/github_secret_scanning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ fn github_mock() -> MockGitHubClient {

#[tokio::test(flavor = "multi_thread")]
async fn github_secret_alert_revokes_token() {
let (app, anon, user, token) = TestApp::init().with_github(github_mock()).with_token();
let (app, anon, user, token) = TestApp::init()
.with_github(github_mock())
.with_token()
.await;
let mut conn = app.async_db_conn().await;

// Ensure no emails were sent up to this point
Expand Down Expand Up @@ -99,7 +102,10 @@ async fn github_secret_alert_revokes_token() {

#[tokio::test(flavor = "multi_thread")]
async fn github_secret_alert_for_revoked_token() {
let (app, anon, user, token) = TestApp::init().with_github(github_mock()).with_token();
let (app, anon, user, token) = TestApp::init()
.with_github(github_mock())
.with_token()
.await;
let mut conn = app.async_db_conn().await;

// Ensure no emails were sent up to this point
Expand Down Expand Up @@ -160,7 +166,10 @@ async fn github_secret_alert_for_revoked_token() {

#[tokio::test(flavor = "multi_thread")]
async fn github_secret_alert_for_unknown_token() {
let (app, anon, user, token) = TestApp::init().with_github(github_mock()).with_token();
let (app, anon, user, token) = TestApp::init()
.with_github(github_mock())
.with_token()
.await;
let mut conn = app.async_db_conn().await;

// Ensure no emails were sent up to this point
Expand Down Expand Up @@ -202,7 +211,7 @@ async fn github_secret_alert_for_unknown_token() {

#[tokio::test(flavor = "multi_thread")]
async fn github_secret_alert_invalid_signature_fails() {
let (_, anon) = TestApp::init().with_github(github_mock()).empty();
let (_, anon) = TestApp::init().with_github(github_mock()).empty().await;

// No headers or request body
let request = anon.post_request(URL);
Expand Down
5 changes: 4 additions & 1 deletion src/tests/issues/issue1205.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use insta::assert_snapshot;
async fn test_issue_1205() -> anyhow::Result<()> {
const CRATE_NAME: &str = "deepspeech-sys";

let (app, _, _, user) = TestApp::full().with_github(github_mock()).with_token();
let (app, _, _, user) = TestApp::full()
.with_github(github_mock())
.with_token()
.await;

let mut conn = app.db_conn();

Expand Down
8 changes: 4 additions & 4 deletions src/tests/issues/issue2736.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use insta::assert_snapshot;
/// See <https://github.com/rust-lang/crates.io/issues/2736>.
#[tokio::test(flavor = "multi_thread")]
async fn test_issue_2736() -> anyhow::Result<()> {
let (app, _) = TestApp::full().empty();
let (app, _) = TestApp::full().empty().await;
let mut conn = app.db_conn();

// - A user had a GitHub account named, let's say, `foo`
let foo1 = app.db_new_user("foo");
let foo1 = app.db_new_user("foo").await;

// - Another user `someone_else` added them as an owner of a crate
let someone_else = app.db_new_user("someone_else");
let someone_else = app.db_new_user("someone_else").await;

let krate = CrateBuilder::new("crate1", someone_else.as_model().id).expect_build(&mut conn);

Expand All @@ -33,7 +33,7 @@ async fn test_issue_2736() -> anyhow::Result<()> {
// - `foo` deleted their GitHub account (but crates.io has no real knowledge of this)
// - `foo` recreated their GitHub account with the same username (because it was still available), but in this situation GitHub assigns them a new ID
// - When `foo` now logs in to crates.io, it's a different account than their old `foo` crates.io account because of the new GitHub ID (and if it wasn't, this would be a security problem)
let foo2 = app.db_new_user("foo");
let foo2 = app.db_new_user("foo").await;

let github_ids = users::table
.filter(users::gh_login.eq("foo"))
Expand Down
8 changes: 4 additions & 4 deletions src/tests/krate/following.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async fn unfollow(crate_name: &str, user: &impl RequestHelper) {
async fn test_unauthenticated_requests() {
const CRATE_NAME: &str = "foo";

let (app, anon, user) = TestApp::init().with_user();
let (app, anon, user) = TestApp::init().with_user().await;
let mut conn = app.db_conn();

CrateBuilder::new(CRATE_NAME, user.as_model().id).expect_build(&mut conn);
Expand Down Expand Up @@ -61,7 +61,7 @@ async fn test_unauthenticated_requests() {
async fn test_following() {
const CRATE_NAME: &str = "foo_following";

let (app, _, user) = TestApp::init().with_user();
let (app, _, user) = TestApp::init().with_user().await;
let mut conn = app.db_conn();

CrateBuilder::new(CRATE_NAME, user.as_model().id).expect_build(&mut conn);
Expand Down Expand Up @@ -91,7 +91,7 @@ async fn test_following() {

#[tokio::test(flavor = "multi_thread")]
async fn test_unknown_crate() {
let (_, _, user) = TestApp::init().with_user();
let (_, _, user) = TestApp::init().with_user().await;

let response = user
.get::<()>("/api/v1/crates/unknown-crate/following")
Expand All @@ -117,7 +117,7 @@ async fn test_api_token_auth() {
const CRATE_TO_FOLLOW: &str = "some_crate_to_follow";
const CRATE_NOT_TO_FOLLOW: &str = "another_crate";

let (app, _, user, token) = TestApp::init().with_token();
let (app, _, user, token) = TestApp::init().with_token().await;
let mut conn = app.db_conn();
let api_token = token.as_model();

Expand Down
2 changes: 1 addition & 1 deletion src/tests/krate/publish/audit_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ async fn publish_records_an_audit_action() {
use crate::tests::builders::PublishBuilder;
use crate::tests::util::{RequestHelper, TestApp};

let (app, anon, _, token) = TestApp::full().with_token();
let (app, anon, _, token) = TestApp::full().with_token().await;

let mut conn = app.db_conn();
assert!(VersionOwnerAction::all(&mut conn).unwrap().is_empty());
Expand Down
7 changes: 4 additions & 3 deletions src/tests/krate/publish/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use insta::assert_snapshot;

#[tokio::test(flavor = "multi_thread")]
async fn new_wrong_token() {
let (app, anon, _, token) = TestApp::full().with_token();
let (app, anon, _, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;

// Try to publish without a token
Expand All @@ -35,14 +35,15 @@ async fn new_wrong_token() {

#[tokio::test(flavor = "multi_thread")]
async fn new_krate_wrong_user() {
let (app, _, user) = TestApp::full().with_user();
let (app, _, user) = TestApp::full().with_user().await;
let mut conn = app.db_conn();

// Create the foo_wrong crate with one user
CrateBuilder::new("foo_wrong", user.as_model().id).expect_build(&mut conn);

// Then try to publish with a different user
let another_user = app.db_new_user("another").db_new_token("bar");
let another_user = app.db_new_user("another").await;
let another_user = another_user.db_new_token("bar").await;
let crate_to_publish = PublishBuilder::new("foo_wrong", "2.0.0");

let response = another_user.publish_crate(crate_to_publish).await;
Expand Down
12 changes: 6 additions & 6 deletions src/tests/krate/publish/basics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use insta::{assert_json_snapshot, assert_snapshot};

#[tokio::test(flavor = "multi_thread")]
async fn new_krate() {
let (app, _, user) = TestApp::full().with_user();
let (app, _, user) = TestApp::full().with_user().await;
let mut conn = app.async_db_conn().await;

let crate_to_publish = PublishBuilder::new("foo_new", "1.0.0");
Expand Down Expand Up @@ -43,7 +43,7 @@ async fn new_krate() {

#[tokio::test(flavor = "multi_thread")]
async fn new_krate_with_token() {
let (app, _, _, token) = TestApp::full().with_token();
let (app, _, _, token) = TestApp::full().with_token().await;

let crate_to_publish = PublishBuilder::new("foo_new", "1.0.0");
let response = token.publish_crate(crate_to_publish).await;
Expand All @@ -64,7 +64,7 @@ async fn new_krate_with_token() {

#[tokio::test(flavor = "multi_thread")]
async fn new_krate_weird_version() {
let (app, _, _, token) = TestApp::full().with_token();
let (app, _, _, token) = TestApp::full().with_token().await;

let crate_to_publish = PublishBuilder::new("foo_weird", "0.0.0-pre");
let response = token.publish_crate(crate_to_publish).await;
Expand All @@ -85,7 +85,7 @@ async fn new_krate_weird_version() {

#[tokio::test(flavor = "multi_thread")]
async fn new_krate_twice() {
let (app, _, _, token) = TestApp::full().with_token();
let (app, _, _, token) = TestApp::full().with_token().await;

let crate_to_publish = PublishBuilder::new("foo_twice", "0.99.0");
token.publish_crate(crate_to_publish).await.good();
Expand Down Expand Up @@ -116,7 +116,7 @@ async fn new_krate_twice() {
// The primary purpose is to verify that the `default_version` we provide is as expected.
#[tokio::test(flavor = "multi_thread")]
async fn new_krate_twice_alt() {
let (app, _, _, token) = TestApp::full().with_token();
let (app, _, _, token) = TestApp::full().with_token().await;

let crate_to_publish =
PublishBuilder::new("foo_twice", "2.0.0").description("2.0.0 description");
Expand Down Expand Up @@ -145,7 +145,7 @@ async fn new_krate_twice_alt() {

#[tokio::test(flavor = "multi_thread")]
async fn new_krate_duplicate_version() {
let (app, _, user, token) = TestApp::full().with_token();
let (app, _, user, token) = TestApp::full().with_token().await;
let mut conn = app.db_conn();

// Insert a crate directly into the database and then we'll try to publish the same version
Expand Down
2 changes: 1 addition & 1 deletion src/tests/krate/publish/build_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use insta::assert_json_snapshot;
use serde_json::json;

async fn version_with_build_metadata(v1: &str, v2: &str, expected_error: &str) {
let (_app, _anon, _cookie, token) = TestApp::full().with_token();
let (_app, _anon, _cookie, token) = TestApp::full().with_token().await;

let response = token.publish_crate(PublishBuilder::new("foo", v1)).await;
assert_eq!(response.status(), StatusCode::OK);
Expand Down
6 changes: 3 additions & 3 deletions src/tests/krate/publish/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use insta::{assert_json_snapshot, assert_snapshot};

#[tokio::test(flavor = "multi_thread")]
async fn good_categories() {
let (app, _, _, token) = TestApp::full().with_token();
let (app, _, _, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;

insert_into(categories::table)
Expand All @@ -30,7 +30,7 @@ async fn good_categories() {

#[tokio::test(flavor = "multi_thread")]
async fn ignored_categories() {
let (_, _, _, token) = TestApp::full().with_token();
let (_, _, _, token) = TestApp::full().with_token().await;

let crate_to_publish = PublishBuilder::new("foo_ignored_cat", "1.0.0").category("bar");
let response = token.publish_crate(crate_to_publish).await;
Expand All @@ -40,7 +40,7 @@ async fn ignored_categories() {

#[tokio::test(flavor = "multi_thread")]
async fn too_many_categories() {
let (app, _, _, token) = TestApp::full().with_token();
let (app, _, _, token) = TestApp::full().with_token().await;

let response = token
.publish_crate(
Expand Down
2 changes: 1 addition & 1 deletion src/tests/krate/publish/deleted_crates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use insta::assert_snapshot;

#[tokio::test(flavor = "multi_thread")]
async fn test_recently_deleted_crate_with_same_name() -> anyhow::Result<()> {
let (app, _, _, token) = TestApp::full().with_token();
let (app, _, _, token) = TestApp::full().with_token().await;
let mut conn = app.async_db_conn().await;

let now = Utc::now();
Expand Down
Loading