From 92a7620465c7857f690d80b7c343fd92480ecc86 Mon Sep 17 00:00:00 2001 From: "Ching-Hsin,Lee" Date: Wed, 1 May 2024 15:02:40 +0000 Subject: [PATCH 1/5] Add unit test to cover httpParserOnStatusCompleteCallback --- test/unit-test/core_http_send_utest.c | 97 ++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 11 deletions(-) diff --git a/test/unit-test/core_http_send_utest.c b/test/unit-test/core_http_send_utest.c index 28197e9c..4a376ba4 100644 --- a/test/unit-test/core_http_send_utest.c +++ b/test/unit-test/core_http_send_utest.c @@ -75,6 +75,7 @@ /* HTTP OK Status-Line. */ #define HTTP_STATUS_LINE_OK "HTTP/1.1 200 OK\r\n" +#define HTTP_STATUS_LINE_NO_REASON_PHRASE "HTTP/1.1 200\r\n" #define HTTP_STATUS_CODE_OK 200 /* Various header lines for test response templates. */ @@ -109,6 +110,21 @@ #define HTTP_TEST_RESPONSE_HEAD_PARTIAL_HEADER_FIELD_LENGTH ( sizeof( HTTP_STATUS_LINE_OK ) + sizeof( HTTP_TEST_CONTENT_LENGTH_PARTIAL_HEADER_FIELD ) - 2U ) #define HTTP_TEST_RESPONSE_HEAD_PARTIAL_HEADER_VALUE_LENGTH ( sizeof( HTTP_STATUS_LINE_OK ) + sizeof( HTTP_TEST_CONTENT_LENGTH_PARTIAL_HEADER_VALUE ) - 2U ) +#define HTTP_TEST_RESPONSE_HEAD_2 \ + HTTP_STATUS_LINE_NO_REASON_PHRASE \ + HTTP_TEST_CONTENT_LENGTH_HEADER_LINE \ + HTTP_TEST_CONNECTION_CLOSE_HEADER_LINE \ + HTTP_TEST_DATE_HEADER_LINE \ + HTTP_TEST_ETAG_HEADER_LINE \ + HTTP_TEST_VARY_HEADER_LINE \ + HTTP_TEST_P3P_HEADER_LINE \ + HTTP_TEST_XSERVER_HEADER_LINE HTTP_HEADER_LINE_SEPARATOR +#define HTTP_TEST_RESPONSE_HEAD_2_LENGTH ( sizeof( HTTP_TEST_RESPONSE_HEAD_2 ) - 1U ) +#define HTTP_TEST_RESPONSE_HEAD_2_HEADER_COUNT 7 +#define HTTP_TEST_RESPONSE_HEAD_2_CONTENT_LENGTH 43 +#define HTTP_TEST_RESPONSE_HEAD_2_PARTIAL_HEADER_FIELD_LENGTH ( sizeof( HTTP_STATUS_LINE_NO_REASON_PHRASE ) + sizeof( HTTP_TEST_CONTENT_LENGTH_PARTIAL_HEADER_FIELD ) - 2U ) +#define HTTP_TEST_RESPONSE_HEAD_2_PARTIAL_HEADER_VALUE_LENGTH ( sizeof( HTTP_STATUS_LINE_NO_REASON_PHRASE ) + sizeof( HTTP_TEST_CONTENT_LENGTH_PARTIAL_HEADER_VALUE ) - 2U ) + /* Template HTTP PUT response. This has no body. */ #define HTTP_TEST_RESPONSE_PUT \ HTTP_STATUS_LINE_OK \ @@ -235,6 +251,9 @@ static HTTPRequestHeaders_t requestHeaders = { 0 }; /* Header parsing callback shared among the tests. */ static HTTPClient_ResponseHeaderParsingCallback_t headerParsingCallback = { 0 }; +/* Flag to indicate this callback is called. */ +static int statuCompleteCallbackFlag = 0; + /* A mocked timer query function that increments on every call. */ static uint32_t getTestTime( void ) { @@ -432,6 +451,7 @@ static void helper_parse_status_line( const char ** pNext, const llhttp_settings_t * pSettings ) { const char * pReasonPhraseStart = NULL; + const char * pNextLineStart = NULL; size_t reasonPhraseStartLen = 0; /* For purposes of unit testing the response is well formed in the non-error @@ -440,17 +460,36 @@ static void helper_parse_status_line( const char ** pNext, * always string literals. strchr() should not be used in application code. */ *pNext = strchr( *pNext, SPACE_CHARACTER ); /* Get the space before the status-code. */ *pNext += SPACE_CHARACTER_LEN; - *pNext = strchr( *pNext, SPACE_CHARACTER ); /* Get the space before the reason-phrase. */ - *pNext += SPACE_CHARACTER_LEN; - pReasonPhraseStart = *pNext; - *pNext = strstr( *pNext, HTTP_HEADER_LINE_SEPARATOR ); - reasonPhraseStartLen = ( size_t ) ( *pNext - pReasonPhraseStart ); - pParser->status_code = 200; - pSettings->on_status( pParser, - pReasonPhraseStart, - reasonPhraseStartLen ); - - *pNext += HTTP_HEADER_LINE_SEPARATOR_LEN; + /* pNext points to the status code now. */ + + pReasonPhraseStart = strchr( *pNext, SPACE_CHARACTER ); + pReasonPhraseStart = &( pReasonPhraseStart[ SPACE_CHARACTER_LEN ] ); + + pNextLineStart = strstr( *pNext, HTTP_HEADER_LINE_SEPARATOR ); + pNextLineStart = &( pNextLineStart[ HTTP_HEADER_LINE_SEPARATOR_LEN ] ); + + pParser->status_code = 200; + + /* Check if the reason phrase exist in the header and call the corresponding callback. + * Reason phrase "OK" exists in the response "HTTP/1.1 200 OK\r\n". The callback + * on_status is called. + * Reason phrase doesn't exist in the response "HTTP/1.1 200\r\n". The callback + * on_status_complete is called. */ + if( pNextLineStart > pReasonPhraseStart ) + { + reasonPhraseStartLen = ( size_t ) ( pNextLineStart - pReasonPhraseStart ); + reasonPhraseStartLen = reasonPhraseStartLen - HTTP_HEADER_LINE_SEPARATOR_LEN; + pSettings->on_status( pParser, + pReasonPhraseStart, + reasonPhraseStartLen ); + *pNext = pNextLineStart; + } + else + { + statuCompleteCallbackFlag = 1; + pSettings->on_status_complete( pParser ); + *pNext = pNextLineStart; + } } /* Mock helper that parses all of the headers starting from pNext. */ @@ -805,6 +844,7 @@ void setUp( void ) response.pBuffer = httpBuffer; response.bufferLen = sizeof( httpBuffer ); response.pHeaderParsingCallback = &headerParsingCallback; + statuCompleteCallbackFlag = 0; /* Ignore third-party init functions that return void. */ llhttp_init_Ignore(); @@ -846,6 +886,41 @@ void test_HTTPClient_Send_HEAD_request_parse_whole_response( void ) /*-----------------------------------------------------------*/ +/* Test successfully parsing a response to a HEAD request. The full response + * message is present in the response buffer on the first network read. The response + * contains a status code but without a reason string. The on_status_complete is called + * in this case. */ +void test_HTTPClient_Send_HEAD_request_parse_whole_response_no_reason_string( void ) +{ + HTTPStatus_t returnStatus = HTTPSuccess; + + pNetworkData = ( uint8_t * ) HTTP_TEST_RESPONSE_HEAD_2; + networkDataLen = HTTP_TEST_RESPONSE_HEAD_2_LENGTH; + + llhttp_execute_Stub( llhttp_execute_whole_response ); + + returnStatus = HTTPClient_Send( &transportInterface, + &requestHeaders, + NULL, + 0, + &response, + 0 ); + TEST_ASSERT_EQUAL( HTTPSuccess, returnStatus ); + TEST_ASSERT_EQUAL( NULL, response.pBody ); + TEST_ASSERT_EQUAL( 0U, response.bodyLen ); + TEST_ASSERT_EQUAL( response.pBuffer + ( sizeof( HTTP_STATUS_LINE_NO_REASON_PHRASE ) - 1U ), response.pHeaders ); + TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_HEAD_2_LENGTH - ( sizeof( HTTP_STATUS_LINE_NO_REASON_PHRASE ) - 1U ) - HTTP_HEADER_END_INDICATOR_LEN, + response.headersLen ); + TEST_ASSERT_EQUAL( HTTP_STATUS_CODE_OK, response.statusCode ); + TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_HEAD_2_CONTENT_LENGTH, response.contentLength ); + TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_HEAD_2_HEADER_COUNT, response.headerCount ); + TEST_ASSERT_BITS_HIGH( HTTP_RESPONSE_CONNECTION_CLOSE_FLAG, response.respFlags ); + TEST_ASSERT_BITS_LOW( HTTP_RESPONSE_CONNECTION_KEEP_ALIVE_FLAG, response.respFlags ); + TEST_ASSERT_EQUAL( 1, statuCompleteCallbackFlag ); +} + +/*-----------------------------------------------------------*/ + /* Test successfully parsing a response to a PUT request. The full response * message is present in the response buffer on the first network read. */ void test_HTTPClient_Send_PUT_request_parse_whole_response( void ) From b4125ee6d879ca3be2c8c9c6d1ce642924b4f7a2 Mon Sep 17 00:00:00 2001 From: "Ching-Hsin,Lee" Date: Wed, 1 May 2024 15:34:49 +0000 Subject: [PATCH 2/5] Add unit test to cover more code * cover HTTP_RESPONSE_DO_NOT_PARSE_BODY_FLAG * cover HTTP_REQUEST_NO_USER_AGENT_FLAG --- test/unit-test/core_http_send_utest.c | 50 +++++++++++++++++++++++++++ test/unit-test/core_http_utest.c | 50 +++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/test/unit-test/core_http_send_utest.c b/test/unit-test/core_http_send_utest.c index 4a376ba4..5fe91dc5 100644 --- a/test/unit-test/core_http_send_utest.c +++ b/test/unit-test/core_http_send_utest.c @@ -886,6 +886,37 @@ void test_HTTPClient_Send_HEAD_request_parse_whole_response( void ) /*-----------------------------------------------------------*/ +/* Test successfully parsing a response to a HEAD request. The full response + * message is present in the response buffer on the first network read. */ +void test_HTTPClient_Send_HEAD_request_no_parse_body( void ) +{ + HTTPStatus_t returnStatus = HTTPSuccess; + + llhttp_execute_Stub( llhttp_execute_whole_response ); + + response.respOptionFlags |= HTTP_RESPONSE_DO_NOT_PARSE_BODY_FLAG; + + returnStatus = HTTPClient_Send( &transportInterface, + &requestHeaders, + NULL, + 0, + &response, + 0 ); + TEST_ASSERT_EQUAL( HTTPSuccess, returnStatus ); + TEST_ASSERT_EQUAL( NULL, response.pBody ); + TEST_ASSERT_EQUAL( 0U, response.bodyLen ); + TEST_ASSERT_EQUAL( response.pBuffer + ( sizeof( HTTP_STATUS_LINE_OK ) - 1U ), response.pHeaders ); + TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_HEAD_LENGTH - ( sizeof( HTTP_STATUS_LINE_OK ) - 1U ) - HTTP_HEADER_END_INDICATOR_LEN, + response.headersLen ); + TEST_ASSERT_EQUAL( HTTP_STATUS_CODE_OK, response.statusCode ); + TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_HEAD_CONTENT_LENGTH, response.contentLength ); + TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_HEAD_HEADER_COUNT, response.headerCount ); + TEST_ASSERT_BITS_HIGH( HTTP_RESPONSE_CONNECTION_CLOSE_FLAG, response.respFlags ); + TEST_ASSERT_BITS_LOW( HTTP_RESPONSE_CONNECTION_KEEP_ALIVE_FLAG, response.respFlags ); +} + +/*-----------------------------------------------------------*/ + /* Test successfully parsing a response to a HEAD request. The full response * message is present in the response buffer on the first network read. The response * contains a status code but without a reason string. The on_status_complete is called @@ -1832,6 +1863,25 @@ void test_HTTPClient_Send_parsing_errors( void ) 0 ); TEST_ASSERT_EQUAL( HTTPSecurityAlertInvalidContentLength, returnStatus ); + httpParsingErrno = HPE_PAUSED; + returnStatus = HTTPClient_Send( &transportInterface, + &requestHeaders, + NULL, + 0, + &response, + 0 ); + TEST_ASSERT_EQUAL( HTTPParserPaused, returnStatus ); + + httpParsingErrno = HPE_PAUSED; + response.respOptionFlags |= HTTP_RESPONSE_DO_NOT_PARSE_BODY_FLAG; + returnStatus = HTTPClient_Send( &transportInterface, + &requestHeaders, + NULL, + 0, + &response, + 0 ); + TEST_ASSERT_EQUAL( HTTPParserPaused, returnStatus ); + /* Use -1 to indicate an unknown error. */ httpParsingErrno = -1; returnStatus = HTTPClient_Send( &transportInterface, diff --git a/test/unit-test/core_http_utest.c b/test/unit-test/core_http_utest.c index ec22b1c2..dc356aaa 100644 --- a/test/unit-test/core_http_utest.c +++ b/test/unit-test/core_http_utest.c @@ -72,6 +72,10 @@ typedef struct _headers "%s: %s\r\n" \ "%s: %s\r\n\r\n" +#define HTTP_TEST_HEADER_NO_USER_AGENT_FORMAT \ + "%s %s %s\r\n" \ + "%s: %s\r\n\r\n" + #define HTTP_TEST_EXTRA_HEADER_FORMAT \ "%s %s %s\r\n" \ "%s: %s\r\n" \ @@ -94,6 +98,19 @@ typedef struct _headers HTTP_TEST_HOST_VALUE_LEN + HTTP_HEADER_LINE_SEPARATOR_LEN + \ HTTP_HEADER_LINE_SEPARATOR_LEN ) +/* Length of the following template HTTP header. + * \r\n + * : \r\n + * \r\n + * This is used to initialize the expectedHeader string. */ +#define HTTP_TEST_PREFIX_HEADER_NO_USER_AGENT_LEN \ + ( HTTP_METHOD_GET_LEN + SPACE_CHARACTER_LEN + \ + HTTP_TEST_REQUEST_PATH_LEN + SPACE_CHARACTER_LEN + \ + HTTP_PROTOCOL_VERSION_LEN + HTTP_HEADER_LINE_SEPARATOR_LEN + \ + HTTP_HOST_FIELD_LEN + HTTP_HEADER_FIELD_SEPARATOR_LEN + \ + HTTP_TEST_HOST_VALUE_LEN + HTTP_HEADER_LINE_SEPARATOR_LEN + \ + HTTP_HEADER_LINE_SEPARATOR_LEN ) + /* Add 1 because snprintf(...) writes a null byte at the end. */ #define HTTP_TEST_INITIALIZED_HEADER_BUFFER_LEN \ ( HTTP_TEST_PREFIX_HEADER_LEN + 1 ) @@ -472,6 +489,39 @@ void test_Http_InitializeRequestHeaders_Happy_Path() expectedHeaders.dataLen ); } +/** + * @brief Test happy path with HTTP_REQUEST_NO_USER_AGENT_FLAG. + */ +void test_Http_InitializeRequestHeaders_no_user_agent_flag() +{ + HTTPStatus_t httpStatus = HTTPSuccess; + HTTPRequestHeaders_t requestHeaders = { 0 }; + HTTPRequestInfo_t requestInfo = { 0 }; + int numBytes = 0; + + setupRequestInfo( &requestInfo ); + requestInfo.reqFlags |= HTTP_REQUEST_NO_USER_AGENT_FLAG; + + expectedHeaders.dataLen = HTTP_TEST_PREFIX_HEADER_NO_USER_AGENT_LEN; + setupBuffer( &requestHeaders ); + + /* Happy Path testing. */ + numBytes = snprintf( ( char * ) expectedHeaders.buffer, sizeof( expectedHeaders.buffer ), + HTTP_TEST_HEADER_NO_USER_AGENT_FORMAT, + HTTP_METHOD_GET, HTTP_TEST_REQUEST_PATH, + HTTP_PROTOCOL_VERSION, + HTTP_HOST_FIELD, HTTP_TEST_HOST_VALUE ); + /* Make sure that the entire pre-existing data was printed to the buffer. */ + TEST_ASSERT_GREATER_THAN( 0, numBytes ); + TEST_ASSERT_LESS_THAN( sizeof( expectedHeaders.buffer ), ( size_t ) numBytes ); + + httpStatus = HTTPClient_InitializeRequestHeaders( &requestHeaders, &requestInfo ); + TEST_ASSERT_EQUAL( HTTPSuccess, httpStatus ); + TEST_ASSERT_EQUAL( expectedHeaders.dataLen, requestHeaders.headersLen ); + TEST_ASSERT_EQUAL_MEMORY( expectedHeaders.buffer, requestHeaders.pBuffer, + expectedHeaders.dataLen ); +} + /** * @brief Test NULL parameters, following order of else-if blocks in the HTTP library. */ From abd856b5153ba2ac6548526c994e992f9bb2c9ea Mon Sep 17 00:00:00 2001 From: "Ching-Hsin,Lee" Date: Wed, 1 May 2024 15:36:56 +0000 Subject: [PATCH 3/5] Fix uncrusitfy --- test/unit-test/core_http_send_utest.c | 52 +++++++++++++-------------- test/unit-test/core_http_utest.c | 12 +++---- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/test/unit-test/core_http_send_utest.c b/test/unit-test/core_http_send_utest.c index 5fe91dc5..f8512a01 100644 --- a/test/unit-test/core_http_send_utest.c +++ b/test/unit-test/core_http_send_utest.c @@ -104,11 +104,11 @@ HTTP_TEST_VARY_HEADER_LINE \ HTTP_TEST_P3P_HEADER_LINE \ HTTP_TEST_XSERVER_HEADER_LINE HTTP_HEADER_LINE_SEPARATOR -#define HTTP_TEST_RESPONSE_HEAD_LENGTH ( sizeof( HTTP_TEST_RESPONSE_HEAD ) - 1U ) -#define HTTP_TEST_RESPONSE_HEAD_HEADER_COUNT 7 -#define HTTP_TEST_RESPONSE_HEAD_CONTENT_LENGTH 43 -#define HTTP_TEST_RESPONSE_HEAD_PARTIAL_HEADER_FIELD_LENGTH ( sizeof( HTTP_STATUS_LINE_OK ) + sizeof( HTTP_TEST_CONTENT_LENGTH_PARTIAL_HEADER_FIELD ) - 2U ) -#define HTTP_TEST_RESPONSE_HEAD_PARTIAL_HEADER_VALUE_LENGTH ( sizeof( HTTP_STATUS_LINE_OK ) + sizeof( HTTP_TEST_CONTENT_LENGTH_PARTIAL_HEADER_VALUE ) - 2U ) +#define HTTP_TEST_RESPONSE_HEAD_LENGTH ( sizeof( HTTP_TEST_RESPONSE_HEAD ) - 1U ) +#define HTTP_TEST_RESPONSE_HEAD_HEADER_COUNT 7 +#define HTTP_TEST_RESPONSE_HEAD_CONTENT_LENGTH 43 +#define HTTP_TEST_RESPONSE_HEAD_PARTIAL_HEADER_FIELD_LENGTH ( sizeof( HTTP_STATUS_LINE_OK ) + sizeof( HTTP_TEST_CONTENT_LENGTH_PARTIAL_HEADER_FIELD ) - 2U ) +#define HTTP_TEST_RESPONSE_HEAD_PARTIAL_HEADER_VALUE_LENGTH ( sizeof( HTTP_STATUS_LINE_OK ) + sizeof( HTTP_TEST_CONTENT_LENGTH_PARTIAL_HEADER_VALUE ) - 2U ) #define HTTP_TEST_RESPONSE_HEAD_2 \ HTTP_STATUS_LINE_NO_REASON_PHRASE \ @@ -460,36 +460,36 @@ static void helper_parse_status_line( const char ** pNext, * always string literals. strchr() should not be used in application code. */ *pNext = strchr( *pNext, SPACE_CHARACTER ); /* Get the space before the status-code. */ *pNext += SPACE_CHARACTER_LEN; - /* pNext points to the status code now. */ + /* pNext points to the status code now. */ - pReasonPhraseStart = strchr( *pNext, SPACE_CHARACTER ); - pReasonPhraseStart = &( pReasonPhraseStart[ SPACE_CHARACTER_LEN ] ); + pReasonPhraseStart = strchr( *pNext, SPACE_CHARACTER ); + pReasonPhraseStart = &( pReasonPhraseStart[ SPACE_CHARACTER_LEN ] ); - pNextLineStart = strstr( *pNext, HTTP_HEADER_LINE_SEPARATOR ); - pNextLineStart = &( pNextLineStart[ HTTP_HEADER_LINE_SEPARATOR_LEN ] ); + pNextLineStart = strstr( *pNext, HTTP_HEADER_LINE_SEPARATOR ); + pNextLineStart = &( pNextLineStart[ HTTP_HEADER_LINE_SEPARATOR_LEN ] ); - pParser->status_code = 200; + pParser->status_code = 200; /* Check if the reason phrase exist in the header and call the corresponding callback. * Reason phrase "OK" exists in the response "HTTP/1.1 200 OK\r\n". The callback * on_status is called. * Reason phrase doesn't exist in the response "HTTP/1.1 200\r\n". The callback * on_status_complete is called. */ - if( pNextLineStart > pReasonPhraseStart ) - { - reasonPhraseStartLen = ( size_t ) ( pNextLineStart - pReasonPhraseStart ); + if( pNextLineStart > pReasonPhraseStart ) + { + reasonPhraseStartLen = ( size_t ) ( pNextLineStart - pReasonPhraseStart ); reasonPhraseStartLen = reasonPhraseStartLen - HTTP_HEADER_LINE_SEPARATOR_LEN; - pSettings->on_status( pParser, - pReasonPhraseStart, - reasonPhraseStartLen ); - *pNext = pNextLineStart; - } - else - { + pSettings->on_status( pParser, + pReasonPhraseStart, + reasonPhraseStartLen ); + *pNext = pNextLineStart; + } + else + { statuCompleteCallbackFlag = 1; - pSettings->on_status_complete( pParser ); - *pNext = pNextLineStart; - } + pSettings->on_status_complete( pParser ); + *pNext = pNextLineStart; + } } /* Mock helper that parses all of the headers starting from pNext. */ @@ -893,7 +893,7 @@ void test_HTTPClient_Send_HEAD_request_no_parse_body( void ) HTTPStatus_t returnStatus = HTTPSuccess; llhttp_execute_Stub( llhttp_execute_whole_response ); - + response.respOptionFlags |= HTTP_RESPONSE_DO_NOT_PARSE_BODY_FLAG; returnStatus = HTTPClient_Send( &transportInterface, @@ -1871,7 +1871,7 @@ void test_HTTPClient_Send_parsing_errors( void ) &response, 0 ); TEST_ASSERT_EQUAL( HTTPParserPaused, returnStatus ); - + httpParsingErrno = HPE_PAUSED; response.respOptionFlags |= HTTP_RESPONSE_DO_NOT_PARSE_BODY_FLAG; returnStatus = HTTPClient_Send( &transportInterface, diff --git a/test/unit-test/core_http_utest.c b/test/unit-test/core_http_utest.c index dc356aaa..e6b4fd14 100644 --- a/test/unit-test/core_http_utest.c +++ b/test/unit-test/core_http_utest.c @@ -103,12 +103,12 @@ typedef struct _headers * : \r\n * \r\n * This is used to initialize the expectedHeader string. */ -#define HTTP_TEST_PREFIX_HEADER_NO_USER_AGENT_LEN \ - ( HTTP_METHOD_GET_LEN + SPACE_CHARACTER_LEN + \ - HTTP_TEST_REQUEST_PATH_LEN + SPACE_CHARACTER_LEN + \ - HTTP_PROTOCOL_VERSION_LEN + HTTP_HEADER_LINE_SEPARATOR_LEN + \ - HTTP_HOST_FIELD_LEN + HTTP_HEADER_FIELD_SEPARATOR_LEN + \ - HTTP_TEST_HOST_VALUE_LEN + HTTP_HEADER_LINE_SEPARATOR_LEN + \ +#define HTTP_TEST_PREFIX_HEADER_NO_USER_AGENT_LEN \ + ( HTTP_METHOD_GET_LEN + SPACE_CHARACTER_LEN + \ + HTTP_TEST_REQUEST_PATH_LEN + SPACE_CHARACTER_LEN + \ + HTTP_PROTOCOL_VERSION_LEN + HTTP_HEADER_LINE_SEPARATOR_LEN + \ + HTTP_HOST_FIELD_LEN + HTTP_HEADER_FIELD_SEPARATOR_LEN + \ + HTTP_TEST_HOST_VALUE_LEN + HTTP_HEADER_LINE_SEPARATOR_LEN + \ HTTP_HEADER_LINE_SEPARATOR_LEN ) /* Add 1 because snprintf(...) writes a null byte at the end. */ From c1a570f3e3f6c618e2a5d2670c3e0ba60c1f189d Mon Sep 17 00:00:00 2001 From: "Ching-Hsin,Lee" Date: Wed, 1 May 2024 15:40:19 +0000 Subject: [PATCH 4/5] Enforce 100 percent coverage --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1444471d..746af97e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,8 @@ jobs: uses: FreeRTOS/CI-CD-Github-Actions/coverage-cop@main with: coverage-file: ./build/coverage.info + branch-coverage-min: 100 + line-coverage-min: 100 complexity: runs-on: ubuntu-latest From 4e1b74869efe67b96c1f7254421506d2d3c4cc83 Mon Sep 17 00:00:00 2001 From: "Ching-Hsin,Lee" Date: Wed, 1 May 2024 15:50:04 +0000 Subject: [PATCH 5/5] Fix unit test and spelling --- test/unit-test/core_http_send_utest.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unit-test/core_http_send_utest.c b/test/unit-test/core_http_send_utest.c index f8512a01..db83af52 100644 --- a/test/unit-test/core_http_send_utest.c +++ b/test/unit-test/core_http_send_utest.c @@ -252,7 +252,7 @@ static HTTPRequestHeaders_t requestHeaders = { 0 }; static HTTPClient_ResponseHeaderParsingCallback_t headerParsingCallback = { 0 }; /* Flag to indicate this callback is called. */ -static int statuCompleteCallbackFlag = 0; +static int statusCompleteCallbackFlag = 0; /* A mocked timer query function that increments on every call. */ static uint32_t getTestTime( void ) @@ -486,7 +486,7 @@ static void helper_parse_status_line( const char ** pNext, } else { - statuCompleteCallbackFlag = 1; + statusCompleteCallbackFlag = 1; pSettings->on_status_complete( pParser ); *pNext = pNextLineStart; } @@ -844,7 +844,7 @@ void setUp( void ) response.pBuffer = httpBuffer; response.bufferLen = sizeof( httpBuffer ); response.pHeaderParsingCallback = &headerParsingCallback; - statuCompleteCallbackFlag = 0; + statusCompleteCallbackFlag = 0; /* Ignore third-party init functions that return void. */ llhttp_init_Ignore(); @@ -947,7 +947,7 @@ void test_HTTPClient_Send_HEAD_request_parse_whole_response_no_reason_string( vo TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_HEAD_2_HEADER_COUNT, response.headerCount ); TEST_ASSERT_BITS_HIGH( HTTP_RESPONSE_CONNECTION_CLOSE_FLAG, response.respFlags ); TEST_ASSERT_BITS_LOW( HTTP_RESPONSE_CONNECTION_KEEP_ALIVE_FLAG, response.respFlags ); - TEST_ASSERT_EQUAL( 1, statuCompleteCallbackFlag ); + TEST_ASSERT_EQUAL( 1, statusCompleteCallbackFlag ); } /*-----------------------------------------------------------*/ @@ -1880,7 +1880,7 @@ void test_HTTPClient_Send_parsing_errors( void ) 0, &response, 0 ); - TEST_ASSERT_EQUAL( HTTPParserPaused, returnStatus ); + TEST_ASSERT_EQUAL( HTTPNoResponse, returnStatus ); /* Use -1 to indicate an unknown error. */ httpParsingErrno = -1;