Skip to content

Commit

Permalink
100% coverage again
Browse files Browse the repository at this point in the history
  • Loading branch information
aggarw13 committed Aug 14, 2021
1 parent 26b26bd commit 6c04aba
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion source/sigv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -2030,7 +2030,7 @@ static void generateCredentialScope( const SigV4Parameters_t * pSigV4Params,

returnStatus = setQueryStringFieldsAndValues( pQuery, queryLen, &numberOfParameters, pCanonicalContext );

if( returnStatus == SigV4Success )
if( ( returnStatus == SigV4Success ) && ( numberOfParameters > 0U ) )
{
/* Sort the parameter names by character code point in ascending order.
* Parameters with duplicate names should be sorted by value. */
Expand Down
10 changes: 6 additions & 4 deletions source/sigv4_quicksort.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ void quickSort( void * pArray,
size_t itemSize,
ComparisonFunc_t comparator )
{
if( ( numItems != 0U ) && ( pArray != NULL ) )
{
quickSortHelper( pArray, 0U, numItems - 1U, itemSize, comparator );
}
assert( pArray != NULL );
assert( numItems > 0U );
assert( itemSize > 0U );
assert( comparator != NULL );

quickSortHelper( pArray, 0U, numItems - 1U, itemSize, comparator );
}
2 changes: 1 addition & 1 deletion test/unit-test/sigv4_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
* <b>Default value:</b> `100`
*/
#ifndef SIGV4_MAX_HTTP_HEADER_COUNT
#define SIGV4_MAX_HTTP_HEADER_COUNT 5U
#define SIGV4_MAX_HTTP_HEADER_COUNT 7U
#endif

/**
Expand Down
25 changes: 23 additions & 2 deletions test/unit-test/sigv4_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,18 @@
#define HEADERS_WITH_TRIMMABLE_SPACES " Header-1 : Value \t - \t 1 \r\n"

/* Examples with more header pairs than SIGV4_MAX_HTTP_HEADER_COUNT=5. */
#define PRECAN_HEADERS_PAIRS_GT_THAN_MAX "H1:a\nH2:b\nH3:c\nH4:d\nH5:e\nH6:\n"
#define HEADERS_PAIRS_GT_THAN_MAX "H1:a\r\nH2:b\r\nH3:c\r\nH4:d\r\nH5:e\r\nH6:\r\n\r\n"
#define PRECAN_HEADERS_PAIRS_GT_THAN_MAX "H1:a\nH2:b\nH3:c\nH4:d\nH5:e\nH6:\nH7:\nH8:\n"
#define HEADERS_PAIRS_GT_THAN_MAX "H1:a\r\nH2:b\r\nH3:c\r\nH4:d\r\nH5:e\r\nH6:\r\nH7:\r\n:H8:\r\n\r\n"

/* Examples of invalid HTTP headers data. */
#define INVALID_HEADERS_NO_HEADER_VAL "Header1: Value1\r\nHeader2: Value2\n"
#define INVALID_HEADERS_NO_HEADER_KEY "Header=Value\r\n"
#define INVALID_PRECANON_HEADERS_NO_HEADER_KEY "Header=Value\n"

#define HEADERS_SORTED_COVERAGE_1 "A:a\r\nB:b\r\nC:c\r\nE:e\r\nF:f\r\nD:d\r\n\r\n"
#define HEADERS_SORTED_COVERAGE_2 "A:a\r\nC:c\r\nE:e\r\nF:f\r\nD:d\r\n\r\n"


#define STRING_TO_SIGN_LEN_WITH_DEFAULT_REGION \
SIGV4_AWS4_HMAC_SHA256_LENGTH + 1U + \
SIGV4_ISO_STRING_LEN + 1U + \
Expand Down Expand Up @@ -1233,3 +1237,20 @@ void test_SigV4_GenerateAuthorization_Headers_Greater_Than_Configured_Max()
TEST_ASSERT_EQUAL( SigV4MaxHeaderPairCountExceeded, SigV4_GenerateHTTPAuthorization(
&params, authBuf, &authBufLen, &signature, &signatureLen ) );
}

void test_SigV4_GenerateAuthorization_Sorting_Algorithm_Coverage()
{
params.pHttpParameters->pHeaders = HEADERS_SORTED_COVERAGE_1;
params.pHttpParameters->headersLen = strlen( HEADERS_SORTED_COVERAGE_1 );
TEST_ASSERT_EQUAL( SigV4Success, SigV4_GenerateHTTPAuthorization(
&params, authBuf, &authBufLen, &signature, &signatureLen ) );

params.pHttpParameters->pPath = NULL;
params.pHttpParameters->pathLen = 0U;
params.pHttpParameters->pQuery = NULL;
params.pHttpParameters->queryLen = 0U;
params.pHttpParameters->pHeaders = HEADERS_SORTED_COVERAGE_2;
params.pHttpParameters->headersLen = strlen( HEADERS_SORTED_COVERAGE_2 );
TEST_ASSERT_EQUAL( SigV4Success, SigV4_GenerateHTTPAuthorization(
&params, authBuf, &authBufLen, &signature, &signatureLen ) );
}

0 comments on commit 6c04aba

Please sign in to comment.