*/
#include <cstring>
#include <gtest/gtest.h>
-#include <iostream>
-#include <string>
#include <unistd.h>
#include <message-buffer.h>
#include <serialization.h>
}
TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_param_s_N1)
{// serialize: invalid member
- wauthn_pubkey_cred_param_s param1 = {static_cast<wauthn_pubkey_cred_type_e>(0x00FFFFFF),
+ wauthn_pubkey_cred_param_s param1 = {static_cast<wauthn_pubkey_cred_type_e>(0),
WAUTHN_COSE_ALGORITHM_ECDSA_P256_WITH_SHA256};
PubkeyCredParamSerializer data1(¶m1);
__testSerializeForInvalidMember(data1);
wauthn_pubkey_cred_param_s param2 = {WAUTHN_PUBKEY_CRED_TYPE_PUBLIC_KEY,
- static_cast<wauthn_cose_algorithm_e>(0x00FFFFFF)};
+ static_cast<wauthn_cose_algorithm_e>(0)};
PubkeyCredParamSerializer data2(¶m2);
__testSerializeForInvalidMember(data2);
}
TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_param_s_N2)
{// deserialize: for invalid type
- wauthn_pubkey_cred_param_s param1 = {static_cast<wauthn_pubkey_cred_type_e>(0x00FFFFFF),
+ wauthn_pubkey_cred_param_s param1 = {static_cast<wauthn_pubkey_cred_type_e>(0),
WAUTHN_COSE_ALGORITHM_ECDSA_P256_WITH_SHA256};
__testDeserializeForInvalidMember<wauthn_pubkey_cred_param_s,
PubkeyCredParamDeserializer>(param1);
TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_descriptor_s_N1)
{// serialize: invalid member
wauthn_pubkey_cred_descriptor_s data = TestCommonData::pubkeyCredDescriptor;
- data.type = static_cast<wauthn_pubkey_cred_type_e>(0x00FFFFFF);
+ data.type = static_cast<wauthn_pubkey_cred_type_e>(0);
__testDeserializeForInvalidMember<wauthn_pubkey_cred_descriptor_s,
PubkeyCredDescriptorDeserializer>(data);
}
}
TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_descriptor_s_N3)
{// deserialize: for invalid type
- wauthn_pubkey_cred_descriptor_s data = {static_cast<wauthn_pubkey_cred_type_e>(0x00FFFFFF),
+ wauthn_pubkey_cred_descriptor_s data = {static_cast<wauthn_pubkey_cred_type_e>(0),
&TestCommonData::clientDataJson, 3};
__testDeserializeForInvalidMember<wauthn_pubkey_cred_descriptor_s,
PubkeyCredDescriptorDeserializer>(data);
TEST_F(WAuthnSerializationTest, wauthn_authenticator_sel_cri_s_N1)
{// serialize: invalid member
wauthn_authenticator_sel_cri_s data1 = TestCommonData::authenticatorSelCri;
- data1.attachment = static_cast<wauthn_authenticator_attachment_e>(0x00FFFFFF);
+ data1.attachment = static_cast<wauthn_authenticator_attachment_e>(3);
__testDeserializeForInvalidMember<wauthn_authenticator_sel_cri_s,
AuthenticatorSelCriDeserializer>(data1);
wauthn_authenticator_sel_cri_s data2 = TestCommonData::authenticatorSelCri;
- data2.resident_key = static_cast<wauthn_resident_key_requirement_e>(0x00FFFFFF);
+ data2.resident_key = static_cast<wauthn_resident_key_requirement_e>(4);
__testDeserializeForInvalidMember<wauthn_authenticator_sel_cri_s,
AuthenticatorSelCriDeserializer>(data2);
wauthn_authenticator_sel_cri_s data3 = TestCommonData::authenticatorSelCri;
- data3.user_verification = static_cast<wauthn_user_verification_requirement_e>(0x00FFFFFF);
+ data3.user_verification = static_cast<wauthn_user_verification_requirement_e>(4);
__testDeserializeForInvalidMember<wauthn_authenticator_sel_cri_s,
AuthenticatorSelCriDeserializer>(data3);
}
TEST_F(WAuthnSerializationTest, wauthn_authenticator_sel_cri_s_N2)
{// deserialize: for invalid attachment
- wauthn_authenticator_sel_cri_s data = {static_cast<wauthn_authenticator_attachment_e>(0x00FFFFFF),
+ wauthn_authenticator_sel_cri_s data = {static_cast<wauthn_authenticator_attachment_e>(3),
WAUTHN_RESIDENT_KEY_REQUIREMENT_DISCOURAGED,
false,
WAUTHN_USER_VERIFICATION_REQUIREMENT_DISCOURAGED};
TEST_F(WAuthnSerializationTest, wauthn_authenticator_sel_cri_s_N3)
{// deserialize: for invalid resident_key
wauthn_authenticator_sel_cri_s data = {WAUTHN_AUTHENTICATOR_ATTACHMENT_CROSS_PLATFORM,
- static_cast<wauthn_resident_key_requirement_e>(0x00FFFFFF),
+ static_cast<wauthn_resident_key_requirement_e>(4),
false,
WAUTHN_USER_VERIFICATION_REQUIREMENT_DISCOURAGED};
__testDeserializeForInvalidMember<wauthn_authenticator_sel_cri_s,
wauthn_authenticator_sel_cri_s data = {WAUTHN_AUTHENTICATOR_ATTACHMENT_CROSS_PLATFORM,
WAUTHN_RESIDENT_KEY_REQUIREMENT_DISCOURAGED,
false,
- static_cast<wauthn_user_verification_requirement_e>(0x00FFFFFF)};
+ static_cast<wauthn_user_verification_requirement_e>(4)};
__testDeserializeForInvalidMember<wauthn_authenticator_sel_cri_s,
AuthenticatorSelCriDeserializer>(data);
}
TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_creation_options_s_N2)
{// serialize: invalid member
wauthn_pubkey_cred_creation_options_s data = TestCommonData::pubkeyCredCreationOptions;
- data.attestation = static_cast<wauthn_attestation_pref_e>(0x00FFFFFF);
+ data.attestation = static_cast<wauthn_attestation_pref_e>(4);
__testDeserializeForInvalidMember<wauthn_pubkey_cred_creation_options_s,
PubKeyCredCreationOptionsDeserializer>(data);
}
TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_request_options_s_N1)
{// serialize: invalid member
wauthn_pubkey_cred_request_options_s data = TestCommonData::pubkeyCredRequestOptions;
- data.user_verification = static_cast<wauthn_user_verification_requirement_e>(0x00FFFFFF);
+ data.user_verification = static_cast<wauthn_user_verification_requirement_e>(4);
__testDeserializeForInvalidMember<wauthn_pubkey_cred_request_options_s,
PubKeyCredRequestOptionsDeserializer>(data);
}
TEST_F(WAuthnSerializationTest, wauthn_pubkey_cred_request_options_s_N2)
{// serialize: invalid member
wauthn_pubkey_cred_request_options_s data = TestCommonData::pubkeyCredRequestOptions;
- data.attestation = static_cast<wauthn_attestation_pref_e>(0x00FFFFFF);
+ data.attestation = static_cast<wauthn_attestation_pref_e>(4);
__testDeserializeForInvalidMember<wauthn_pubkey_cred_request_options_s,
PubKeyCredRequestOptionsDeserializer>(data);
}
TEST_F(WAuthnSerializationTest, wauthn_pubkey_credential_attestation_s_N2)
{// deserialize: for invalid type
wauthn_pubkey_credential_attestation_s data = TestCommonData::pubkeyCredentialAttestation;
- data.type = static_cast<wauthn_pubkey_cred_type_e>(0x00FFFFFF);
+ data.type = static_cast<wauthn_pubkey_cred_type_e>(0);
__testDeserializeForInvalidMember<wauthn_pubkey_credential_attestation_s,
PubkeyCredentialAttestationDeserializer>(data);
}
TEST_F(WAuthnSerializationTest, wauthn_pubkey_credential_attestation_s_N3)
{// deserialize: for invalid authenticator_attachment
wauthn_pubkey_credential_attestation_s data = TestCommonData::pubkeyCredentialAttestation;
- data.authenticator_attachment = static_cast<wauthn_authenticator_attachment_e>(0x00FFFFFF);
+ data.authenticator_attachment = static_cast<wauthn_authenticator_attachment_e>(3);
__testDeserializeForInvalidMember<wauthn_pubkey_credential_attestation_s,
PubkeyCredentialAttestationDeserializer>(data);
}
TEST_F(WAuthnSerializationTest, wauthn_pubkey_credential_assertion_s_N2)
{// deserialize: for invalid type
wauthn_pubkey_credential_assertion_s data = TestCommonData::pubkeyCredentialAssertion;
- data.type = static_cast<wauthn_pubkey_cred_type_e>(0x00FFFFFF);
+ data.type = static_cast<wauthn_pubkey_cred_type_e>(0);
__testDeserializeForInvalidMember<wauthn_pubkey_credential_assertion_s,
PubkeyCredentialAssertionDeserializer>(data);
}
TEST_F(WAuthnSerializationTest, wauthn_pubkey_credential_assertion_s_N3)
{// deserialize: for invalid authenticator_attachment
wauthn_pubkey_credential_assertion_s data = TestCommonData::pubkeyCredentialAssertion;
- data.authenticator_attachment = static_cast<wauthn_authenticator_attachment_e>(0x00FFFFFF);
+ data.authenticator_attachment = static_cast<wauthn_authenticator_attachment_e>(3);
__testDeserializeForInvalidMember<wauthn_pubkey_credential_assertion_s,
PubkeyCredentialAssertionDeserializer>(data);
}
TEST_F(WAuthnSerializationTest, wauthn_client_data_s_N1)
{// serialize: invalid member
wauthn_client_data_s data = TestCommonData::clientData;
- data.hash_alg = static_cast<wauthn_hash_algorithm_e>(0x00FFFFFF);
+ data.hash_alg = static_cast<wauthn_hash_algorithm_e>(0);
__testDeserializeForInvalidMember<wauthn_client_data_s, ClientDataDeserializer>(data);
}
TEST_F(WAuthnSerializationTest, wauthn_client_data_s_N2)
{
auto clientData = TestCommonData::clientData;
auto backupData = clientData.hash_alg;
- clientData.hash_alg = (wauthn_hash_algorithm_e)-1;
+ clientData.hash_alg = static_cast<wauthn_hash_algorithm_e>(0);
int ret = try_catch([&]() -> int {
CheckParameters(&clientData);
return WAUTHN_ERROR_NONE;
{
int ret = WAUTHN_ERROR_NONE;
auto backupData = credParams.params[i].type;
- credParams.params[i].type = (wauthn_pubkey_cred_type_e)-1;
+ credParams.params[i].type = static_cast<wauthn_pubkey_cred_type_e>(0);
ret = try_catch([&]() -> int {
CheckParameters(&credParams);
return WAUTHN_ERROR_NONE;
{
int ret = WAUTHN_ERROR_NONE;
auto backupData = credParams.params[i].alg;
- credParams.params[i].alg = (wauthn_cose_algorithm_e)-1;
+ credParams.params[i].alg = static_cast<wauthn_cose_algorithm_e>(0);
ret = try_catch([&]() -> int {
CheckParameters(&credParams);
return WAUTHN_ERROR_NONE;
{
int ret = WAUTHN_ERROR_NONE;
auto backupData = credDescs.descriptors[i].type;
- credDescs.descriptors[i].type = (wauthn_pubkey_cred_type_e)-1;
+ credDescs.descriptors[i].type = static_cast<wauthn_pubkey_cred_type_e>(0);
ret = try_catch([&]() -> int {
CheckParameters(&credDescs);
return WAUTHN_ERROR_NONE;
{
auto authSel = TestCommonData::authenticatorSelCri;
auto backupData = authSel.attachment;
- authSel.attachment = (wauthn_authenticator_attachment_e)-1;
+ authSel.attachment = static_cast<wauthn_authenticator_attachment_e>(3);
int ret = try_catch([&]() -> int {
CheckParameters(&authSel);
return WAUTHN_ERROR_NONE;
{
auto authSel = TestCommonData::authenticatorSelCri;
auto backupData = authSel.resident_key;
- authSel.resident_key = (wauthn_resident_key_requirement_e)-1;
+ authSel.resident_key = static_cast<wauthn_resident_key_requirement_e>(4);
int ret = try_catch([&]() -> int {
CheckParameters(&authSel);
return WAUTHN_ERROR_NONE;
{
auto authSel = TestCommonData::authenticatorSelCri;
auto backupData = authSel.user_verification;
- authSel.user_verification = (wauthn_user_verification_requirement_e)-1;
+ authSel.user_verification = static_cast<wauthn_user_verification_requirement_e>(4);
int ret = try_catch([&]() -> int {
CheckParameters(&authSel);
return WAUTHN_ERROR_NONE;
{
int ret = WAUTHN_ERROR_NONE;
auto backupData = hints.hints[i];
- hints.hints[i] = (wauthn_pubkey_cred_hint_e)-1;
+ hints.hints[i] = static_cast<wauthn_pubkey_cred_hint_e>(4);
ret = try_catch([&]() -> int {
CheckParameters(&hints);
return WAUTHN_ERROR_NONE;
{
auto options = TestCommonData::pubkeyCredCreationOptions;
auto backupData = options.attestation;
- options.attestation = (wauthn_attestation_pref_e)-1;
+ options.attestation = static_cast<wauthn_attestation_pref_e>(4);
int ret = try_catch([&]() -> int {
CheckParameters(&options);
return WAUTHN_ERROR_NONE;