Skip to content

Commit c9b4b6e

Browse files
committed
Add unit test for OtherParamsSelection has more than one bit set.
Signed-off-by: Zhao, Zhiqiang <[email protected]>
1 parent a732e90 commit c9b4b6e

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

unit_test/test_spdm_requester/error_test/negotiate_algorithms_err.c

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ static libspdm_return_t libspdm_requester_negotiate_algorithms_test_send_message
123123
return LIBSPDM_STATUS_SUCCESS;
124124
case 0x29:
125125
return LIBSPDM_STATUS_SUCCESS;
126+
case 0x2A:
127+
return LIBSPDM_STATUS_SUCCESS;
126128
default:
127129
return LIBSPDM_STATUS_SEND_FAIL;
128130
}
@@ -1565,6 +1567,41 @@ static libspdm_return_t libspdm_requester_negotiate_algorithm_test_receive_messa
15651567
}
15661568
return LIBSPDM_STATUS_SUCCESS;
15671569

1570+
case 0x2A: {
1571+
spdm_algorithms_response_t *spdm_response;
1572+
size_t spdm_response_size;
1573+
size_t transport_header_size;
1574+
1575+
spdm_response_size = sizeof(spdm_algorithms_response_t);
1576+
transport_header_size = libspdm_transport_test_get_header_size(spdm_context);
1577+
spdm_response = (void *)((uint8_t *)*response + transport_header_size);
1578+
1579+
libspdm_zero_mem(spdm_response, spdm_response_size);
1580+
spdm_response->header.spdm_version = SPDM_MESSAGE_VERSION_12;
1581+
spdm_response->header.request_response_code = SPDM_ALGORITHMS;
1582+
spdm_response->header.param1 = 0;
1583+
spdm_response->header.param2 = 0;
1584+
spdm_response->length = sizeof(spdm_algorithms_response_t);
1585+
spdm_response->measurement_specification_sel =
1586+
SPDM_MEASUREMENT_BLOCK_HEADER_SPECIFICATION_DMTF;
1587+
/* Two bits set when only one should be set. */
1588+
spdm_response->other_params_support =
1589+
SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_0 |
1590+
SPDM_ALGORITHMS_OPAQUE_DATA_FORMAT_1;
1591+
spdm_response->measurement_hash_algo =
1592+
m_libspdm_use_measurement_hash_algo;
1593+
spdm_response->base_asym_sel = m_libspdm_use_asym_algo;
1594+
spdm_response->base_hash_sel = m_libspdm_use_hash_algo;
1595+
spdm_response->ext_asym_sel_count = 0;
1596+
spdm_response->ext_hash_sel_count = 0;
1597+
1598+
libspdm_transport_test_encode_message(spdm_context, NULL, false,
1599+
false, spdm_response_size,
1600+
spdm_response,
1601+
response_size, response);
1602+
}
1603+
return LIBSPDM_STATUS_SUCCESS;
1604+
15681605
default:
15691606
return LIBSPDM_STATUS_RECEIVE_FAIL;
15701607
}
@@ -2653,7 +2690,7 @@ static void libspdm_test_requester_negotiate_algorithms_error_case35(void **stat
26532690
}
26542691

26552692
/**
2656-
* Test 35: MeasurementSpecificationSel has more than one bit set.
2693+
* Test 36: MeasurementSpecificationSel has more than one bit set.
26572694
* Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
26582695
**/
26592696
static void libspdm_test_requester_negotiate_algorithms_error_case36(void **state)
@@ -2854,6 +2891,33 @@ static void libspdm_test_requester_negotiate_algorithms_error_case40(void** stat
28542891
assert_int_equal(status, LIBSPDM_STATUS_INVALID_MSG_FIELD);
28552892
}
28562893

2894+
/**
2895+
* Test 41: OtherParamsSelection is added in SPDM 1.2.
2896+
* OtherParamsSelection has more than one bit set.
2897+
* Expected behavior: returns with status LIBSPDM_STATUS_INVALID_MSG_FIELD.
2898+
**/
2899+
static void libspdm_test_requester_negotiate_algorithms_error_case41(void **state)
2900+
{
2901+
libspdm_return_t status;
2902+
libspdm_test_context_t *spdm_test_context;
2903+
libspdm_context_t *spdm_context;
2904+
2905+
spdm_test_context = *state;
2906+
spdm_context = spdm_test_context->spdm_context;
2907+
spdm_test_context->case_id = 0x2A;
2908+
spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 <<
2909+
SPDM_VERSION_NUMBER_SHIFT_BIT;
2910+
spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_AFTER_CAPABILITIES;
2911+
spdm_context->local_context.algorithm.measurement_hash_algo =
2912+
m_libspdm_use_measurement_hash_algo;
2913+
spdm_context->local_context.algorithm.base_asym_algo = m_libspdm_use_asym_algo;
2914+
spdm_context->local_context.algorithm.base_hash_algo = m_libspdm_use_hash_algo;
2915+
libspdm_reset_message_a(spdm_context);
2916+
2917+
status = libspdm_negotiate_algorithms(spdm_context);
2918+
assert_int_equal(status, LIBSPDM_STATUS_NEGOTIATION_FAIL);
2919+
}
2920+
28572921
libspdm_test_context_t m_libspdm_requester_negotiate_algorithms_test_context = {
28582922
LIBSPDM_TEST_CONTEXT_VERSION,
28592923
true,
@@ -2907,6 +2971,7 @@ int libspdm_requester_negotiate_algorithms_error_test_main(void)
29072971
cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case38),
29082972
cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case39),
29092973
cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case40),
2974+
cmocka_unit_test(libspdm_test_requester_negotiate_algorithms_error_case41),
29102975
};
29112976

29122977
libspdm_setup_test_context(&m_libspdm_requester_negotiate_algorithms_test_context);

0 commit comments

Comments
 (0)