makes test_get_info more readable

This commit is contained in:
Fabian Kaczmarczyck
2021-01-21 18:24:25 +01:00
parent de3addba74
commit 3408c0a2ed

View File

@@ -1181,7 +1181,7 @@ mod test {
MakeCredentialOptions, PublicKeyCredentialRpEntity, PublicKeyCredentialUserEntity, MakeCredentialOptions, PublicKeyCredentialRpEntity, PublicKeyCredentialUserEntity,
}; };
use super::*; use super::*;
use cbor::{cbor_array, cbor_map}; use cbor::{cbor_array, cbor_array_vec, cbor_map};
use crypto::rng256::ThreadRng256; use crypto::rng256::ThreadRng256;
const CLOCK_FREQUENCY_HZ: usize = 32768; const CLOCK_FREQUENCY_HZ: usize = 32768;
@@ -1237,43 +1237,44 @@ mod test {
let mut ctap_state = CtapState::new(&mut rng, user_immediately_present, DUMMY_CLOCK_VALUE); let mut ctap_state = CtapState::new(&mut rng, user_immediately_present, DUMMY_CLOCK_VALUE);
let info_reponse = ctap_state.process_command(&[0x04], DUMMY_CHANNEL_ID, DUMMY_CLOCK_VALUE); let info_reponse = ctap_state.process_command(&[0x04], DUMMY_CHANNEL_ID, DUMMY_CLOCK_VALUE);
let mut expected_response = vec![0x00, 0xAD, 0x01]; let expected_cbor = cbor_map_options! {
// The version array differs with CTAP1, always including 2.0 and 2.1. 0x01 => cbor_array_vec![vec![
#[cfg(not(feature = "with_ctap1"))] #[cfg(feature = "with_ctap1")]
let version_count = 2; String::from(U2F_VERSION_STRING),
#[cfg(feature = "with_ctap1")] String::from(FIDO2_VERSION_STRING),
let version_count = 3; String::from(FIDO2_1_VERSION_STRING),
expected_response.push(0x80 + version_count); ]],
#[cfg(feature = "with_ctap1")] 0x02 => cbor_array_vec![vec![
expected_response.extend(&[0x66, 0x55, 0x32, 0x46, 0x5F, 0x56, 0x32]); String::from("hmac-secret"),
expected_response.extend( String::from("credProtect"),
[ String::from("minPinLength"),
0x68, 0x46, 0x49, 0x44, 0x4F, 0x5F, 0x32, 0x5F, 0x30, 0x6C, 0x46, 0x49, 0x44, 0x4F, String::from("credBlob"),
0x5F, 0x32, 0x5F, 0x31, 0x5F, 0x50, 0x52, 0x45, 0x02, 0x84, 0x6B, 0x68, 0x6D, 0x61, ]],
0x63, 0x2D, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74, 0x6B, 0x63, 0x72, 0x65, 0x64, 0x50, 0x03 => ctap_state.persistent_store.aaguid().unwrap(),
0x72, 0x6F, 0x74, 0x65, 0x63, 0x74, 0x6C, 0x6D, 0x69, 0x6E, 0x50, 0x69, 0x6E, 0x4C, 0x04 => cbor_map! {
0x65, 0x6E, 0x67, 0x74, 0x68, 0x68, 0x63, 0x72, 0x65, 0x64, 0x42, 0x6C, 0x6F, 0x62, "rk" => true,
0x03, 0x50, "up" => true,
] "clientPin" => false,
.iter(), "credMgmt" => true,
); "setMinPINLength" => true,
expected_response.extend(&ctap_state.persistent_store.aaguid().unwrap()); "forcePINChange" => false,
expected_response.extend( },
[ 0x05 => 1024,
0x04, 0xA6, 0x62, 0x72, 0x6B, 0xF5, 0x62, 0x75, 0x70, 0xF5, 0x68, 0x63, 0x72, 0x65, 0x06 => cbor_array_vec![vec![1]],
0x64, 0x4D, 0x67, 0x6D, 0x74, 0xF5, 0x69, 0x63, 0x6C, 0x69, 0x65, 0x6E, 0x74, 0x50, 0x07 => MAX_CREDENTIAL_COUNT_IN_LIST.map(|c| c as u64),
0x69, 0x6E, 0xF4, 0x6E, 0x66, 0x6F, 0x72, 0x63, 0x65, 0x50, 0x49, 0x4E, 0x43, 0x68, 0x08 => CREDENTIAL_ID_SIZE as u64,
0x61, 0x6E, 0x67, 0x65, 0xF4, 0x6F, 0x73, 0x65, 0x74, 0x4D, 0x69, 0x6E, 0x50, 0x49, 0x09 => cbor_array_vec![vec!["usb"]],
0x4E, 0x4C, 0x65, 0x6E, 0x67, 0x74, 0x68, 0xF5, 0x05, 0x19, 0x04, 0x00, 0x06, 0x81, 0x0A => cbor_array_vec![vec![ES256_CRED_PARAM]],
0x01, 0x08, 0x18, 0x70, 0x09, 0x81, 0x63, 0x75, 0x73, 0x62, 0x0A, 0x81, 0xA2, 0x63, 0x0C => DEFAULT_CRED_PROTECT.map(|c| c as u64),
0x61, 0x6C, 0x67, 0x26, 0x64, 0x74, 0x79, 0x70, 0x65, 0x6A, 0x70, 0x75, 0x62, 0x6C, 0x0D => ctap_state.persistent_store.min_pin_length().unwrap() as u64,
0x69, 0x63, 0x2D, 0x6B, 0x65, 0x79, 0x0D, 0x04, 0x0F, 0x18, 0x20, 0x10, 0x08, 0x14, 0x0F => MAX_CRED_BLOB_LENGTH as u64,
0x18, 0x96, 0x10 => MAX_RP_IDS_LENGTH as u64,
] 0x14 => ctap_state.persistent_store.remaining_credentials().unwrap() as u64,
.iter(), };
);
assert_eq!(info_reponse, expected_response); let mut response_cbor = vec![0x00];
assert!(cbor::write(expected_cbor, &mut response_cbor));
assert_eq!(info_reponse, response_cbor);
} }
fn create_minimal_make_credential_parameters() -> AuthenticatorMakeCredentialParameters { fn create_minimal_make_credential_parameters() -> AuthenticatorMakeCredentialParameters {