Skip to content

Commit 3139543

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

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/tests/authentication.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::tests::TestApp;
2-
use crate::tests::util::{MockRequestExt, RequestHelper, Response};
2+
use crate::tests::util::{MockRequestExt, MockTokenUser, RequestHelper, Response};
33

4+
use crate::tests::builders::PublishBuilder;
45
use crate::tests::util::encode_session_header;
56
use http::{Method, StatusCode, header};
67
use insta::assert_snapshot;
@@ -18,11 +19,11 @@ async fn anonymous_user_unauthorized() {
1819

1920
#[tokio::test(flavor = "multi_thread")]
2021
async fn token_auth_cannot_find_token() {
21-
let (_, anon) = TestApp::init().empty().await;
22-
let mut request = anon.request_builder(Method::GET, URL);
23-
request.header(header::AUTHORIZATION, "cio1tkfake-token");
24-
let response: Response<()> = anon.run(request).await;
22+
let (app, _anon) = TestApp::full().empty().await;
2523

24+
let client = MockTokenUser::with_auth_header("cio1tkfake-token".to_string(), app.clone());
25+
let pb = PublishBuilder::new("foo", "1.0.0");
26+
let response = client.publish_crate(pb).await;
2627
assert_snapshot!(response.status(), @"403 Forbidden");
2728
assert_snapshot!(response.text(), @r#"{"errors":[{"detail":"authentication failed"}]}"#);
2829
}

0 commit comments

Comments
 (0)