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

Tests for the user-facing API functions declared in iot_https_client.h. More...

#include <string.h>
#include "iot_tests_https_common.h"

Macros

#define HTTPS_TEST_REQUEST_LINE_WITHOUT_METHOD   HTTPS_TEST_PATH " " HTTPS_PROTOCOL_VERSION HTTPS_END_OF_HEADER_LINES_INDICATOR
 Expected HTTP request line without the method.
 
#define HTTPS_TEST_REQUEST_LINE_WITHOUT_PATH_WITHOUT_METHOD   HTTPS_EMPTY_PATH " " HTTPS_PROTOCOL_VERSION HTTPS_END_OF_HEADER_LINES_INDICATOR
 Expected HTTP request line without the path and without the method.
 
#define HTTPS_TEST_USER_AGENT_HEADER_LINE   HTTPS_USER_AGENT_HEADER HTTPS_HEADER_FIELD_SEPARATOR IOT_HTTPS_USER_AGENT HTTPS_END_OF_HEADER_LINES_INDICATOR
 Expected HTTP User-Agent header line.
 
#define HTTPS_TEST_HOST_HEADER_LINE   HTTPS_HOST_HEADER HTTPS_HEADER_FIELD_SEPARATOR HTTPS_TEST_ADDRESS HTTPS_END_OF_HEADER_LINES_INDICATOR
 Expected HTTP Host header line.
 
#define HTTPS_TEST_RESPONSE_HEADER_LINES
 HTTP response header lines to share among the tests. More...
 
#define HTTPS_TEST_RESPONSE_HEADER_LINES_LENGTH   sizeof( HTTPS_TEST_RESPONSE_HEADER_LINES ) - 1
 The length of the HTTP response test header lines.
 
#define HTTPS_TEST_RESPONSE_HEADER_LINES_NO_CONTENT_LENGTH
 Header lines with no content-length for testing. More...
 
#define HTTPS_TEST_RESPONSE_HEADER_LINES_NO_CONTENT_LENGTH_LENGTH   sizeof( HTTPS_TEST_RESPONSE_HEADER_LINES_NO_CONTENT_LENGTH ) - 1
 Length of the HTTP test response headers where there is no Content-Length.
 
#define HTTPS_DATE_HEADER   "Date"
 "Date" HTTP header field name. More...
 
#define HTTPS_ETAG_HEADER   "ETag"
 "ETag" HTTP header field name.
 
#define HTTPS_NONEXISTENT_HEADER   "Non-Existent-Header"
 HTTP header field name of a non-existing header for testing.
 
#define HTTPS_DATE_HEADER_VALUE   "Sun, 14 Jul 2019 06:07:52 GMT"
 Test header value for the "Date" header field.
 
#define HTTPS_ETAG_HEADER_VALUE   "\"3356-5233\""
 Test header value for the "ETag" header field.
 
#define HTTPS_CONTENT_LENGTH_VALUE   ( ( uint32_t ) 43 )
 Test header value as a unsigned integer for the "Content-Length" header field.
 
#define HTTPS_TEST_VALUE_BUFFER_LENGTH_LARGE_ENOUGH   ( 64 )
 A large enough test length of a local value buffer to store the returned header value. More...
 
#define HTTPS_TEST_VALUE_BUFFER_LENGTH_TOO_SMALL   ( 8 )
 A too small test length of a local value buffer to store the returned header value.
 

Functions

static size_t _networkReceiveFail (void *pConnection, uint8_t *pBuffer, size_t bytesRequested)
 A network receive callback that fails.
 
static size_t _networkSendSuccess (void *pConnection, const uint8_t *pMessage, size_t messageLength)
 A network receive callback that succeeds. More...
 
static size_t _networkSendFail (void *pConnection, const uint8_t *pMessage, size_t messageLength)
 Network abstraction send function that fails.
 
static IotNetworkError_t _networkCloseFail (void *pConnection)
 Network Abstraction close function that fails.
 
static IotNetworkError_t _networkDestroyFail (void *pConnection)
 Network Abstraction close function that fails.
 
