FreeRTOS: HTTPS Client
HTTPS Client v1.0.0 library
Return to main page ↑
iot_tests_https_common.h File Reference

Common definitions for the HTTPS Client unit tests. More...

#include "iot_config.h"
#include <string.h>
#include "iot_init.h"
#include "private/iot_https_internal.h"
#include "iot_test_access_https.h"
#include "aws_clientcredential.h"
#include "aws_clientcredential_keys.h"
#include "unity_fixture.h"

Go to the source code of this file.

Macros

#define HTTPS_TEST_PORT   ( ( uint16_t ) 443 )
 Test TLS TCP port.
 
#define HTTPS_TEST_ADDRESS   "www.amazon.com "
 Test address to share among the tests.
 
#define HTTPS_TEST_PATH   "/path.txt"
 Test path to share among the tests.
 
#define HTTPS_TEST_ALPN_PROTOCOL   "http/1.1"
 Test HTTP/1.1 protocol to share among the tests.
 
#define HTTPS_TEST_ROOT_CA
 Baltimore Cybertrust root CA to share among the tests. More...
 
#define HTTPS_TEST_CONN_USER_BUFFER_SIZE   ( sizeof( _httpsConnection_t ) )
 The size of the connection user buffer to use among the tests.
 
#define HTTPS_TEST_REQ_USER_BUFFER_SIZE   ( 512 )
 The size of the request user buffer to use among the tests.
 
#define HTTPS_TEST_RESP_USER_BUFFER_SIZE   ( sizeof( _httpsResponse_t ) + 128 )
 The size of the response user buffer to use among the tests. More...
 
#define HTTPS_TEST_RESP_BODY_BUFFER_SIZE   ( 256 )
 The size of the response body buffer to use among the tests.
 
#define HTTPS_TEST_RESPONSE_MESSAGE_LENGTH   ( 1024 )
 The maximum length of the HTTP response message buffer shared among the test. More...
 
#define HTTPS_TEST_RESP_HEADER_BUFFER_LENGTH   ( HTTPS_TEST_RESP_USER_BUFFER_SIZE - sizeof( _httpsResponse_t ) )
 The length of the response header buffer shared among the tests.
 
#define HTTPS_TEST_REQUEST_BODY
 Test HTTP request body to share among the tests. More...
 
#define HTTPS_TEST_REQUEST_BODY_LENGTH   ( sizeof( HTTPS_TEST_REQUEST_BODY ) - 1 )
 The length of the test HTTP request body.
 
#define HTTPS_TEST_SMALL_RESPONSE
 A small test HTTPS response to share among the tests. More...
 
#define HTTPS_TEST_SMALL_RESPONSE_LENGTH   ( sizeof( HTTPS_TEST_SMALL_RESPONSE ) - 1 )
 The length of the small test HTTP response.
 
#define HTTPS_TEST_CHUNKED_RESPONSE
 Test HTTP chunked response message to share among the tests. More...
 
#define HTTPS_TEST_CHUNKED_RESPONSE_BODY_LENGTH   ( 0xB + 0xC + 3 )
 The length of the test chunked HTTP response body.
 

Functions

static IotNetworkError_t _networkCreateSuccess (void *pConnectionInfo, void *pCredentialInfo, void **pConnection)
 Network Abstraction create function that succeeds.
 
static IotNetworkError_t _setReceiveCallbackSuccess (void *pConnection, IotNetworkReceiveCallback_t receiveCallback, void *pContext)
 Network Abstraction setReceiveCallback that succeeds.
 
static IotHttpsConnectionHandle_t _getConnHandle (void)
 Get a valid connected state intialized connection handle using _pConnUserBuffer and _connInfo.
 
static IotHttpsRequestHandle_t _getReqHandle (IotHttpsRequestInfo_t *pReqInfo)
 Get a valid request handle with the input pReqInfo.
 
static IotHttpsResponseHandle_t _getRespHandle (IotHttpsResponseInfo_t *pRespInfo, IotHttpsRequestHandle_t reqHandle)
 Get a valid response handle using _pRespUserBuffer, and respInfoGET.
 
static IotNetworkError_t _networkCloseSuccess (void *pConnection)
 Network Abstraction close function that succeeds.
 
