FreeRTOS: HTTPS Client
HTTPS Client v1.0.0 library
Return to main page ↑
iot_tests_https_sync.c File Reference

Tests for IotHttpsClient_SendSync() in iot_https_client.h. More...

Macros

#define HTTPS_TEST_SYNC_TIMEOUT_MS   ( ( uint32_t ) 30000 )
 Timeout for IotHttpsClient_SendSync() for all tests.
 
#define HTTPS_TEST_NETWORK_RECEIVE_CALLBACK_WAIT_MS   ( ( uint32_t ) 300 )
 Wait time before the network receive callback is invoked. More...
 
#define HTTPS_TEST_SMALL_RESPONSE_UP_TO_CARRIAGE_RETURN   "HTTP/1.1 200 OK\r\nheader0: value0\r\nheader1: value1\r"
 A test response from the network that goes up to a carriage return in the HTTP response headers. More...
 
#define HTTPS_TEST_SMALL_RESPONSE_UP_TO_NEWLINE   "HTTP/1.1 200 OK\r\nheader0: value0\r\nheader1: value1\r\n"
 A test response from the network that goes up to a newline in the HTTP response headers.

 
#define HTTPS_TEST_SMALL_RESPONSE_UP_TO_COLON   "HTTP/1.1 200 OK\r\nheader0: value0\r\nheader1:"
 A test response from the network that goes up to a colon in the HTTP response headers.
 
#define HTTPS_TEST_SMALL_RESPONSE_UP_TO_SPACE   "HTTP/1.1 200 OK\r\nheader0: value0\r\nheader1: "
 A test response from the network that goes up to the space after a colon in the HTTP response headers.
 
#define HTTPS_TEST_SMALL_RESPONSE_UP_TO_SPACE_IN_BETWEEN_VALUE    "HTTP/1.1 200 OK\r\nheader0: value0\r\nheader1: value1\r\nheader2: value2 "
 A test response from the network that goes up to the space that is after a header value in the HTTP response headers.
 
#define HTTPS_TEST_HEADER1   "header1"
 The string literal for a header field named "header1". This is for test result checking.
 
#define HTTPS_TEST_HEADER1_PLUS_COLON   "header1:"
 The string literal for a header field named "header1" including the colon after.
 
#define HTTPS_TEST_HEADER1_PLUS_SPACE   "header1: "
 The string literal for a header field named "header1" including the colon and space after.
 
#define HTTPS_TEST_HEADER2   "header2"
 The string literal for a header field named "header2". This is for test result checking.
 
#define HTTPS_TEST_HEADER_VALUE1   "value1"
 The string literal for a header value named "value1".
 
#define HTTPS_TEST_HEADER_VALUE2_PLUS_SPACE   "value2 "
 The string literal for a header value named "value2.".
 
#define HTTPS_TEST_HEADER_VALUE2_VALUE2A   "value2 value2a"
 The string literal a header value that contains two strings separated by a space.
 
#define HTTPS_TEST_HEADER_VALUE1_PLUS_CARRIAGE_RETURN   "value1\r"
 the string literal for a header value with the carriage return following it.
 
#define HTTPS_TEST_HEADER_VALUE1_PLUS_NEWLINE   "value1\r\n"
 the string ltieral for a header value with the carriage return and newline following it.
 

Functions

static void _invokeNetworkReceiveCallback (void *pArgument)
 thread that invokes the _networkReceiveCallback internal to the library.
 
static size_t _httpParserExecuteFailHeaders (http_parser *parser, const http_parser_settings *settings, const char *data, size_t len)
 Mock the http parser execution failing when parsing the HTTP headers buffer.
 
static size_t _httpParserExecuteFailBody (http_parser *parser, const http_parser_settings *settings, const char *data, size_t len)
 Mock the http parser execution failing when parsing the HTTP body buffer.
 
static size_t _networkSendFailHeaders (void *pConnection, const uint8_t *pMessage, size_t messageLength)
 Network abstraction send function that fails sending the HTTP headers.
 
static size_t _networkSendFailBody (void *pConnection, const uint8_t *pMessage, size_t messageLength)
 Network abstraction send function that fails sending the HTTP body.
 
static size_t _networkSendSuccess (void *pConnection, const uint8_t *pMessage, size_t messageLength)
 Network abstraction send function that succeeds. More...
 
static size_t _networkReceiveFailHeaders (void *pConnection, uint8_t *pBuffer, size_t bytesRequested)
 Network abstraction receive function that fails when sending the HTTP headers.
 
static size_t _networkReceiveFailBody (void *pConnection, uint8_t *pBuffer, size_t bytesRequested)
 Network abstraction receive function that fails when sending the HTTP body.
 
