UnitTest/TestSpdmRequester/TestSpdmRequesterGetMeasurement.c
/**
  Test 17: Error case, response to get total number of measurements, but response NumberOfBlocks and/or MeasurementRecordLength are non 0
  Expected Behavior: get a RETURN_DEVICE_ERROR return code
**/
Test 17: Error case, response to get total number of measurements, but response NumberOfBlocks and/or MeasurementRecordLength are non 0
Expected Behavior: get a RETURN_DEVICE_ERROR return code
Test 17 : Error case response to get total number of measurements but response NumberOfBlocks and / or MeasurementRecordLength are non 0 Expected Behavior : get a RETURN_DEVICE_ERROR return code
void TestSpdmRequesterGetMeasurementCase17(void **state) {
  RETURN_STATUS        Status;
  SPDM_TEST_CONTEXT    *SpdmTestContext;
  SPDM_DEVICE_CONTEXT  *SpdmContext;
  UINT8                NumberOfBlocks;
  UINT8                RequestAttribute;
  VOID                 *Data;
  UINTN                DataSize;
  VOID                 *Hash;
  UINTN                HashSize;
  SpdmTestContext = *state;
  SpdmContext = SpdmTestContext->SpdmContext;
  SpdmTestContext->CaseId = 0x11;
  SpdmContext->ConnectionInfo.Version.SpdmVersionCount = 1;
  SpdmContext->ConnectionInfo.Version.SpdmVersion[0].MajorVersion = 1;
  SpdmContext->ConnectionInfo.Version.SpdmVersion[0].MinorVersion = 1;
  SpdmContext->ConnectionInfo.ConnectionState = SpdmConnectionStateAuthenticated;
  SpdmContext->ConnectionInfo.Capability.Flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG;
  ReadResponderPublicCertificateChain (mUseHashAlgo, mUseAsymAlgo, &Data, &DataSize, &Hash, &HashSize);
  SpdmContext->Transcript.MessageM.BufferSize = 0;
  SpdmContext->ConnectionInfo.Algorithm.MeasurementSpec = mUseMeasurementSpec;
  SpdmContext->ConnectionInfo.Algorithm.MeasurementHashAlgo = mUseMeasurementHashAlgo;
  SpdmContext->ConnectionInfo.Algorithm.BaseHashAlgo = mUseHashAlgo;
  SpdmContext->ConnectionInfo.Algorithm.BaseAsymAlgo = mUseAsymAlgo;
  SpdmContext->ConnectionInfo.PeerUsedCertChainBufferSize = DataSize;
  CopyMem (SpdmContext->ConnectionInfo.PeerUsedCertChainBuffer, Data, DataSize);
  RequestAttribute = 0;
  for (int i=0; i<3; i++) {
    Status = SpdmGetMeasurement (
               SpdmContext, NULL, RequestAttribute,
               SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS,
               0, &NumberOfBlocks, NULL, NULL);
    assert_int_equal (Status, RETURN_DEVICE_ERROR);
    assert_int_equal (SpdmContext->Transcript.MessageM.BufferSize, 0);
  }
  free(Data);
}
void TestSpdmRequesterGetMeasurementCase17 ( void * * state ) { RETURN_STATUS Status ; SPDM_TEST_CONTEXT * SpdmTestContext ; SPDM_DEVICE_CONTEXT * SpdmContext ; UINT8 NumberOfBlocks ; UINT8 RequestAttribute ; VOID * Data ; UINTN DataSize ; VOID * Hash ; UINTN HashSize ; SpdmTestContext = * state ; SpdmContext = SpdmTestContext -> SpdmContext ; SpdmTestContext -> CaseId = 0x11 ; SpdmContext -> ConnectionInfo . Version . SpdmVersionCount = 1 ; SpdmContext -> ConnectionInfo . Version . SpdmVersion [ 0 ] . MajorVersion = 1 ; SpdmContext -> ConnectionInfo . Version . SpdmVersion [ 0 ] . MinorVersion = 1 ; SpdmContext -> ConnectionInfo . ConnectionState = SpdmConnectionStateAuthenticated ; SpdmContext -> ConnectionInfo . Capability . Flags |= SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MEAS_CAP_SIG ; ReadResponderPublicCertificateChain ( mUseHashAlgo , mUseAsymAlgo , & Data , & DataSize , & Hash , & HashSize ) ; SpdmContext -> Transcript . MessageM . BufferSize = 0 ; SpdmContext -> ConnectionInfo . Algorithm . MeasurementSpec = mUseMeasurementSpec ; SpdmContext -> ConnectionInfo . Algorithm . MeasurementHashAlgo = mUseMeasurementHashAlgo ; SpdmContext -> ConnectionInfo . Algorithm . BaseHashAlgo = mUseHashAlgo ; SpdmContext -> ConnectionInfo . Algorithm . BaseAsymAlgo = mUseAsymAlgo ; SpdmContext -> ConnectionInfo . PeerUsedCertChainBufferSize = DataSize ; CopyMem ( SpdmContext -> ConnectionInfo . PeerUsedCertChainBuffer , Data , DataSize ) ; RequestAttribute = 0 ; for ( int i = 0 ; i < 3 ; i ++ ) { Status = SpdmGetMeasurement ( SpdmContext , NULL , RequestAttribute , SPDM_GET_MEASUREMENTS_REQUEST_MEASUREMENT_OPERATION_TOTAL_NUMBER_OF_MEASUREMENTS , 0 , & NumberOfBlocks , NULL , NULL ) ; assert_int_equal ( Status , RETURN_DEVICE_ERROR ) ; assert_int_equal ( SpdmContext -> Transcript . MessageM . BufferSize , 0 ) ; } free ( Data ) ; }
Test 17: Error case, response to get total number of measurements, but response NumberOfBlocks and/or MeasurementRecordLength are non 0
Expected Behavior: get a RETURN_DEVICE_ERROR return code
Test 17 : Error case response to get total number of measurements but response NumberOfBlocks and / or MeasurementRecordLength are non 0 Expected Behavior : get a RETURN_DEVICE_ERROR return code
// i=0 => both NumberOfBlocks and MeasurementRecordLength are non 0
 // i=1 => only NumberOfBlocks is non 0
 // i=2 => only is MeasurementRecordLength is non 0