static IotNetworkError_t _networkDestroySuccess (void *pConnection)
 Network abstraction destroy function that succeeds.
 
static size_t _networkReceiveSuccess (void *pConnection, uint8_t *pBuffer, size_t bytesRequested)
 Network abstraction receive function that succeeds.
 
void _generateHttpResponseMessage (int headerLength, int bodyLength)
 Generate an test HTTP response message with the specified header length and the specified body length. More...
 
void _verifyHttpResponseBody (int bodyLength, uint8_t *pBody, int startIndex)
 Test verify the response body in pBody up to bodyLength. More...
 

Variables

uint8_t _pConnUserBuffer [HTTPS_TEST_CONN_USER_BUFFER_SIZE]
 HTTPS Client connection user buffer to share among the tests. More...
 
uint8_t _pRespBodyBuffer [HTTPS_TEST_RESP_BODY_BUFFER_SIZE]
 HTTPS Response body buffer to share among the tests. More...
 
uint8_t _pRespMessageBuffer [HTTPS_TEST_RESPONSE_MESSAGE_LENGTH]
 An HTTP response message to share among the tests. More...
 
uint8_t _pReqUserBuffer [HTTPS_TEST_REQ_USER_BUFFER_SIZE]
 HTTPS Request user buffer to share among the tests. More...
 
uint8_t _pRespUserBuffer [HTTPS_TEST_RESP_USER_BUFFER_SIZE]
 HTTPS Response user buffer to share among the tests. More...
 
static uint32_t _nextRespMessageBufferByteToReceive = 0
 The current place in _pRespMessageBuffer to receive the next byte. More...
 
static IotNetworkInterface_t _networkInterface = { 0 }
 An IotNetworkInterface_t to share among the tests.
 
static IotHttpsConnectionInfo_t _connInfo
 A IotHttpsConnectionInfo_t to share among the tests. More...
 

Detailed Description

Common definitions for the HTTPS Client unit tests.

Macro Definition Documentation

◆ HTTPS_TEST_ROOT_CA

#define HTTPS_TEST_ROOT_CA
Value:
"-----BEGIN CERTIFICATE-----\n" \
"MIIDdzCCAl+gAwIBAgIEAgAAuTANBgkqhkiG9w0BAQUFADBaMQswCQYDVQQGEwJJ\n" \
"RTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJlclRydXN0MSIwIAYD\n" \
"VQQDExlCYWx0aW1vcmUgQ3liZXJUcnVzdCBSb290MB4XDTAwMDUxMjE4NDYwMFoX\n" \
"DTI1MDUxMjIzNTkwMFowWjELMAkGA1UEBhMCSUUxEjAQBgNVBAoTCUJhbHRpbW9y\n" \
"ZTETMBEGA1UECxMKQ3liZXJUcnVzdDEiMCAGA1UEAxMZQmFsdGltb3JlIEN5YmVy\n" \
"VHJ1c3QgUm9vdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKMEuyKr\n" \
"mD1X6CZymrV51Cni4eiVgLGw41uOKymaZN+hXe2wCQVt2yguzmKiYv60iNoS6zjr\n" \
"IZ3AQSsBUnuId9Mcj8e6uYi1agnnc+gRQKfRzMpijS3ljwumUNKoUMMo6vWrJYeK\n" \
"mpYcqWe4PwzV9/lSEy/CG9VwcPCPwBLKBsua4dnKM3p31vjsufFoREJIE9LAwqSu\n" \
"XmD+tqYF/LTdB1kC1FkYmGP1pWPgkAx9XbIGevOF6uvUA65ehD5f/xXtabz5OTZy\n" \
"dc93Uk3zyZAsuT3lySNTPx8kmCFcB5kpvcY67Oduhjprl3RjM71oGDHweI12v/ye\n" \
"jl0qhqdNkNwnGjkCAwEAAaNFMEMwHQYDVR0OBBYEFOWdWTCCR1jMrPoIVDaGezq1\n" \
"BE3wMBIGA1UdEwEB/wQIMAYBAf8CAQMwDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3\n" \
"DQEBBQUAA4IBAQCFDF2O5G9RaEIFoN27TyclhAO992T9Ldcw46QQF+vaKSm2eT92\n" \
"9hkTI7gQCvlYpNRhcL0EYWoSihfVCr3FvDB81ukMJY2GQE/szKN+OMY3EU/t3Wgx\n" \
"jkzSswF07r51XgdIGn9w/xZchMB5hbgF/X++ZRGjD8ACtPhSNzkE1akxehi/oCr0\n" \
"Epn3o0WC4zxe9Z2etciefC7IpJ5OCBRLbf1wbWsaY71k5h+3zvDyny67G7fyUIhz\n" \
"ksLi4xaNmjICq44Y3ekQEe5+NauQrz4wlHrQMz2nZQ/1/I6eYs9HRCwBXbsdtTLS\n" \
"R9I4LtD+gdwyah617jzV/OeBHRnDJELqYzmp\n" \
"-----END CERTIFICATE-----\n"

