Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/apis/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ mod tests {
let conn = pool.get().await.expect("Failed to get connection");
conn.interact(|conn| {
diesel::sql_query(
"UPDATE invite_code_admin SET otp_enabled = 1, otp_verified = 1 WHERE username = 'testuser'",
"UPDATE invite_code_admin SET otp_enabled = 1, otp_verified = 1, otp_auth_url = 'otpauth://totp/InviteCodeManager:testuser?secret=TESTSECRET' WHERE username = 'testuser'",
)
.execute(conn)
})
Expand Down Expand Up @@ -280,6 +280,13 @@ mod tests {
let auth_cookie = session_cookie(&login_resp)
.or_else(|| session_cookie(&seed_resp))
.expect("Expected a session cookie after login");
let response_body = axum::body::to_bytes(login_resp.into_body(), usize::MAX)
.await
.expect("Failed to read login response");
let response_json: serde_json::Value =
serde_json::from_slice(&response_body).expect("Login response must be JSON");
assert_eq!(response_json["otp_verified"], true);
assert_eq!(response_json["otp_auth_url"], serde_json::Value::Null);

let admin_req = Request::builder()
.method("GET")
Expand Down
6 changes: 5 additions & 1 deletion src/apis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ pub struct InviteCodes {
pub fn invite_code_admin_to_response(user: &InviteCodeAdmin) -> InviteCodeAdminData {
InviteCodeAdminData {
username: user.username.to_owned(),
otp_auth_url: user.otp_auth_url.to_owned(),
otp_auth_url: if user.otp_verified == 1 {
None
} else {
user.otp_auth_url.to_owned()
},
otp_enabled: user.otp_enabled.eq(&1),
otp_verified: user.otp_verified.eq(&1),
}
Expand Down
Loading