Skip to content

Commit 577a4e8

Browse files
committed
tests/util: Add MockTokenUser::for_token() fn
This makes it possible to construct `MockTokenUser` instances from an existing plaintext token.
1 parent e010faa commit 577a4e8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/tests/util.rs

+9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use http::header;
3939
use secrecy::ExposeSecret;
4040
use serde_json::json;
4141
use std::collections::HashMap;
42+
use std::fmt::Display;
4243
use std::net::SocketAddr;
4344
use tower::ServiceExt;
4445

@@ -361,6 +362,14 @@ impl RequestHelper for MockTokenUser {
361362
}
362363

363364
impl MockTokenUser {
365+
pub fn for_token(token: impl Display, app: TestApp) -> Self {
366+
Self {
367+
app,
368+
token: None,
369+
plaintext: format!("Bearer {token}"),
370+
}
371+
}
372+
364373
/// Returns a reference to the database `ApiToken` model
365374
pub fn as_model(&self) -> &ApiToken {
366375
const ERROR: &str = "Original `ApiToken` was not set on this `MockTokenUser` instance";

0 commit comments

Comments
 (0)