Skip to content

Commit 59a536a

Browse files
committed
Add final missing test
1 parent 578e0a2 commit 59a536a

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

test/unit-test/core_http_send_utest.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,34 @@ static llhttp_errno_t llhttp_execute_error( llhttp_t * pParser,
445445
return httpParsingErrno;
446446
}
447447

448+
/* Mocked llhttp_execute callback that parses the status line, then invokes
449+
* on_header_field with a zero-length field name to exercise the early return
450+
* guard in httpParserOnHeaderFieldCallback. */
451+
static llhttp_errno_t llhttp_execute_zero_length_header_field( llhttp_t * pParser,
452+
const char * pData,
453+
size_t len,
454+
int cmock_num_calls )
455+
{
456+
( void ) cmock_num_calls;
457+
( void ) len;
458+
const char * pNext = pData;
459+
llhttp_settings_t * pSettings = ( llhttp_settings_t * ) pParser->settings;
460+
int cbReturnValue = 0;
461+
462+
pSettings->on_message_begin( pParser );
463+
helper_parse_status_line( &pNext, pParser, pSettings );
464+
465+
/* Invoke on_header_field with length zero. The real callback should return
466+
* LLHTTP_STOP_PARSING. */
467+
cbReturnValue = pSettings->on_header_field( pParser, pNext, 0 );
468+
TEST_ASSERT_EQUAL( LLHTTP_STOP_PARSING, cbReturnValue );
469+
470+
pParser->error = HPE_USER;
471+
httpParserExecuteCallCount++;
472+
return HPE_USER;
473+
}
474+
475+
448476
/* Mock helper that parses the status line starting from pNext. */
449477
static void helper_parse_status_line( const char ** pNext,
450478
llhttp_t * pParser,
@@ -1960,3 +1988,23 @@ void test_HTTPClient_Send_parsing_errors( void )
19601988
0 );
19611989
TEST_ASSERT_EQUAL( HTTPParserInternalError, returnStatus );
19621990
}
1991+
1992+
/* Test that httpParserOnHeaderFieldCallback returns LLHTTP_STOP_PARSING when
1993+
* the parser invokes it with a zero-length header field name (lines 720-724
1994+
* of core_http_client.c). */
1995+
void test_HTTPClient_Send_zero_length_header_field( void )
1996+
{
1997+
HTTPStatus_t returnStatus = HTTPSuccess;
1998+
1999+
llhttp_execute_Stub( llhttp_execute_zero_length_header_field );
2000+
2001+
returnStatus = HTTPClient_Send( &transportInterface,
2002+
&requestHeaders,
2003+
NULL,
2004+
0,
2005+
&response,
2006+
0 );
2007+
/* HPE_USER falls through to the default case in processLlhttpError,
2008+
* which maps to HTTPParserInternalError. */
2009+
TEST_ASSERT_EQUAL( HTTPParserInternalError, returnStatus );
2010+
}

0 commit comments

Comments
 (0)