static IotNetworkError_t _networkCreateFail (void *pConnectionInfo, void *pCredentialInfo, void **pConnection)
 Network Abstraction create function that fails.
 
static IotNetworkError_t _setReceiveCallbackFail (void *pConnection, IotNetworkReceiveCallback_t receiveCallback, void *pContext)
 Network Abstraction setReceiveCallback that fails.
 
static size_t _httpParserExecuteFail (http_parser *parser, const http_parser_settings *settings, const char *data, size_t len)
 Mock the http parser execution failing.
 
 TEST_GROUP (HTTPS_Client_Unit_API)
 Test group for HTTPS Client API tests.
 
 TEST_SETUP (HTTPS_Client_Unit_API)
 Test setup for HTTPS Client API tests.
 
 TEST_TEAR_DOWN (HTTPS_Client_Unit_API)
 Test tear down for HTTPS Client API tests.
 
 TEST_GROUP_RUNNER (HTTPS_Client_Unit_API)
 Test group runner for HTTPS Client API tests.
 
 TEST (HTTPS_Client_Unit_API, ConnectInvalidParameters)
 Test various invalid parameters in the IotHttpsClient_Connect API.
 
 TEST (HTTPS_Client_Unit_API, ConnectFailure)
 Test a connection failing in few network abstraction upset scenarios.
 
 TEST (HTTPS_Client_Unit_API, ConnectSuccess)
 Test a connection succeeding.
 
 TEST (HTTPS_Client_Unit_API, DisconnectInvalidParameters)
 Test various invalid parameters in the IotHttpsClient_Disconnect API.
 
 TEST (HTTPS_Client_Unit_API, DisconnectFailure)
 Test that we set the connection in the correct state when a disconnect fails.
 
 TEST (HTTPS_Client_Unit_API, DisconnectSuccess)
 Test that we set the connection in the correct state when a disconnect succeeds.
 
 TEST (HTTPS_Client_Unit_API, InitializeRequestInvalidParameters)
 Test intitializing an HTTP request with various invalid parameters.
 
 TEST (HTTPS_Client_Unit_API, InitializeRequestFormatCheck)
 Verify that the intialized request is in the standard HTTP format expected in the user buffer header space.
 
 TEST (HTTPS_Client_Unit_API, AddHeaderInvalidParameters)
 Test IotHttpsClient_AddHeader() with various invalid parameters.
 
 TEST (HTTPS_Client_Unit_API, AddHeaderFormatCheck)
 Add a header to the HTTP request and verify the format is correct.
 
 TEST (HTTPS_Client_Unit_API, AddHeaderMultipleHeaders)
 Add multiple headers to the header buffer space in the request.
 
 TEST (HTTPS_Client_Unit_API, ReadHeaderInvalidParameters)
 Test IotHttpsClient_ReadHeader() with various invalid parameters.
 
 TEST (HTTPS_Client_Unit_API, ReadHeaderVaryingValues)
 Test IotHttpsClient_ReadHeader() with various header search parameters.
 
 TEST (HTTPS_Client_Unit_API, ReadContentLengthInvalidParameters)
 Test IotHttpsClient_ReadContentLength() with invalid parameters.
 
 TEST (HTTPS_Client_Unit_API, ReadContentLengthSuccess)
 Test a successful read of the Content-Length from the HTTP response.
 
 TEST (HTTPS_Client_Unit_API, ReadContentLengthNotFound)
 Test a reading the content length when the header does not exist.
 
 TEST (HTTPS_Client_Unit_API, ReadResponseStatusInvalidParameters)
 Test IotHttpsClient_ReadResponseStatus() with various invalid parameters.
 
 TEST (HTTPS_Client_Unit_API, ReadResponseStatusSuccess)
 Test a successful read of the HTTP response status code from an HTTP response message.
 
 TEST (HTTPS_Client_Unit_API, WriteRequestBodyInvalidParameters)
 Test IotHttpsClient_WriteRequestBody() with various invalid parameters.
 
 TEST (HTTPS_Client_Unit_API, WriteRequestBodySuccess)
 Test a successful call to IotHttpsClient_WriteRequestBody().
 
 TEST (HTTPS_Client_Unit_API, WriteRequestBodyNetworkSendFailure)
 Test a network send failure in a call to IotHttpsClient_WriteRequestBody().
 
 TEST (HTTPS_Client_Unit_API, ReadResponseBodyInvalidParameters)
 Test IotHttpsClient_ReadResponseBody() with NULL parameters.
 
 TEST (HTTPS_Client_Unit_API, ReadResponseBodyNetworkReceiveFailure)
 Test a network error is returned when there is failure to receive on the network.
 
 TEST (HTTPS_Client_Unit_API, ReadResponseBodyParsingFailure)
 Test that there is a parsing error when there is a failure to parse the data received from the network.
 
 TEST (HTTPS_Client_Unit_API, ReadResponseBodySuccess)
 Test a successful call to IotHttpsClient_ReadResponseBody().
 