static size_t _networkSendSuccessWithSettingParseFailForHeaders (void *pConnection, const uint8_t *pMessage, size_t messageLength)
 Network send success that replaces the _httpsResponse_t.httpParserInfo.parseFunc with one from this test. More...
 
static size_t _networkSendSuccessWithSettingParseFailForBody (void *pConnection, const uint8_t *pMessage, size_t messageLength)
 Network send success that replaces the _httpsResponse_t.httpParserInfo.parseFunc with one from this test. More...
 
 TEST_GROUP (HTTPS_Client_Unit_Sync)
 Test group for HTTPS Client Sync Unit tests.
 
 TEST_SETUP (HTTPS_Client_Unit_Sync)
 Test setup for HTTPS Client Sync Unit tests.
 
 TEST_TEAR_DOWN (HTTPS_Client_Unit_Sync)
 Test tear down for HTTPS Client Sync Unit tests..
 
 TEST_GROUP_RUNNER (HTTPS_Client_Unit_Sync)
 Test group runner for HTTPS Client IotHttpsClient_SendSync.
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncInvalidParameters)
 Test various invalid parameters input into IotHttpsClient_SendSync().
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncFailureSendingHeaders)
 Test failures to send over the network the request headers.
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncFailureSendingBody)
 Test failures to send over the network the request body.
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncFailureReceivingHeaders)
 Test failures to receive over the network the response headers.
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncFailureReceivingBody)
 Test failures to receive over the network response body.
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncFailureParsingHeaders)
 Test failure to parse over the network the response headers.
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncFailureParsingBody)
 Test failure to parse over the network the response body.
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncSomeBodyInHeaderBuffer)
 Test that we receive the HTTP response body correctly when part of it is network received into the header buffer.
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncSomeHeaderInBodyBuffer)
 Test that we receive the HTTP response body correctly when network received headers spill over into the body buffer.
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncEntireResponseInHeaderBuffer)
 Test that we receive the HTTP response body correctly all of the body is network received into the header buffer.
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncBodyTooLarge)
 Test that we return the correct error code when the HTTP response body is too large to fit into the configured body buffer.
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncBodyBufferNull)
 Test a successful synchronous workflow when the body buffer is configured as NULL, but HTTP response body is received on the network.
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncPersistentRequest)
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncNonPersistentRequest)
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncHeadersEndsWithCarriageReturnSeparator)
 Test that we have the correct header data when it ends on the carriage return of the end of the header lines separator. More...
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncHeadersEndsWithNewlineSeparator)
 Test that we have the correct header data when it ends on the newline of the end of the header lines separator. More...
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncHeadersEndsWithColonSeparator)
 Test that we have the correct header data when it ends on the colon character of the header field value separator. More...
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncHeadersEndsWithSpaceSeparator)
 Test that we have the correct header data when it ends on the space character of the header field value separator. More...
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncHeadersEndsWithSpaceAfterHeaderValue)
 
 TEST (HTTPS_Client_Unit_Sync, SendSyncChunkedResponse)
 Test receiving a chunked HTTP response message.
 

Variables

static IotHttpsConnectionHandle_t _receiveCallbackConnHandle = IOT_HTTPS_CONNECTION_HANDLE_INITIALIZER
 The connection handle that is needed by tests that are testing a workflow that involves receiving data on the network. More...
 
static bool _alreadyCreatedReceiveCallbackThread = false
 Flag indicating that the _invokeNetworkReceiveCallback task was already created. More...
 
static IotHttpsRequestHandle_t _currentlySendingRequestHandle = IOT_HTTPS_REQUEST_HANDLE_INITIALIZER
 The request handle that is currently being serviced in the current tests network receive callback. More...
 
static IotHttpsSyncInfo_t _syncRequestInfo
 A IotHttpsSyncInfo_t for requests to share among the tests. More...
 
static IotHttpsSyncInfo_t _syncResponseInfo
 A IotHttpsSyncInfo_t for responses to share among the tests. More...
 
static IotHttpsRequestInfo_t _reqInfo
 A IotHttpsRequestInfo_t to share among the tests. More...
 
static IotHttpsResponseInfo_t _respInfo
 A IotHttpsResponseInfo_t to share among the tests. More...
 

Detailed Description

Macro Definition Documentation

◆ HTTPS_TEST_NETWORK_RECEIVE_CALLBACK_WAIT_MS

#define HTTPS_TEST_NETWORK_RECEIVE_CALLBACK_WAIT_MS   ( ( uint32_t ) 300 )

Wait time before the network receive callback is invoked.

