use crate::*;
fn start(attachment: Option<AuthenticatorAttachment>) -> serde_json::Value {
let passki = Passki::new("localhost", &["http://localhost:3000"], "Test App");
let (challenge, _) = passki
.start_passkey_registration(
b"user123_16bytes_",
"testuser",
"Test User",
RegistrationOptions {
authenticator_attachment: attachment,
..Default::default()
},
)
.unwrap();
serde_json::to_value(&challenge).unwrap()
}
#[test]
fn test_challenge_carries_platform_attachment() {
let json = start(Some(AuthenticatorAttachment::Platform));
assert_eq!(
json["authenticatorSelection"]["authenticatorAttachment"],
"platform"
);
}
#[test]
fn test_challenge_carries_cross_platform_attachment() {
let json = start(Some(AuthenticatorAttachment::CrossPlatform));
assert_eq!(
json["authenticatorSelection"]["authenticatorAttachment"],
"cross-platform"
);
}
#[test]
fn test_challenge_omits_attachment_by_default() {
let json = start(None);
assert!(
json["authenticatorSelection"]
.get("authenticatorAttachment")
.is_none()
);
assert!(json["authenticatorSelection"]["residentKey"].is_string());
}
#[test]
fn test_registration_credential_captures_reported_attachment() {
let json = serde_json::json!({
"credential_id": "AAAA",
"public_key": "AAAA",
"client_data_json": "AAAA",
"authenticator_attachment": "cross-platform"
});
let credential: RegistrationCredential = serde_json::from_value(json).unwrap();
assert_eq!(
credential.authenticator_attachment,
Some(AuthenticatorAttachment::CrossPlatform)
);
}
#[test]
fn test_registration_credential_without_reported_attachment() {
let json = serde_json::json!({
"credential_id": "AAAA",
"public_key": "AAAA",
"client_data_json": "AAAA"
});
let credential: RegistrationCredential = serde_json::from_value(json).unwrap();
assert_eq!(credential.authenticator_attachment, None);
}
#[test]
fn test_authentication_credential_captures_reported_attachment() {
let json = serde_json::json!({
"credential_id": "AAAA",
"authenticator_data": "AAAA",
"client_data_json": "AAAA",
"signature": "AAAA",
"authenticator_attachment": "platform"
});
let credential: AuthenticationCredential = serde_json::from_value(json).unwrap();
assert_eq!(
credential.authenticator_attachment,
Some(AuthenticatorAttachment::Platform)
);
}
#[test]
fn test_authentication_credential_without_reported_attachment() {
let json = serde_json::json!({
"credential_id": "AAAA",
"authenticator_data": "AAAA",
"client_data_json": "AAAA",
"signature": "AAAA"
});
let credential: AuthenticationCredential = serde_json::from_value(json).unwrap();
assert_eq!(credential.authenticator_attachment, None);
}