Skip to content

Commit

Permalink
fixup! Add qr code login
Browse files Browse the repository at this point in the history
  • Loading branch information
poljar committed May 28, 2024
1 parent d4a7587 commit 10b0de7
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions crates/matrix-sdk/src/authentication/qrcode/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,10 @@ mod test {

enum AliceBehaviour {
HappyPath,
RefuseSecrets,
DeclinedProtocol,
UnexpectedMessage,
UnexpectedMessageInsteadOfSecrets,
RefuseSecrets,
}

fn client_metadata() -> VerifiedClientMetadata {
Expand Down Expand Up @@ -612,10 +613,13 @@ mod test {
let message: QrAuthMessage = alice.receive_json().await.unwrap();
assert_let!(QrAuthMessage::LoginSuccess = message);

let message = if let AliceBehaviour::RefuseSecrets = behavior {
QrAuthMessage::LoginDeclined
} else {
QrAuthMessage::LoginSecrets(secrets_bundle())
let message = match behavior {
AliceBehaviour::UnexpectedMessageInsteadOfSecrets => QrAuthMessage::LoginDeclined,
AliceBehaviour::RefuseSecrets => QrAuthMessage::LoginFailure {
reason: LoginFailureReason::DeviceNotFound,
homeserver: None,
},
_ => QrAuthMessage::LoginSecrets(secrets_bundle()),
};

alice.send_json(message).await.unwrap();
Expand Down Expand Up @@ -896,14 +900,26 @@ mod test {
}

#[async_test]
async fn test_qr_login_refuse_secrets() {
async fn test_qr_login_unexpected_message_instead_of_secrets() {
let result = test_failure(
ResponseTemplate::new(200).set_body_json(token()),
AliceBehaviour::RefuseSecrets,
AliceBehaviour::UnexpectedMessageInsteadOfSecrets,
)
.await;

assert_let!(Err(QRCodeLoginError::UnexpectedMessage { expected, .. }) = result);
assert_eq!(expected, "m.login.secrets");
}

#[async_test]
async fn test_qr_login_refuse_secrets() {
let result = test_failure(
ResponseTemplate::new(200).set_body_json(token()),
AliceBehaviour::RefuseSecrets,
)
.await;

assert_let!(Err(QRCodeLoginError::LoginFailure { reason, .. }) = result);
assert_eq!(reason, LoginFailureReason::DeviceNotFound);
}
}

0 comments on commit 10b0de7

Please sign in to comment.