This wait time is to mimic not only response being received on the network, but also needs to incorporate the time it takes to complete sending the request.

◆ HTTPS_TEST_SMALL_RESPONSE_UP_TO_CARRIAGE_RETURN

#define HTTPS_TEST_SMALL_RESPONSE_UP_TO_CARRIAGE_RETURN   "HTTP/1.1 200 OK\r\nheader0: value0\r\nheader1: value1\r"

A test response from the network that goes up to a carriage return in the HTTP response headers.

Definitions for part of the small HTTP test response.

Theser are used to verify behavior when the header buffer ends with just a part of the HTTP response headers.

Function Documentation

◆ _networkSendSuccess()

static size_t _networkSendSuccess ( void *  pConnection,
const uint8_t *  pMessage,
size_t  messageLength 
)
static

Network abstraction send function that succeeds.

Because the network send succeeded we mimic the network by starting a thread to envoke the network receive callback.

◆ _networkSendSuccessWithSettingParseFailForHeaders()

static size_t _networkSendSuccessWithSettingParseFailForHeaders ( void *  pConnection,
const uint8_t *  pMessage,
size_t  messageLength 
)
static

Network send success that replaces the _httpsResponse_t.httpParserInfo.parseFunc with one from this test.

This function relies on _httpsResponse_t.pHttpsResponse getting set, in the currently processing _httpsResponse_t, before the network send function is called.

◆ _networkSendSuccessWithSettingParseFailForBody()

static size_t _networkSendSuccessWithSettingParseFailForBody ( void *  pConnection,
const uint8_t *  pMessage,
size_t  messageLength 
)
static

Network send success that replaces the _httpsResponse_t.httpParserInfo.parseFunc with one from this test.

This function relies on _httpsResponse_t.pHttpsResponse getting set, in the currently processing _httpsResponse_t, before the network send function is called.

◆ TEST() [1/7]

TEST ( HTTPS_Client_Unit_Sync  ,
SendSyncPersistentRequest   
)

Test for a successful synchronous workflow that the connection stays open when the request is persistent.

◆ TEST() [2/7]

TEST ( HTTPS_Client_Unit_Sync  ,
SendSyncNonPersistentRequest   
)

Test for a successful synchronous workflow that the connection closes when the request is non-persistent.

◆ TEST() [3/7]

TEST ( HTTPS_Client_Unit_Sync  ,
SendSyncHeadersEndsWithCarriageReturnSeparator   
)

Test that we have the correct header data when it ends on the carriage return of the end of the header lines separator.

The end of the header lines separator is "\r\n". This test is important because it makes sure that the pHeaderCur pointer in the internal response context is updated even though the http-parser callback does not notify the library of these characters.

These tests are separated into difference cases so that I can easily free the memory allocated.

◆ TEST() [4/7]

TEST ( HTTPS_Client_Unit_Sync  ,
SendSyncHeadersEndsWithNewlineSeparator   
)

Test that we have the correct header data when it ends on the newline of the end of the header lines separator.

The end of the header lines separator is "\r\n". This test is important because it makes sure that the pHeaderCur pointer in the internal response context is updated even though the http-parser callback does not notify the library of these characters.

These tests are separated into difference cases so that I can easily free the memory allocated.

◆ TEST() [5/7]

TEST ( HTTPS_Client_Unit_Sync  ,
SendSyncHeadersEndsWithColonSeparator   
)

Test that we have the correct header data when it ends on the colon character of the header field value separator.

The header field value separator is ": ". This test is important because it makes sure that the pHeaderCur pointer in the internal response context is updated even though the http-parser callback does not notify the library of these characters.

These tests are separated into difference cases so that I can easily free the memory allocated.

◆ TEST() [6/7]

TEST ( HTTPS_Client_Unit_Sync  ,
SendSyncHeadersEndsWithSpaceSeparator   
)

Test that we have the correct header data when it ends on the space character of the header field value separator.

The header field value separator is ": ". This test is important because it makes sure that the pHeaderCur pointer in the internal response context is updated even though the http-parser callback does not notify the library of these characters.

These tests are separated into difference cases so that I can easily free the memory allocated.

◆ TEST() [7/7]

TEST ( HTTPS_Client_Unit_Sync  ,
SendSyncHeadersEndsWithSpaceAfterHeaderValue   
)

Test that when the header buffer ends on a space after a header value that this space is treated as parted of the header value.

Variable Documentation

◆ _receiveCallbackConnHandle

The connection handle that is needed by tests that are testing a workflow that involves receiving data on the network.

HTTP tests run sequentially, so there is no race condition here.

◆ _alreadyCreatedReceiveCallbackThread

