Skip to content

Commit c778663

Browse files
committed
tests/token: Use API endpoint in old_tokens_give_specific_error_message() that actually supports token auth
`GET /api/v1/me` only supports cookie authentication, so this test was a bit misleading before
1 parent 3139543 commit c778663

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/tests/token.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use crate::tests::util::MockRequestExt;
1+
use crate::tests::builders::PublishBuilder;
2+
use crate::tests::util::MockTokenUser;
23
use crate::tests::{RequestHelper, TestApp};
34
use crate::{models::ApiToken, views::EncodableMe};
45
use diesel::prelude::*;
56
use diesel_async::RunQueryDsl;
6-
use http::header;
77
use insta::assert_snapshot;
88

99
#[tokio::test(flavor = "multi_thread")]
@@ -35,12 +35,11 @@ async fn using_token_updates_last_used_at() {
3535

3636
#[tokio::test(flavor = "multi_thread")]
3737
async fn old_tokens_give_specific_error_message() {
38-
let url = "/api/v1/me";
39-
let (_, anon) = TestApp::init().empty().await;
38+
let (app, _anon) = TestApp::full().empty().await;
4039

41-
let mut request = anon.get_request(url);
42-
request.header(header::AUTHORIZATION, "oldtoken");
43-
let response = anon.run::<()>(request).await;
40+
let client = MockTokenUser::with_auth_header("oldtoken".to_string(), app.clone());
41+
let pb = PublishBuilder::new("foo", "1.0.0");
42+
let response = client.publish_crate(pb).await;
4443
assert_snapshot!(response.status(), @"401 Unauthorized");
4544
assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"The given API token does not match the format used by crates.io. Tokens generated before 2020-07-14 were generated with an insecure random number generator, and have been revoked. You can generate a new token at https://crates.io/me. For more information please see https://blog.rust-lang.org/2020/07/14/crates-io-security-advisory.html. We apologize for any inconvenience."}]}"#);
4645
}

0 commit comments

Comments
 (0)