diff --git a/.github/linkAllowList.txt b/.github/linkAllowList.txt index fd788f2c..73c1ee44 100644 --- a/.github/linkAllowList.txt +++ b/.github/linkAllowList.txt @@ -1 +1,2 @@ https://s3.region.amazonaws.com/joe-ota/ +https://www.misra.org.uk diff --git a/source/otaJobParser/include/job_parser.h b/source/otaJobParser/include/job_parser.h index a8d72dcf..875646ad 100644 --- a/source/otaJobParser/include/job_parser.h +++ b/source/otaJobParser/include/job_parser.h @@ -14,7 +14,22 @@ #include #include -typedef struct AfrOtaJobDocumentFields_t * AfrOtaJobDocumentFields; +typedef struct +{ + const char * signature; + size_t signatureLen; + const char * filepath; + size_t filepathLen; + const char * certfile; + size_t certfileLen; + const char * authScheme; + size_t authSchemeLen; + const char * imageRef; + size_t imageRefLen; + uint32_t fileId; + uint32_t fileSize; + uint32_t fileType; +} AfrOtaJobDocumentFields_t; /** * @brief Populate the fields of 'result', returning @@ -30,6 +45,6 @@ typedef struct AfrOtaJobDocumentFields_t * AfrOtaJobDocumentFields; bool populateJobDocFields( const char * jobDoc, const size_t jobDocLength, int32_t fileIndex, - AfrOtaJobDocumentFields result ); + AfrOtaJobDocumentFields_t * result ); #endif /* JOB_PARSER_H */ diff --git a/source/otaJobParser/include/ota_job_processor.h b/source/otaJobParser/include/ota_job_processor.h index 74555129..53339648 100644 --- a/source/otaJobParser/include/ota_job_processor.h +++ b/source/otaJobParser/include/ota_job_processor.h @@ -20,6 +20,6 @@ int8_t otaParser_parseJobDocFile( const char * jobDoc, const size_t jobDocLength, const uint8_t fileIndex, - AfrOtaJobDocumentFields fields ); + AfrOtaJobDocumentFields_t * fields ); #endif /*OTA_JOB_PROCESSOR_H*/ diff --git a/source/otaJobParser/job_parser.c b/source/otaJobParser/job_parser.c index c40b4c9e..c64cef14 100644 --- a/source/otaJobParser/job_parser.c +++ b/source/otaJobParser/job_parser.c @@ -15,23 +15,6 @@ #include "core_json.h" #include "job_parser.h" -struct AfrOtaJobDocumentFields_t -{ - const char * signature; - size_t signatureLen; - const char * filepath; - size_t filepathLen; - const char * certfile; - size_t certfileLen; - const char * authScheme; - size_t authSchemeLen; - const char * imageRef; - size_t imageRefLen; - uint32_t fileId; - uint32_t fileSize; - uint32_t fileType; -}; - /** * @brief Populates common job document fields in result * @@ -44,7 +27,7 @@ struct AfrOtaJobDocumentFields_t static JSONStatus_t populateCommonFields( const char * jobDoc, const size_t jobDocLength, int32_t fileIndex, - AfrOtaJobDocumentFields result ); + AfrOtaJobDocumentFields_t * result ); /** * @brief Populates MQTT job document fields in result @@ -56,7 +39,7 @@ static JSONStatus_t populateCommonFields( const char * jobDoc, */ static JSONStatus_t populateMqttStreamingFields( const char * jobDoc, const size_t jobDocLength, - AfrOtaJobDocumentFields result ); + AfrOtaJobDocumentFields_t * result ); /** * @brief Populates HTTP job document fields in result @@ -70,7 +53,7 @@ static JSONStatus_t populateMqttStreamingFields( const char * jobDoc, static JSONStatus_t populateHttpStreamingFields( const char * jobDoc, const size_t jobDocLength, int32_t fileIndex, - AfrOtaJobDocumentFields result ); + AfrOtaJobDocumentFields_t * result ); /** * @brief Assembles an indexed OTA file query @@ -151,7 +134,7 @@ static bool addOverflowUint32( const uint32_t a, bool populateJobDocFields( const char * jobDoc, const size_t jobDocLength, int32_t fileIndex, - AfrOtaJobDocumentFields result ) + AfrOtaJobDocumentFields_t * result ) { bool populatedJobDocFields = false; JSONStatus_t jsonResult = JSONNotFound; @@ -200,7 +183,7 @@ bool populateJobDocFields( const char * jobDoc, static JSONStatus_t populateCommonFields( const char * jobDoc, const size_t jobDocLength, int32_t fileIndex, - AfrOtaJobDocumentFields result ) + AfrOtaJobDocumentFields_t * result ) { JSONStatus_t jsonResult = JSONNotFound; const char * jsonValue = NULL; @@ -299,7 +282,7 @@ static JSONStatus_t populateCommonFields( const char * jobDoc, static JSONStatus_t populateMqttStreamingFields( const char * jobDoc, const size_t jobDocLength, - AfrOtaJobDocumentFields result ) + AfrOtaJobDocumentFields_t * result ) { JSONStatus_t jsonResult = JSONNotFound; const char * jsonValue = NULL; @@ -327,7 +310,7 @@ static JSONStatus_t populateMqttStreamingFields( const char * jobDoc, static JSONStatus_t populateHttpStreamingFields( const char * jobDoc, const size_t jobDocLength, int32_t fileIndex, - AfrOtaJobDocumentFields result ) + AfrOtaJobDocumentFields_t * result ) { JSONStatus_t jsonResult = JSONNotFound; const char * jsonValue = NULL; diff --git a/source/otaJobParser/ota_job_handler.c b/source/otaJobParser/ota_job_handler.c index 61e32ba6..e0f7999c 100644 --- a/source/otaJobParser/ota_job_handler.c +++ b/source/otaJobParser/ota_job_handler.c @@ -33,7 +33,7 @@ static bool isJobFileIndexValid( const char * jobDoc, int8_t otaParser_parseJobDocFile( const char * jobDoc, const size_t jobDocLength, const uint8_t fileIndex, - AfrOtaJobDocumentFields fields ) + AfrOtaJobDocumentFields_t * fields ) { bool fieldsPopulated = false; int8_t nextFileIndex = -1; diff --git a/test/cbmc/proofs.c b/test/cbmc/proofs.c index dfcfe882..a24e7dc2 100644 --- a/test/cbmc/proofs.c +++ b/test/cbmc/proofs.c @@ -443,7 +443,7 @@ void proof_populateJobDocFields( void ) const char * jobDoc; const size_t jobDocLength; int fileIndex; - AfrOtaJobDocumentFields result = { 0 }; + AfrOtaJobDocumentFields_t result = { 0 }; bool ret; __CPROVER_assume( jobDocLength <= CBMC_JOBDOC_MAX_LEN ); @@ -462,7 +462,7 @@ void proof_otaParser_parseJobDocFile( void ) const char * jobDoc; const size_t jobDocLength; const uint8_t fileIndex; - AfrOtaJobDocumentFields fields = { 0 }; + AfrOtaJobDocumentFields_t fields = { 0 }; int8_t ret; __CPROVER_assume( jobDocLength <= CBMC_JOBDOC_MAX_LEN ); diff --git a/test/unit-test/job_parser_utest.c b/test/unit-test/job_parser_utest.c index 28ae1cb8..c32e0a9a 100644 --- a/test/unit-test/job_parser_utest.c +++ b/test/unit-test/job_parser_utest.c @@ -18,26 +18,7 @@ static bool result; static uint32_t convertedUint; - -struct AfrOtaJobDocumentFields_t -{ - const char * signature; - size_t signatureLen; - const char * filepath; - size_t filepathLen; - const char * certfile; - size_t certfileLen; - const char * authScheme; - size_t authSchemeLen; - const char * imageRef; - size_t imageRefLen; - uint32_t fileId; - uint32_t fileSize; - uint32_t fileType; -}; - -struct AfrOtaJobDocumentFields_t document; -AfrOtaJobDocumentFields documentFields = &document; +static AfrOtaJobDocumentFields_t documentFields; static void resetDocumentFields( void ); @@ -45,19 +26,19 @@ static void resetDocumentFields( void ); static void resetDocumentFields( void ) { - documentFields->signature = NULL; - documentFields->signatureLen = UINT32_MAX; - documentFields->filepath = NULL; - documentFields->filepathLen = UINT32_MAX; - documentFields->certfile = NULL; - documentFields->certfileLen = UINT32_MAX; - documentFields->authScheme = NULL; - documentFields->authSchemeLen = UINT32_MAX; - documentFields->imageRef = NULL; - documentFields->imageRefLen = UINT32_MAX; - documentFields->fileId = UINT32_MAX; - documentFields->fileSize = UINT32_MAX; - documentFields->fileType = UINT32_MAX; + documentFields.signature = NULL; + documentFields.signatureLen = UINT32_MAX; + documentFields.filepath = NULL; + documentFields.filepathLen = UINT32_MAX; + documentFields.certfile = NULL; + documentFields.certfileLen = UINT32_MAX; + documentFields.authScheme = NULL; + documentFields.authSchemeLen = UINT32_MAX; + documentFields.imageRef = NULL; + documentFields.imageRefLen = UINT32_MAX; + documentFields.fileId = UINT32_MAX; + documentFields.fileSize = UINT32_MAX; + documentFields.fileType = UINT32_MAX; } /* Called before each test method. */ @@ -99,32 +80,32 @@ void test_populateJobDocFields_returnsTrue_givenValidMqttDocument( void ) result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_TRUE( result ); - TEST_ASSERT_EQUAL( 123456789U, documentFields->fileSize ); - TEST_ASSERT_EQUAL( 0U, documentFields->fileId ); + TEST_ASSERT_EQUAL( 123456789U, documentFields.fileSize ); + TEST_ASSERT_EQUAL( 0U, documentFields.fileId ); TEST_ASSERT_EQUAL_STRING_LEN( "certfile.cert", - documentFields->certfile, + documentFields.certfile, strlen( "certfile.cert" ) ); - TEST_ASSERT_EQUAL( strlen( "certfile.cert" ), documentFields->certfileLen ); + TEST_ASSERT_EQUAL( strlen( "certfile.cert" ), documentFields.certfileLen ); TEST_ASSERT_EQUAL_STRING_LEN( "signature_hash_239871", - documentFields->signature, + documentFields.signature, strlen( "signature_hash_239871" ) ); TEST_ASSERT_EQUAL( strlen( "signature_hash_239871" ), - documentFields->signatureLen ); + documentFields.signatureLen ); TEST_ASSERT_EQUAL_STRING_LEN( "/device", - documentFields->filepath, + documentFields.filepath, strlen( "/device" ) ); - TEST_ASSERT_EQUAL( strlen( "/device" ), documentFields->filepathLen ); + TEST_ASSERT_EQUAL( strlen( "/device" ), documentFields.filepathLen ); TEST_ASSERT_EQUAL_STRING_LEN( "AFR_OTA-streamname", - documentFields->imageRef, + documentFields.imageRef, strlen( "AFR_OTA-streamname" ) ); TEST_ASSERT_EQUAL( strlen( "AFR_OTA-streamname" ), - documentFields->imageRefLen ); - TEST_ASSERT_EQUAL( UINT32_MAX, documentFields->fileType ); - TEST_ASSERT_NULL( documentFields->authScheme ); - TEST_ASSERT_EQUAL( UINT32_MAX, documentFields->authSchemeLen ); + documentFields.imageRefLen ); + TEST_ASSERT_EQUAL( UINT32_MAX, documentFields.fileType ); + TEST_ASSERT_NULL( documentFields.authScheme ); + TEST_ASSERT_EQUAL( UINT32_MAX, documentFields.authSchemeLen ); } void test_populateJobDocFields_returnsTrue_givenValidMultiFileMqttDocument( void ) @@ -143,63 +124,63 @@ void test_populateJobDocFields_returnsTrue_givenValidMultiFileMqttDocument( void result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_TRUE( result ); - TEST_ASSERT_EQUAL( 123456789U, documentFields->fileSize ); - TEST_ASSERT_EQUAL( 0U, documentFields->fileId ); + TEST_ASSERT_EQUAL( 123456789U, documentFields.fileSize ); + TEST_ASSERT_EQUAL( 0U, documentFields.fileId ); TEST_ASSERT_EQUAL_STRING_LEN( "certfile.cert", - documentFields->certfile, + documentFields.certfile, strlen( "certfile.cert" ) ); - TEST_ASSERT_EQUAL( strlen( "certfile.cert" ), documentFields->certfileLen ); + TEST_ASSERT_EQUAL( strlen( "certfile.cert" ), documentFields.certfileLen ); TEST_ASSERT_EQUAL_STRING_LEN( "signature_hash_239871", - documentFields->signature, + documentFields.signature, strlen( "signature_hash_239871" ) ); TEST_ASSERT_EQUAL( strlen( "signature_hash_239871" ), - documentFields->signatureLen ); + documentFields.signatureLen ); TEST_ASSERT_EQUAL_STRING_LEN( "/path1", - documentFields->filepath, + documentFields.filepath, strlen( "/path1" ) ); - TEST_ASSERT_EQUAL( strlen( "/path1" ), documentFields->filepathLen ); + TEST_ASSERT_EQUAL( strlen( "/path1" ), documentFields.filepathLen ); TEST_ASSERT_EQUAL_STRING_LEN( "AFR_OTA-streamname", - documentFields->imageRef, + documentFields.imageRef, strlen( "AFR_OTA-streamname" ) ); TEST_ASSERT_EQUAL( strlen( "AFR_OTA-streamname" ), - documentFields->imageRefLen ); - TEST_ASSERT_EQUAL( UINT32_MAX, documentFields->fileType ); - TEST_ASSERT_NULL( documentFields->authScheme ); - TEST_ASSERT_EQUAL( UINT32_MAX, documentFields->authSchemeLen ); + documentFields.imageRefLen ); + TEST_ASSERT_EQUAL( UINT32_MAX, documentFields.fileType ); + TEST_ASSERT_NULL( documentFields.authScheme ); + TEST_ASSERT_EQUAL( UINT32_MAX, documentFields.authSchemeLen ); result = false; result = populateJobDocFields( document, strlen( document ), 1, - documentFields ); + &documentFields ); TEST_ASSERT_TRUE( result ); - TEST_ASSERT_EQUAL( 101010, documentFields->fileSize ); - TEST_ASSERT_EQUAL( 13U, documentFields->fileId ); + TEST_ASSERT_EQUAL( 101010, documentFields.fileSize ); + TEST_ASSERT_EQUAL( 13U, documentFields.fileId ); TEST_ASSERT_EQUAL_STRING_LEN( "certfile2.cert", - documentFields->certfile, + documentFields.certfile, strlen( "certfile2.cert" ) ); - TEST_ASSERT_EQUAL( strlen( "certfile2.cert" ), documentFields->certfileLen ); + TEST_ASSERT_EQUAL( strlen( "certfile2.cert" ), documentFields.certfileLen ); TEST_ASSERT_EQUAL_STRING_LEN( "signature_hash_101010", - documentFields->signature, + documentFields.signature, strlen( "signature_hash_101010" ) ); TEST_ASSERT_EQUAL( strlen( "signature_hash_101010" ), - documentFields->signatureLen ); + documentFields.signatureLen ); TEST_ASSERT_EQUAL_STRING_LEN( "/path2", - documentFields->filepath, + documentFields.filepath, strlen( "/path2" ) ); - TEST_ASSERT_EQUAL( strlen( "/path2" ), documentFields->filepathLen ); + TEST_ASSERT_EQUAL( strlen( "/path2" ), documentFields.filepathLen ); TEST_ASSERT_EQUAL_STRING_LEN( "AFR_OTA-streamname", - documentFields->imageRef, + documentFields.imageRef, strlen( "AFR_OTA-streamname" ) ); TEST_ASSERT_EQUAL( strlen( "AFR_OTA-streamname" ), - documentFields->imageRefLen ); - TEST_ASSERT_EQUAL( UINT32_MAX, documentFields->fileType ); - TEST_ASSERT_NULL( documentFields->authScheme ); - TEST_ASSERT_EQUAL( UINT32_MAX, documentFields->authSchemeLen ); + documentFields.imageRefLen ); + TEST_ASSERT_EQUAL( UINT32_MAX, documentFields.fileType ); + TEST_ASSERT_NULL( documentFields.authScheme ); + TEST_ASSERT_EQUAL( UINT32_MAX, documentFields.authSchemeLen ); } void test_populateJobDocFields_returnsTrue_givenValidHttpDocument( void ) @@ -218,36 +199,36 @@ void test_populateJobDocFields_returnsTrue_givenValidHttpDocument( void ) result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_TRUE( result ); - TEST_ASSERT_EQUAL( 343135U, documentFields->fileSize ); - TEST_ASSERT_EQUAL( 0U, documentFields->fileId ); - TEST_ASSERT_EQUAL( 2U, documentFields->fileType ); + TEST_ASSERT_EQUAL( 343135U, documentFields.fileSize ); + TEST_ASSERT_EQUAL( 0U, documentFields.fileId ); + TEST_ASSERT_EQUAL( 2U, documentFields.fileType ); TEST_ASSERT_EQUAL_STRING_LEN( "/strangepath/certificate.cert", - documentFields->certfile, + documentFields.certfile, strlen( "/strangepath/certificate.cert" ) ); TEST_ASSERT_EQUAL( strlen( "/strangepath/certificate.cert" ), - documentFields->certfileLen ); + documentFields.certfileLen ); TEST_ASSERT_EQUAL_STRING_LEN( "SIGNATUREHASH+ASDFLKJ123===", - documentFields->signature, + documentFields.signature, strlen( "SIGNATUREHASH+ASDFLKJ123===" ) ); TEST_ASSERT_EQUAL( strlen( "SIGNATUREHASH+ASDFLKJ123===" ), - documentFields->signatureLen ); + documentFields.signatureLen ); TEST_ASSERT_EQUAL_STRING_LEN( "/device", - documentFields->filepath, + documentFields.filepath, strlen( "/device" ) ); - TEST_ASSERT_EQUAL( strlen( "/device" ), documentFields->filepathLen ); + TEST_ASSERT_EQUAL( strlen( "/device" ), documentFields.filepathLen ); TEST_ASSERT_EQUAL_STRING_LEN( "presignedS3Url.s3.amazon.com", - documentFields->imageRef, + documentFields.imageRef, strlen( "presignedS3Url.s3.amazon.com" ) ); TEST_ASSERT_EQUAL( strlen( "presignedS3Url.s3.amazon.com" ), - documentFields->imageRefLen ); + documentFields.imageRefLen ); TEST_ASSERT_EQUAL_STRING_LEN( "aws.s3.presigned", - documentFields->authScheme, + documentFields.authScheme, strlen( "aws.s3.presigned" ) ); TEST_ASSERT_EQUAL( strlen( "aws.s3.presigned" ), - documentFields->authSchemeLen ); + documentFields.authSchemeLen ); } void test_populateJobDocFields_returnsTrue_givenValidMultiFileHttpDocument( void ) @@ -270,71 +251,71 @@ void test_populateJobDocFields_returnsTrue_givenValidMultiFileHttpDocument( void result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_TRUE( result ); - TEST_ASSERT_EQUAL( 343135U, documentFields->fileSize ); - TEST_ASSERT_EQUAL( 0U, documentFields->fileId ); - TEST_ASSERT_EQUAL( 2U, documentFields->fileType ); + TEST_ASSERT_EQUAL( 343135U, documentFields.fileSize ); + TEST_ASSERT_EQUAL( 0U, documentFields.fileId ); + TEST_ASSERT_EQUAL( 2U, documentFields.fileType ); TEST_ASSERT_EQUAL_STRING_LEN( "/strangepath/certificate.cert", - documentFields->certfile, + documentFields.certfile, strlen( "/strangepath/certificate.cert" ) ); TEST_ASSERT_EQUAL( strlen( "/strangepath/certificate.cert" ), - documentFields->certfileLen ); + documentFields.certfileLen ); TEST_ASSERT_EQUAL_STRING_LEN( "SIGNATUREHASH+ASDFLKJ123===", - documentFields->signature, + documentFields.signature, strlen( "SIGNATUREHASH+ASDFLKJ123===" ) ); TEST_ASSERT_EQUAL( strlen( "SIGNATUREHASH+ASDFLKJ123===" ), - documentFields->signatureLen ); + documentFields.signatureLen ); TEST_ASSERT_EQUAL_STRING_LEN( "/device", - documentFields->filepath, + documentFields.filepath, strlen( "/device" ) ); - TEST_ASSERT_EQUAL( strlen( "/device" ), documentFields->filepathLen ); + TEST_ASSERT_EQUAL( strlen( "/device" ), documentFields.filepathLen ); TEST_ASSERT_EQUAL_STRING_LEN( "presignedS3Url.s3.amazon.com", - documentFields->imageRef, + documentFields.imageRef, strlen( "presignedS3Url.s3.amazon.com" ) ); TEST_ASSERT_EQUAL( strlen( "presignedS3Url.s3.amazon.com" ), - documentFields->imageRefLen ); + documentFields.imageRefLen ); TEST_ASSERT_EQUAL_STRING_LEN( "aws.s3.presigned", - documentFields->authScheme, + documentFields.authScheme, strlen( "aws.s3.presigned" ) ); TEST_ASSERT_EQUAL( strlen( "aws.s3.presigned" ), - documentFields->authSchemeLen ); + documentFields.authSchemeLen ); result = false; result = populateJobDocFields( document, strlen( document ), 1, - documentFields ); + &documentFields ); TEST_ASSERT_TRUE( result ); - TEST_ASSERT_EQUAL( 43210U, documentFields->fileSize ); - TEST_ASSERT_EQUAL( 99U, documentFields->fileId ); - TEST_ASSERT_EQUAL( 333U, documentFields->fileType ); + TEST_ASSERT_EQUAL( 43210U, documentFields.fileSize ); + TEST_ASSERT_EQUAL( 99U, documentFields.fileId ); + TEST_ASSERT_EQUAL( 333U, documentFields.fileType ); TEST_ASSERT_EQUAL_STRING_LEN( "/strangepath/file.cert", - documentFields->certfile, + documentFields.certfile, strlen( "/strangepath/file.cert" ) ); TEST_ASSERT_EQUAL( strlen( "/strangepath/file.cert" ), - documentFields->certfileLen ); + documentFields.certfileLen ); TEST_ASSERT_EQUAL_STRING_LEN( "SIGNATUREHASH+ASDFLKJ123===", - documentFields->signature, + documentFields.signature, strlen( "SIGNATUREHASH+ASDFLKJ123===" ) ); TEST_ASSERT_EQUAL( strlen( "SIGNATUREHASH+ASDFLKJ123===" ), - documentFields->signatureLen ); + documentFields.signatureLen ); TEST_ASSERT_EQUAL_STRING_LEN( "/path2", - documentFields->filepath, + documentFields.filepath, strlen( "/path2" ) ); - TEST_ASSERT_EQUAL( strlen( "/path2" ), documentFields->filepathLen ); + TEST_ASSERT_EQUAL( strlen( "/path2" ), documentFields.filepathLen ); TEST_ASSERT_EQUAL_STRING_LEN( "presignedS3Url.s3.amazon.com", - documentFields->imageRef, + documentFields.imageRef, strlen( "presignedS3Url.s3.amazon.com" ) ); TEST_ASSERT_EQUAL( strlen( "presignedS3Url.s3.amazon.com" ), - documentFields->imageRefLen ); + documentFields.imageRefLen ); TEST_ASSERT_EQUAL_STRING_LEN( "aws.s3.presigned", - documentFields->authScheme, + documentFields.authScheme, strlen( "aws.s3.presigned" ) ); TEST_ASSERT_EQUAL( strlen( "aws.s3.presigned" ), - documentFields->authSchemeLen ); + documentFields.authSchemeLen ); } void test_populateJobDocFields_returnsTrue_givenValidMultiProtocolDocument( void ) @@ -352,32 +333,32 @@ void test_populateJobDocFields_returnsTrue_givenValidMultiProtocolDocument( void result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_TRUE( result ); - TEST_ASSERT_EQUAL( 123456789U, documentFields->fileSize ); - TEST_ASSERT_EQUAL( 0U, documentFields->fileId ); + TEST_ASSERT_EQUAL( 123456789U, documentFields.fileSize ); + TEST_ASSERT_EQUAL( 0U, documentFields.fileId ); TEST_ASSERT_EQUAL_STRING_LEN( "certfile.cert", - documentFields->certfile, + documentFields.certfile, strlen( "certfile.cert" ) ); - TEST_ASSERT_EQUAL( strlen( "certfile.cert" ), documentFields->certfileLen ); + TEST_ASSERT_EQUAL( strlen( "certfile.cert" ), documentFields.certfileLen ); TEST_ASSERT_EQUAL_STRING_LEN( "signature_hash_239871", - documentFields->signature, + documentFields.signature, strlen( "signature_hash_239871" ) ); TEST_ASSERT_EQUAL( strlen( "signature_hash_239871" ), - documentFields->signatureLen ); + documentFields.signatureLen ); TEST_ASSERT_EQUAL_STRING_LEN( "/device", - documentFields->filepath, + documentFields.filepath, strlen( "/device" ) ); - TEST_ASSERT_EQUAL( strlen( "/device" ), documentFields->filepathLen ); + TEST_ASSERT_EQUAL( strlen( "/device" ), documentFields.filepathLen ); TEST_ASSERT_EQUAL_STRING_LEN( "AFR_OTA-streamname", - documentFields->imageRef, + documentFields.imageRef, strlen( "AFR_OTA-streamname" ) ); TEST_ASSERT_EQUAL( strlen( "AFR_OTA-streamname" ), - documentFields->imageRefLen ); - TEST_ASSERT_EQUAL( UINT32_MAX, documentFields->fileType ); - TEST_ASSERT_NULL( documentFields->authScheme ); - TEST_ASSERT_EQUAL( UINT32_MAX, documentFields->authSchemeLen ); + documentFields.imageRefLen ); + TEST_ASSERT_EQUAL( UINT32_MAX, documentFields.fileType ); + TEST_ASSERT_NULL( documentFields.authScheme ); + TEST_ASSERT_EQUAL( UINT32_MAX, documentFields.authSchemeLen ); } void test_populateJobDocFields_returnsFalse_whenEmptyProtocol( void ) @@ -394,7 +375,7 @@ void test_populateJobDocFields_returnsFalse_whenEmptyProtocol( void ) result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_FALSE( result ); } @@ -414,7 +395,7 @@ void test_populateJobDocFields_returnsFalse_whenMissingProtocol( void ) result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_FALSE( result ); } @@ -432,7 +413,7 @@ void test_populateJobDocFields_returnsFalse_whenMissingFilesize( void ) result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_FALSE( result ); } @@ -452,7 +433,7 @@ void test_populateJobDocFields_returnsFalse_whenMissingFileId( void ) result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_FALSE( result ); } @@ -470,7 +451,7 @@ void test_populateJobDocFields_returnsFalse_whenMissingFilePath( void ) result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_FALSE( result ); } @@ -489,7 +470,7 @@ void test_populateJobDocFields_returnsFalse_whenMissingCertfile( void ) result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_FALSE( result ); } @@ -506,7 +487,7 @@ void test_populateJobDocFields_returnsFalse_whenMissingSignature( void ) result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_FALSE( result ); } @@ -523,7 +504,7 @@ void test_populateJobDocFields_returnsFalse_whenMqttDocEmptyStreamName( void ) result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_FALSE( result ); } @@ -542,7 +523,7 @@ void test_populateJobDocFields_returnsFalse_whenMqttDocMissingStreamName( void ) result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_FALSE( result ); } @@ -565,7 +546,7 @@ void test_populateJobDocFields_returnsFalse_whenHttpDocMissingFileType( void ) result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_FALSE( result ); } @@ -584,7 +565,7 @@ void test_populateJobDocFields_returnsFalse_whenHttpDocEmptyUrl( void ) result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_FALSE( result ); } @@ -604,7 +585,7 @@ void test_populateJobDocFields_returnsFalse_whenHttpDocMissingUrl( void ) result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_FALSE( result ); } @@ -627,7 +608,7 @@ void test_populateJobDocFields_returnsFalse_whenHttpDocMissingAuthScheme( void ) result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_FALSE( result ); } @@ -645,7 +626,7 @@ void test_populateJobDocFields_returnsFalse_whenFileSizeIsNegativeInteger() result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_FALSE( result ); } @@ -663,7 +644,7 @@ void test_populateJobDocFields_returnsFalse_whenFileSizeZeroLength() result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_FALSE( result ); } @@ -681,7 +662,7 @@ void test_populateJobDocFields_returnsFalse_whenFileSizeTooLarge() result = populateJobDocFields( document, strlen( document ), 0, - documentFields ); + &documentFields ); TEST_ASSERT_FALSE( result ); } diff --git a/test/unit-test/ota_job_handler_utest.c b/test/unit-test/ota_job_handler_utest.c index f4170448..c060823e 100644 --- a/test/unit-test/ota_job_handler_utest.c +++ b/test/unit-test/ota_job_handler_utest.c @@ -32,13 +32,26 @@ #define CUSTOM_DOCUMENT "{\"custom_job\":\"test\"}" #define CUSTOM_DOCUMENT_LENGTH ( sizeof( CUSTOM_DOCUMENT ) - 1U ) -AfrOtaJobDocumentFields parsedFields; +AfrOtaJobDocumentFields_t parsedFields; /* =========================== UNITY FIXTURES ============================ */ /* Called before each test method. */ void setUp() { + parsedFields.signature = "expectedSignature"; + parsedFields.signatureLen = strlen( "expectedSignature" ); + parsedFields.filepath = "expectedFilepath"; + parsedFields.filepathLen = strlen( "expectedFilepath" ); + parsedFields.certfile = "expectedCertfile"; + parsedFields.certfileLen = strlen( "expectedCertfile" ); + parsedFields.authScheme = "expectedAuthScheme"; + parsedFields.authSchemeLen = strlen( "expectedAuthScheme" ); + parsedFields.imageRef = "expectedImageRef"; + parsedFields.imageRefLen = strlen( "expectedImageRef" ); + parsedFields.fileId = UINT32_MAX; + parsedFields.fileSize = UINT32_MAX; + parsedFields.fileType = UINT32_MAX; } /* Called after each test method. */ @@ -57,65 +70,91 @@ int suiteTearDown( int numFailures ) return numFailures; } +/* + * NOTE: In production, the string fields would not be null-terminated strings, + * however since we're mocking the return we can force them to be + * null-terminated for easier validation. + */ +void verifyCallbackValues( AfrOtaJobDocumentFields_t * params ) +{ + TEST_ASSERT_EQUAL_STRING( "expectedSignature", params->signature ); + TEST_ASSERT_EQUAL( strlen( "expectedSignature" ), params->signatureLen ); + TEST_ASSERT_EQUAL_STRING( "expectedFilepath", params->filepath ); + TEST_ASSERT_EQUAL( strlen( "expectedFilepath" ), params->filepathLen ); + TEST_ASSERT_EQUAL_STRING( "expectedCertfile", params->certfile ); + TEST_ASSERT_EQUAL( strlen( "expectedCertfile" ), params->certfileLen ); + TEST_ASSERT_EQUAL_STRING( "expectedAuthScheme", params->authScheme ); + TEST_ASSERT_EQUAL( strlen( "expectedAuthScheme" ), params->authSchemeLen ); + TEST_ASSERT_EQUAL_STRING( "expectedImageRef", params->imageRef ); + TEST_ASSERT_EQUAL( strlen( "expectedImageRef" ), params->imageRefLen ); + TEST_ASSERT_EQUAL( UINT32_MAX, params->fileId ); + TEST_ASSERT_EQUAL( UINT32_MAX, params->fileSize ); + TEST_ASSERT_EQUAL( UINT32_MAX, params->fileType ); +} + +static void expectPopulateJobDocWithFileIndex( const char * document, + size_t docLength, + int index ) +{ + populateJobDocFields_ExpectAndReturn( document, + docLength, + index, + NULL, + true ); + populateJobDocFields_IgnoreArg_result(); + populateJobDocFields_ReturnThruPtr_result( &parsedFields ); +} + /* =============================== TESTS =============================== */ void test_parseJobDocFile_returnsZero_whenSingleFileJob( void ) { - populateJobDocFields_ExpectAndReturn( AFR_OTA_DOCUMENT, - AFR_OTA_DOCUMENT_LENGTH, - 0, - parsedFields, - true ); + expectPopulateJobDocWithFileIndex( AFR_OTA_DOCUMENT, + AFR_OTA_DOCUMENT_LENGTH, + 0 ); int8_t result = otaParser_parseJobDocFile( AFR_OTA_DOCUMENT, AFR_OTA_DOCUMENT_LENGTH, 0U, - parsedFields ); + &parsedFields ); TEST_ASSERT_EQUAL( 0, result ); } void test_parseJobDocFile_returnsNextIndex_whenMultiFileIOTOtaJob( void ) { - populateJobDocFields_ExpectAndReturn( MULTI_FILE_OTA_DOCUMENT, - MULTI_FILE_OTA_DOCUMENT_LENGTH, - 0, - parsedFields, - true ); - - populateJobDocFields_ExpectAndReturn( MULTI_FILE_OTA_DOCUMENT, - MULTI_FILE_OTA_DOCUMENT_LENGTH, - 1, - parsedFields, - true ); + expectPopulateJobDocWithFileIndex( MULTI_FILE_OTA_DOCUMENT, + MULTI_FILE_OTA_DOCUMENT_LENGTH, + 0 ); + expectPopulateJobDocWithFileIndex( MULTI_FILE_OTA_DOCUMENT, + MULTI_FILE_OTA_DOCUMENT_LENGTH, + 1 ); int8_t result = otaParser_parseJobDocFile( MULTI_FILE_OTA_DOCUMENT, MULTI_FILE_OTA_DOCUMENT_LENGTH, 0U, - parsedFields ); + &parsedFields ); TEST_ASSERT_EQUAL( 1, result ); result = otaParser_parseJobDocFile( MULTI_FILE_OTA_DOCUMENT, MULTI_FILE_OTA_DOCUMENT_LENGTH, 1U, - parsedFields ); + &parsedFields ); TEST_ASSERT_EQUAL( 2, result ); } void test_parseJobDocFile_returnsZero_whenLastFileIndex( void ) { - populateJobDocFields_ExpectAndReturn( MULTI_FILE_OTA_DOCUMENT, - MULTI_FILE_OTA_DOCUMENT_LENGTH, - 2, - parsedFields, - true ); + expectPopulateJobDocWithFileIndex( MULTI_FILE_OTA_DOCUMENT, + MULTI_FILE_OTA_DOCUMENT_LENGTH, + 2 ); int8_t result = otaParser_parseJobDocFile( MULTI_FILE_OTA_DOCUMENT, MULTI_FILE_OTA_DOCUMENT_LENGTH, 2U, - parsedFields ); + &parsedFields ); TEST_ASSERT_EQUAL( 0, result ); } @@ -125,7 +164,7 @@ void test_parseJobDocFile_returnsNegativeOne_whenIndexOutOfRange( void ) int8_t result = otaParser_parseJobDocFile( AFR_OTA_DOCUMENT, AFR_OTA_DOCUMENT_LENGTH, 1U, - parsedFields ); + &parsedFields ); TEST_ASSERT_EQUAL( -1, result ); } @@ -142,7 +181,7 @@ void test_parseJobDocFile_returnsNegativeOne_whenParsingFails( void ) int8_t result = otaParser_parseJobDocFile( AFR_OTA_DOCUMENT, AFR_OTA_DOCUMENT_LENGTH, 0U, - parsedFields ); + &parsedFields ); TEST_ASSERT_EQUAL( -1, result ); } @@ -159,7 +198,7 @@ void test_parseJobDocFile_returnsNegativeOne_whenMultiFileParsingFails( void ) int8_t result = otaParser_parseJobDocFile( MULTI_FILE_OTA_DOCUMENT, MULTI_FILE_OTA_DOCUMENT_LENGTH, 0, - parsedFields ); + &parsedFields ); TEST_ASSERT_EQUAL( -1, result ); } @@ -169,7 +208,7 @@ void test_parseJobDocFile_returnsNegativeOne_whenCustomJob( void ) int8_t result = otaParser_parseJobDocFile( CUSTOM_DOCUMENT, CUSTOM_DOCUMENT_LENGTH, 0U, - parsedFields ); + &parsedFields ); TEST_ASSERT_EQUAL( -1, result ); } @@ -179,7 +218,7 @@ void test_parseJobDocFile_returnsFalse_givenNullJobDocument( void ) int8_t result = otaParser_parseJobDocFile( NULL, CUSTOM_DOCUMENT_LENGTH, 0U, - parsedFields ); + &parsedFields ); TEST_ASSERT_EQUAL( -1, result ); } @@ -189,7 +228,7 @@ void test_parseJobDocFile_returnsFalse_givenZeroDocumentLength( void ) int8_t result = otaParser_parseJobDocFile( AFR_OTA_DOCUMENT, 0U, 0U, - parsedFields ); + &parsedFields ); TEST_ASSERT_EQUAL( -1, result ); } diff --git a/tools/coverity/misra.config b/tools/coverity/misra.config index daac76e1..c272741a 100644 --- a/tools/coverity/misra.config +++ b/tools/coverity/misra.config @@ -5,6 +5,11 @@ standard : "c2012", title: "Coverity MISRA Configuration", deviations : [ + { + deviation: "Directive 4.8", + category: "Advisory", + reason: "AfrOtaJobDocumentFields_t struct must be externally visible in able to be used by the application." + }, { deviation: "Directive 4.9", category: "Advisory",