Skip to content

Commit c86b77b

Browse files
committed
tests/util/test_app: Convert db_new_scoped_token() fn to async
1 parent 69b25e9 commit c86b77b

File tree

3 files changed

+54
-39
lines changed

3 files changed

+54
-39
lines changed

src/tests/routes/crates/versions/yank_unyank.rs

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,9 @@ mod auth {
208208
let expired_at = Utc::now() + Duration::days(7);
209209

210210
let (app, _, client) = prepare().await;
211-
let client =
212-
client.db_new_scoped_token("test-token", None, None, Some(expired_at.naive_utc()));
211+
let client = client
212+
.db_new_scoped_token("test-token", None, None, Some(expired_at.naive_utc()))
213+
.await;
213214

214215
let response = client.yank(CRATE_NAME, CRATE_VERSION).await;
215216
assert_eq!(response.status(), StatusCode::OK);
@@ -227,8 +228,9 @@ mod auth {
227228
let expired_at = Utc::now() - Duration::days(7);
228229

229230
let (app, _, client) = prepare().await;
230-
let client =
231-
client.db_new_scoped_token("test-token", None, None, Some(expired_at.naive_utc()));
231+
let client = client
232+
.db_new_scoped_token("test-token", None, None, Some(expired_at.naive_utc()))
233+
.await;
232234

233235
let response = client.yank(CRATE_NAME, CRATE_VERSION).await;
234236
assert_eq!(response.status(), StatusCode::FORBIDDEN);
@@ -244,8 +246,9 @@ mod auth {
244246
#[tokio::test(flavor = "multi_thread")]
245247
async fn token_user_with_correct_endpoint_scope() {
246248
let (app, _, client) = prepare().await;
247-
let client =
248-
client.db_new_scoped_token("test-token", None, Some(vec![EndpointScope::Yank]), None);
249+
let client = client
250+
.db_new_scoped_token("test-token", None, Some(vec![EndpointScope::Yank]), None)
251+
.await;
249252

250253
let response = client.yank(CRATE_NAME, CRATE_VERSION).await;
251254
assert_eq!(response.status(), StatusCode::OK);
@@ -261,12 +264,14 @@ mod auth {
261264
#[tokio::test(flavor = "multi_thread")]
262265
async fn token_user_with_incorrect_endpoint_scope() {
263266
let (app, _, client) = prepare().await;
264-
let client = client.db_new_scoped_token(
265-
"test-token",
266-
None,
267-
Some(vec![EndpointScope::PublishUpdate]),
268-
None,
269-
);
267+
let client = client
268+
.db_new_scoped_token(
269+
"test-token",
270+
None,
271+
Some(vec![EndpointScope::PublishUpdate]),
272+
None,
273+
)
274+
.await;
270275

271276
let response = client.yank(CRATE_NAME, CRATE_VERSION).await;
272277
assert_eq!(response.status(), StatusCode::FORBIDDEN);
@@ -282,12 +287,14 @@ mod auth {
282287
#[tokio::test(flavor = "multi_thread")]
283288
async fn token_user_with_correct_crate_scope() {
284289
let (app, _, client) = prepare().await;
285-
let client = client.db_new_scoped_token(
286-
"test-token",
287-
Some(vec![CrateScope::try_from(CRATE_NAME).unwrap()]),
288-
None,
289-
None,
290-
);
290+
let client = client
291+
.db_new_scoped_token(
292+
"test-token",
293+
Some(vec![CrateScope::try_from(CRATE_NAME).unwrap()]),
294+
None,
295+
None,
296+
)
297+
.await;
291298

292299
let response = client.yank(CRATE_NAME, CRATE_VERSION).await;
293300
assert_eq!(response.status(), StatusCode::OK);
@@ -304,12 +311,14 @@ mod auth {
304311
async fn token_user_with_correct_wildcard_crate_scope() {
305312
let (app, _, client) = prepare().await;
306313
let wildcard = format!("{}*", CRATE_NAME.chars().next().unwrap());
307-
let client = client.db_new_scoped_token(
308-
"test-token",
309-
Some(vec![CrateScope::try_from(wildcard).unwrap()]),
310-
None,
311-
None,
312-
);
314+
let client = client
315+
.db_new_scoped_token(
316+
"test-token",
317+
Some(vec![CrateScope::try_from(wildcard).unwrap()]),
318+
None,
319+
None,
320+
)
321+
.await;
313322

314323
let response = client.yank(CRATE_NAME, CRATE_VERSION).await;
315324
assert_eq!(response.status(), StatusCode::OK);
@@ -325,12 +334,14 @@ mod auth {
325334
#[tokio::test(flavor = "multi_thread")]
326335
async fn token_user_with_incorrect_crate_scope() {
327336
let (app, _, client) = prepare().await;
328-
let client = client.db_new_scoped_token(
329-
"test-token",
330-
Some(vec![CrateScope::try_from("foo").unwrap()]),
331-
None,
332-
None,
333-
);
337+
let client = client
338+
.db_new_scoped_token(
339+
"test-token",
340+
Some(vec![CrateScope::try_from("foo").unwrap()]),
341+
None,
342+
None,
343+
)
344+
.await;
334345

335346
let response = client.yank(CRATE_NAME, CRATE_VERSION).await;
336347
assert_eq!(response.status(), StatusCode::FORBIDDEN);
@@ -346,12 +357,14 @@ mod auth {
346357
#[tokio::test(flavor = "multi_thread")]
347358
async fn token_user_with_incorrect_wildcard_crate_scope() {
348359
let (app, _, client) = prepare().await;
349-
let client = client.db_new_scoped_token(
350-
"test-token",
351-
Some(vec![CrateScope::try_from("foo*").unwrap()]),
352-
None,
353-
None,
354-
);
360+
let client = client
361+
.db_new_scoped_token(
362+
"test-token",
363+
Some(vec![CrateScope::try_from("foo*").unwrap()]),
364+
None,
365+
None,
366+
)
367+
.await;
355368

356369
let response = client.yank(CRATE_NAME, CRATE_VERSION).await;
357370
assert_eq!(response.status(), StatusCode::FORBIDDEN);

src/tests/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,13 @@ impl MockCookieUser {
314314
///
315315
/// This method updates the database directly
316316
pub async fn db_new_token(&self, name: &str) -> MockTokenUser {
317-
self.db_new_scoped_token(name, None, None, None)
317+
self.db_new_scoped_token(name, None, None, None).await
318318
}
319319

320320
/// Creates a scoped token and wraps it in a helper struct
321321
///
322322
/// This method updates the database directly
323-
pub fn db_new_scoped_token(
323+
pub async fn db_new_scoped_token(
324324
&self,
325325
name: &str,
326326
crate_scopes: Option<Vec<CrateScope>>,

src/tests/util/test_app.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,9 @@ impl TestAppBuilder {
366366
) -> (TestApp, MockAnonymousUser, MockCookieUser, MockTokenUser) {
367367
let (app, anon) = self.empty().await;
368368
let user = app.db_new_user("foo").await;
369-
let token = user.db_new_scoped_token("bar", crate_scopes, endpoint_scopes, None);
369+
let token = user
370+
.db_new_scoped_token("bar", crate_scopes, endpoint_scopes, None)
371+
.await;
370372
(app, anon, user, token)
371373
}
372374

0 commit comments

Comments
 (0)