Variables

static IotHttpsAsyncInfo_t _asyncInfo
 A IotHttpsAsyncInfo_t 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 for a GET method to share among the tests. More...
 

Detailed Description

Tests for the user-facing API functions declared in iot_https_client.h.

Macro Definition Documentation

◆ HTTPS_TEST_RESPONSE_HEADER_LINES

#define HTTPS_TEST_RESPONSE_HEADER_LINES
Value:
"HTTP/1.1 200 OK\r\n" \
"Content-Length: 43\r\n" \
"Date: Sun, 14 Jul 2019 06:07:52 GMT\r\n" \
"ETag: \"3356-5233\"\r\n" \
"Vary: *\r\n" \
"P3P: CP=\"This is not a P3P policy\"\r\n" \
"xserver: www1021\r\n"

HTTP response header lines to share among the tests.

◆ HTTPS_TEST_RESPONSE_HEADER_LINES_NO_CONTENT_LENGTH

#define HTTPS_TEST_RESPONSE_HEADER_LINES_NO_CONTENT_LENGTH
Value:
"HTTP/1.1 200 OK\r\n" \
"Date: Sun, 14 Jul 2019 06:07:52 GMT\r\n" \
"ETag: \"3356-5233\"\r\n" \
"Vary: *\r\n" \
"P3P: CP=\"This is not a P3P policy\"\r\n" \
"xserver: www1021\r\n\r\n"

Header lines with no content-length for testing.

◆ HTTPS_DATE_HEADER

#define HTTPS_DATE_HEADER   "Date"

"Date" HTTP header field name.

Header name and values to verify reading the header.

◆ HTTPS_TEST_VALUE_BUFFER_LENGTH_LARGE_ENOUGH

#define HTTPS_TEST_VALUE_BUFFER_LENGTH_LARGE_ENOUGH   ( 64 )

A large enough test length of a local value buffer to store the returned header value.

The array lengths of local value buffers in the test to store the header values.

Function Documentation

◆ _networkSendSuccess()

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

A network receive callback that succeeds.

Network abstraction send function that succeeds.

Variable Documentation

◆ _asyncInfo

IotHttpsAsyncInfo_t _asyncInfo
static
Initial value:
=
{
.callbacks = { 0 },
.pPrivData = NULL
}

A IotHttpsAsyncInfo_t to share among the tests.

The tests will replace callbacks in .callbacks as needed and add pPrivData as need for the test.

◆ _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 = true,
.u.pAsyncInfo = &_asyncInfo
}

A IotHttpsRequestInfo_t to share among the tests.

◆ _respInfo

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

A IotHttpsResponseInfo_t for a GET method to share among the tests.

HTTPS_TEST_PATH
#define HTTPS_TEST_PATH
Test path to share among the tests.
Definition: iot_tests_https_common.h:70
_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
HTTPS_TEST_ADDRESS
#define HTTPS_TEST_ADDRESS
Test address to share among the tests.
Definition: iot_tests_https_common.h:65
_asyncInfo
static IotHttpsAsyncInfo_t _asyncInfo
A IotHttpsAsyncInfo_t to share among the tests.
Definition: iot_tests_https_client.c:104