Skip to content

Commit 1cf772d

Browse files
authored
tests/util: Change MockTokenUser::plaintext to String (#11048)
We only use this struct for testing, where we don't want to hide the plaintext token for debugging purposes. This will also make it easier in the future to construct `MockTokenUser` instances from an existing plaintext token, without going through the `PlainToken` struct.
1 parent 9b788f1 commit 1cf772d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/tests/user.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async fn updating_existing_user_doesnt_change_api_token() -> anyhow::Result<()>
4040
assert_ok!(session::save_user_to_database(&gh_user, "bar_token", emails, &mut conn).await);
4141

4242
// Use the original API token to find the now updated user
43-
let hashed_token = assert_ok!(HashedToken::parse(token.expose_secret()));
43+
let hashed_token = assert_ok!(HashedToken::parse(token));
4444
let api_token = assert_ok!(ApiToken::find_by_api_token(&mut conn, &hashed_token).await);
4545
let user = assert_ok!(User::find(&mut conn, api_token.user_id).await);
4646

src/tests/util.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ impl MockCookieUser {
336336
MockTokenUser {
337337
app: self.app.clone(),
338338
token,
339-
plaintext,
339+
plaintext: plaintext.expose_secret().into(),
340340
}
341341
}
342342
}
@@ -345,13 +345,13 @@ impl MockCookieUser {
345345
pub struct MockTokenUser {
346346
app: TestApp,
347347
token: ApiToken,
348-
plaintext: PlainToken,
348+
plaintext: String,
349349
}
350350

351351
impl RequestHelper for MockTokenUser {
352352
fn request_builder(&self, method: Method, path: &str) -> MockRequest {
353353
let mut request = req(method, path);
354-
request.header(header::AUTHORIZATION, self.plaintext.expose_secret());
354+
request.header(header::AUTHORIZATION, &self.plaintext);
355355
request
356356
}
357357

@@ -366,7 +366,7 @@ impl MockTokenUser {
366366
&self.token
367367
}
368368

369-
pub fn plaintext(&self) -> &PlainToken {
369+
pub fn plaintext(&self) -> &str {
370370
&self.plaintext
371371
}
372372
}

0 commit comments

Comments
 (0)