bool _alreadyCreatedReceiveCallbackThread = false
static

Flag indicating that the _invokeNetworkReceiveCallback task was already created.

This is reset to false before each test. This is set during tests that are testing a workflow that involes receiving data on the network.

We do not want to create two tasks that invoke the network receive callback. That is incorrect behavior of the network receive callback.

HTTP tests run sequentially, so there is no race condition here.

This is used for tests sending and receiving one response.

◆ _currentlySendingRequestHandle

IotHttpsRequestHandle_t _currentlySendingRequestHandle = IOT_HTTPS_REQUEST_HANDLE_INITIALIZER
static

The request handle that is currently being serviced in the current tests network receive callback.

This is needed to replace the parseFunc, in the corresponding response, with a unit test mock. This is needed to check if the network receive or network send buffer is the start of the header or the body buffers to get proper failure coverage. This is needed to check if the network receive buffer is the start of the header buffer, so that we can receive part of the response.

◆ _syncRequestInfo

IotHttpsSyncInfo_t _syncRequestInfo
static
Initial value:
=
{
.pBody = ( uint8_t * ) ( HTTPS_TEST_REQUEST_BODY ),
}

A IotHttpsSyncInfo_t for requests to share among the tests.

IotHttpsSyncInfo_t for requests and response to share among the tests.

Even though the method is a GET method for the test _reqInfo, we apply a request body for unit testing purposes. A request body is allowed for a GET method according to the HTTP specification, although it is pointless in practice.

◆ _syncResponseInfo

IotHttpsSyncInfo_t _syncResponseInfo
static
Initial value:
=
{
.pBody = _pRespBodyBuffer,
.bodyLen = sizeof( _pRespBodyBuffer )
}

A IotHttpsSyncInfo_t for responses to share among the tests.

◆ _reqInfo

IotHttpsRequestInfo_t _reqInfo
static
Initial value:
=
{
.pPath = HTTPS_TEST_PATH,
.pathLen = sizeof( HTTPS_TEST_PATH ) - 1,
.method = IOT_HTTPS_METHOD_GET,
.hostLen = sizeof( HTTPS_TEST_ADDRESS ) - 1,
.isNonPersistent = false,
.userBuffer.pBuffer = _pReqUserBuffer,
.userBuffer.bufferLen = sizeof( _pReqUserBuffer ),
.isAsync = false,
.u.pSyncInfo = &_syncRequestInfo
}

A IotHttpsRequestInfo_t to share among the tests.

◆ _respInfo

IotHttpsResponseInfo_t _respInfo
static
Initial value:
=
{
.userBuffer.pBuffer = _pRespUserBuffer,
.userBuffer.bufferLen = sizeof( _pRespUserBuffer ),
.pSyncInfo = &_syncResponseInfo
}

A IotHttpsResponseInfo_t to share among the tests.

HTTPS_TEST_REQUEST_BODY
#define HTTPS_TEST_REQUEST_BODY
Test HTTP request body to share among the tests.
Definition: iot_tests_https_common.h:142
HTTPS_TEST_PATH
#define HTTPS_TEST_PATH
Test path to share among the tests.
Definition: iot_tests_https_common.h:70
_pRespBodyBuffer
uint8_t _pRespBodyBuffer[HTTPS_TEST_RESP_BODY_BUFFER_SIZE]
HTTPS Response body buffer to share among the tests.
Definition: iot_tests_https_common.c:111
_pReqUserBuffer
uint8_t _pReqUserBuffer[HTTPS_TEST_REQ_USER_BUFFER_SIZE]
HTTPS Request user buffer to share among the tests.
Definition: iot_tests_https_common.c:93
_pRespUserBuffer
uint8_t _pRespUserBuffer[HTTPS_TEST_RESP_USER_BUFFER_SIZE]
HTTPS Response user buffer to share among the tests.
Definition: iot_tests_https_common.c:102
_syncRequestInfo
static IotHttpsSyncInfo_t _syncRequestInfo
A IotHttpsSyncInfo_t for requests to share among the tests.
Definition: iot_tests_https_sync.c:112
HTTPS_TEST_REQUEST_BODY_LENGTH
#define HTTPS_TEST_REQUEST_BODY_LENGTH
The length of the test HTTP request body.
Definition: iot_tests_https_common.h:148
HTTPS_TEST_ADDRESS
#define HTTPS_TEST_ADDRESS
Test address to share among the tests.
Definition: iot_tests_https_common.h:65
_syncResponseInfo
static IotHttpsSyncInfo_t _syncResponseInfo
A IotHttpsSyncInfo_t for responses to share among the tests.
Definition: iot_tests_https_sync.c:119