Baltimore Cybertrust root CA to share among the tests.

◆ HTTPS_TEST_RESP_USER_BUFFER_SIZE

#define HTTPS_TEST_RESP_USER_BUFFER_SIZE   ( sizeof( _httpsResponse_t ) + 128 )

The size of the response user buffer to use among the tests.

The header space comes after the response context, hence the addition to the response context.

◆ HTTPS_TEST_RESPONSE_MESSAGE_LENGTH

#define HTTPS_TEST_RESPONSE_MESSAGE_LENGTH   ( 1024 )

The maximum length of the HTTP response message buffer shared among the test.

The buffer of this length is used to test a few scenarios where the headers or body are found in either the header buffer or body buffer and need to be copied over appropriately.

◆ HTTPS_TEST_REQUEST_BODY

#define HTTPS_TEST_REQUEST_BODY
Value:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore " \
"magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo" \
" consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla paria" \
"tur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est lab" \
"orum."

Test HTTP request body to share among the tests.

◆ HTTPS_TEST_SMALL_RESPONSE

#define HTTPS_TEST_SMALL_RESPONSE
Value:
"HTTP/1.1 200 OK\r\nheader0: value0\r\nheader1: value1\r\n" \
"header2: value2 value2a\r\nContent-Length: 26\r\n\r\nabcdefghijklmnopqrstuvwxyz"

A small test HTTPS response to share among the tests.

◆ HTTPS_TEST_CHUNKED_RESPONSE

#define HTTPS_TEST_CHUNKED_RESPONSE
Value:
"HTTP/1.1 403 Forbidden\r\n" \
"header0: value0\r\n" \
"header1: value1\r\n" \
"Transfer-Encoding: chunked\r\n" \
"\r\n" \
"b\r\n" \
"abcdefghijk\r\n" \
"c\r\n" \
"lmnopqrstuvw\r\n" \
"3\r\n" \
"xyz\r\n" \
"0\r\n" \
"\r\n"

Test HTTP chunked response message to share among the tests.

Function Documentation

◆ _generateHttpResponseMessage()

void _generateHttpResponseMessage ( int  headerLength,
int  bodyLength 
)

Generate an test HTTP response message with the specified header length and the specified body length.

This generates the test HTTP response message into _pRespMessageBuffer. _pRespMessageBuffer must be zeroed out before calling this routine. The length of _pRespMessageBuffer must not exceed headerLength + bodyLength. The headerLength is the length of the raw HTTP headers includes delimiters like ": " and "\r\n". The length of headerLength must be greater than: "HTTP/1.1 200 OK\r\nContent-Length: <bodyLengthStr>\r\nheader0: value0\r\n\r\n" in order to generate meaningful header data.

◆ _verifyHttpResponseBody()

void _verifyHttpResponseBody ( int  bodyLength,
uint8_t *  pBody,
int  startIndex 
)

Test verify the response body in pBody up to bodyLength.

This will verify that 'a' through 'z' (then repeated) are written properly.

Variable Documentation

◆ _pConnUserBuffer

uint8_t _pConnUserBuffer[HTTPS_TEST_CONN_USER_BUFFER_SIZE]
extern

HTTPS Client connection user buffer to share among the tests.

This variable is extern to save memory. This is acceptable as the HTTPS Client unit tests run sequentially. The user buffers are always overwritten each utilizing test, so data left over affecting other tests is not a concern.

◆ _pRespBodyBuffer

uint8_t _pRespBodyBuffer[HTTPS_TEST_RESP_BODY_BUFFER_SIZE]
extern

HTTPS Response body buffer to share among the tests.

This variable is extern to save memory. This is acceptable as the HTTPS Client unit tests run sequentially. The user buffers are always overwritten each utilizing test, so data left over affecting other tests is not a concern.

◆ _pRespMessageBuffer

uint8_t _pRespMessageBuffer[HTTPS_TEST_RESPONSE_MESSAGE_LENGTH]
extern

An HTTP response message to share among the tests.

This variable is extern to save memory. This is acceptable as the HTTPS Client unit tests run sequentially. The user buffers are always overwritten each utilizing test, so data left over affecting other tests is not a concern.

◆ _pReqUserBuffer

uint8_t _pReqUserBuffer[HTTPS_TEST_REQ_USER_BUFFER_SIZE]
extern

HTTPS Request user buffer to share among the tests.

This variable is extern to save memory. This is acceptable as the HTTPS Client unit tests run sequentially. The user buffers are always overwritten each utilizing test, so data left over affecting other tests is not a concern.

◆ _pRespUserBuffer

uint8_t _pRespUserBuffer[HTTPS_TEST_RESP_USER_BUFFER_SIZE]
extern

HTTPS Response user buffer to share among the tests.

This variable is extern to save memory. This is acceptable as the HTTPS Client unit tests run sequentially. The user buffers are always overwritten each utilizing test, so data left over affecting other tests is not a concern.

◆ _nextRespMessageBufferByteToReceive

uint32_t _nextRespMessageBufferByteToReceive = 0
static

The current place in _pRespMessageBuffer to receive the next byte.

This is used to mimic receiving the HTTP response message from the network during testing.

◆ _connInfo

IotHttpsConnectionInfo_t _connInfo
static
Initial value:
= {
.pAddress = HTTPS_TEST_ADDRESS,
.addressLen = sizeof( HTTPS_TEST_ADDRESS ) - 1,
.port = HTTPS_TEST_PORT,
.flags = 0,
.pCaCert = HTTPS_TEST_ROOT_CA,
.caCertLen = sizeof( HTTPS_TEST_ROOT_CA ),
.userBuffer.pBuffer = _pConnUserBuffer,
.userBuffer.bufferLen = sizeof( _pConnUserBuffer ),
.pClientCert = keyCLIENT_CERTIFICATE_PEM,
.clientCertLen = sizeof( keyCLIENT_CERTIFICATE_PEM ),
.pPrivateKey = keyCLIENT_PRIVATE_KEY_PEM,
.privateKeyLen = sizeof( keyCLIENT_PRIVATE_KEY_PEM ),
.pAlpnProtocols = HTTPS_TEST_ALPN_PROTOCOL,
.alpnProtocolsLen = sizeof( HTTPS_TEST_ALPN_PROTOCOL ),
.pNetworkInterface = &_networkInterface
}

A IotHttpsConnectionInfo_t to share among the tests.

HTTPS_TEST_ALPN_PROTOCOL
#define HTTPS_TEST_ALPN_PROTOCOL
Test HTTP/1.1 protocol to share among the tests.
Definition: iot_tests_https_common.h:75
HTTPS_TEST_PORT
#define HTTPS_TEST_PORT
Test TLS TCP port.
Definition: iot_tests_https_common.h:60
_networkInterface
static IotNetworkInterface_t _networkInterface
An IotNetworkInterface_t to share among the tests.
Definition: iot_tests_https_common.h:235
HTTPS_TEST_ROOT_CA
#define HTTPS_TEST_ROOT_CA
Baltimore Cybertrust root CA to share among the tests.
Definition: iot_tests_https_common.h:80
_pConnUserBuffer
uint8_t _pConnUserBuffer[HTTPS_TEST_CONN_USER_BUFFER_SIZE]
HTTPS Client connection user buffer to share among the tests.
Definition: iot_tests_https_common.c:84
HTTPS_TEST_ADDRESS
#define HTTPS_TEST_ADDRESS
Test address to share among the tests.
Definition: iot_tests_https_common.h:65