smtp-client
SMTP Client C Library
seams.c File Reference

Test seams for the smtp-client library. More...

#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "test.h"
+ Include dependency graph for seams.c:

Go to the source code of this file.

Functions

int smtp_test_seam_dec_err_ctr (int *const test_err_ctr)
 
BIO * smtp_test_seam_bio_new_socket (int sock, int close_flag)
 
int smtp_test_seam_bio_should_retry (BIO *bio)
 
void * smtp_test_seam_calloc (size_t nelem, size_t elsize)
 
int smtp_test_seam_close (int fildes)
 
int smtp_test_seam_connect (int socket, const struct sockaddr *address, socklen_t address_len)
 
unsigned long smtp_test_seam_err_peek_error (void)
 
int smtp_test_seam_fclose (FILE *stream)
 
int smtp_test_seam_ferror (FILE *stream)
 
struct tm * smtp_test_seam_gmtime_r (const time_t *timep, struct tm *result)
 
unsigned char * smtp_test_seam_hmac (const EVP_MD *evp_md, const void *key, int key_len, const unsigned char *d, size_t n, unsigned char *md, unsigned int *md_len)
 
struct tm * smtp_test_seam_localtime_r (const time_t *timep, struct tm *result)
 
void * smtp_test_seam_malloc (size_t size)
 
time_t smtp_test_seam_mktime (struct tm *timeptr)
 
void * smtp_test_seam_realloc (void *ptr, size_t size)
 
long smtp_test_seam_recv (int socket, void *buffer, size_t length, int flags)
 
int smtp_test_seam_select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *timeout)
 
ssize_t smtp_test_seam_send (int socket, const void *buffer, size_t length, int flags)
 
int smtp_test_seam_socket (int domain, int type, int protocol)
 
int smtp_test_seam_ssl_connect (SSL *ssl)
 
SSL_CTX * smtp_test_seam_ssl_ctx_new (const SSL_METHOD *method)
 
int smtp_test_seam_ssl_do_handshake (SSL *ssl)
 
X509 * smtp_test_seam_ssl_get_peer_certificate (const SSL *ssl)
 
int smtp_test_seam_x509_check_host (X509 *cert, const char *name, size_t namelen, unsigned int flags, char **peername)
 
SSL * smtp_test_seam_ssl_new (SSL_CTX *ctx)
 
int smtp_test_seam_ssl_read (SSL *ssl, void *buf, int num)
 
int smtp_test_seam_ssl_write (SSL *ssl, const void *buf, int num)
 
int smtp_test_seam_sprintf (char *s, const char *format,...)
 
size_t smtp_test_seam_strlen (const char *s)
 
time_t smtp_test_seam_time (time_t *tloc)
 

Variables

int g_smtp_test_err_bio_new_socket_ctr = -1
 
int g_smtp_test_err_bio_should_retry_ctr = -1
 
int g_smtp_test_err_bio_should_retry_rc = -1
 
int g_smtp_test_err_calloc_ctr = -1
 
int g_smtp_test_err_close_ctr = -1
 
int g_smtp_test_err_connect_ctr = -1
 
int g_smtp_test_err_err_peek_error_ctr = -1
 
int g_smtp_test_err_fclose_ctr = -1
 
int g_smtp_test_err_ferror_ctr = -1
 
int g_smtp_test_err_gmtime_r_ctr = -1
 
int g_smtp_test_err_hmac_ctr = -1
 
int g_smtp_test_err_localtime_r_ctr = -1
 
int g_smtp_test_err_malloc_ctr = -1
 
int g_smtp_test_err_mktime_ctr = -1
 
int g_smtp_test_err_realloc_ctr = -1
 
int g_smtp_test_err_recv_ctr = -1
 
int g_smtp_test_err_recv_rc = -1
 
char g_smtp_test_err_recv_bytes [90] = {0}
 
int g_smtp_test_err_select_ctr = -1
 
int g_smtp_test_err_send_ctr = -1
 
int g_smtp_test_send_one_byte = 0
 
int g_smtp_test_err_si_add_size_t_ctr = -1
 
int g_smtp_test_err_si_sub_size_t_ctr = -1
 
int g_smtp_test_err_si_mul_size_t_ctr = -1
 
int g_smtp_test_err_socket_ctr = -1
 
int g_smtp_test_err_ssl_connect_ctr = -1
 
int g_smtp_test_err_ssl_ctx_new_ctr = -1
 
int g_smtp_test_err_ssl_do_handshake_ctr = -1
 
int g_smtp_test_err_ssl_get_peer_certificate_ctr = -1
 
int g_smtp_test_err_x509_check_host_ctr = -1
 
int g_smtp_test_err_ssl_new_ctr = -1
 
int g_smtp_test_err_ssl_read_ctr = -1
 
int g_smtp_test_err_ssl_write_ctr = -1
 
int g_smtp_test_err_sprintf_ctr = -1
 
int g_smtp_test_err_sprintf_rc = 0
 
int g_smtp_test_strlen_custom_ret = 0
 
size_t g_smtp_test_strlen_ret_value = 0
 
int g_smtp_test_time_custom_ret = 0
 
time_t g_smtp_test_time_ret_value = 0
 

Detailed Description

Test seams for the smtp-client library.

Author
James Humphrey (mail@.nosp@m.somn.nosp@m.isoft.nosp@m..com)
Version
1.00

Used by the smtp-client testing framework to inject specific return values by some standard library functions. This makes it possible to test less common errors like out of memory conditions and input/output errors.

This software has been placed into the public domain using CC0.

Definition in file seams.c.

Function Documentation

◆ smtp_test_seam_bio_new_socket()

BIO* smtp_test_seam_bio_new_socket ( int  sock,
int  close_flag 
)

Allows the test harness to control when BIO_new_socket() fails.

Parameters
[in]sockExisting socket to attach the BIO to.
[in]close_flagClose flag for new BIO.
Return values
BIO*New BIO created on existing socket.
NULLFailed to create the new BIO.

Definition at line 263 of file seams.c.

References BIO_new_socket, g_smtp_test_err_bio_new_socket_ctr, and smtp_test_seam_dec_err_ctr().

264  {
266  return NULL;
267  }
268  return BIO_new_socket(sock, close_flag);
269 }
int g_smtp_test_err_bio_new_socket_ctr
Definition: seams.c:28
int sock
Definition: smtp.c:159
#define BIO_new_socket
Definition: seams.h:57
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_bio_should_retry()

int smtp_test_seam_bio_should_retry ( BIO *  bio)

Allows the test harness to control when BIO_should_retry() fails.

Parameters
[in]bioExisting BIO connection.
Return values
0The error condition does not allow a retry.
1The error condition allows a retry.

Definition at line 279 of file seams.c.

References BIO_should_retry, g_smtp_test_err_bio_should_retry_ctr, g_smtp_test_err_bio_should_retry_rc, and smtp_test_seam_dec_err_ctr().

279  {
281  return 0;
282  }
285  }
286  return BIO_should_retry(bio);
287 }
int g_smtp_test_err_bio_should_retry_rc
Definition: seams.c:39
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
#define BIO_should_retry
Definition: seams.h:65
int g_smtp_test_err_bio_should_retry_ctr
Definition: seams.c:34
+ Here is the call graph for this function:

◆ smtp_test_seam_calloc()

void* smtp_test_seam_calloc ( size_t  nelem,
size_t  elsize 
)

Allows the test harness to control when calloc() fails.

Parameters
[in]nelemNumber of elements to allocate.
[in]elsizeSize of each element to allocate.
Return values
void*Pointer to new allocated memory.
NULLMemory allocation failed.

Definition at line 298 of file seams.c.

References calloc, g_smtp_test_err_calloc_ctr, and smtp_test_seam_dec_err_ctr().

299  {
301  errno = ENOMEM;
302  return NULL;
303  }
304  return calloc(nelem, elsize);
305 }
#define calloc
Definition: seams.h:73
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
int g_smtp_test_err_calloc_ctr
Definition: seams.c:44
+ Here is the call graph for this function:

◆ smtp_test_seam_close()

int smtp_test_seam_close ( int  fildes)

Allows the test harness to control when close() fails.

Parameters
[in]fildesSocket file descriptor to close.
Return values
0Successfully closed file descriptor.
-1Failed to close file descriptor.

Definition at line 315 of file seams.c.

References close, g_smtp_test_err_close_ctr, and smtp_test_seam_dec_err_ctr().

315  {
317  errno = EBADF;
318  return -1;
319  }
320  return close(fildes);
321 }
int g_smtp_test_err_close_ctr
Definition: seams.c:49
#define close
Definition: seams.h:81
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_connect()

int smtp_test_seam_connect ( int  socket,
const struct sockaddr *  address,
socklen_t  address_len 
)

Allows the test harness to control when connect() fails.

Parameters
[in]socketSocket connection.
[in]addressNetwork address of peer.
[in]address_lenNumber of bytes in address.
Return values
0Successfully connected to the peer.
-1Failed to connect to the peer.

Definition at line 333 of file seams.c.

References connect, g_smtp_test_err_connect_ctr, and smtp_test_seam_dec_err_ctr().

335  {
337  errno = ECONNREFUSED;
338  return -1;
339  }
340  return connect(socket, address, address_len);
341 }
#define socket
Definition: seams.h:193
#define connect
Definition: seams.h:89
int g_smtp_test_err_connect_ctr
Definition: seams.c:54
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_dec_err_ctr()

int smtp_test_seam_dec_err_ctr ( int *const  test_err_ctr)

Decrement an error counter until it reaches -1.

Once a counter reaches -1, it will return a successful response (1). This typically gets used to denote when to cause a function to fail. For example, the unit test or functional test might need to cause the realloc() function to fail after calling it the third time.

Parameters
[in,out]test_err_ctrInteger counter to decrement.
Return values
0The counter has been decremented, but did not reach -1 yet.
1The counter has reached -1.

Definition at line 244 of file seams.c.

Referenced by smtp_si_add_size_t(), smtp_si_mul_size_t(), smtp_si_sub_size_t(), smtp_test_seam_bio_new_socket(), smtp_test_seam_bio_should_retry(), smtp_test_seam_calloc(), smtp_test_seam_close(), smtp_test_seam_connect(), smtp_test_seam_err_peek_error(), smtp_test_seam_fclose(), smtp_test_seam_ferror(), smtp_test_seam_gmtime_r(), smtp_test_seam_hmac(), smtp_test_seam_localtime_r(), smtp_test_seam_malloc(), smtp_test_seam_mktime(), smtp_test_seam_realloc(), smtp_test_seam_recv(), smtp_test_seam_select(), smtp_test_seam_send(), smtp_test_seam_socket(), smtp_test_seam_sprintf(), smtp_test_seam_ssl_connect(), smtp_test_seam_ssl_ctx_new(), smtp_test_seam_ssl_do_handshake(), smtp_test_seam_ssl_get_peer_certificate(), smtp_test_seam_ssl_new(), smtp_test_seam_ssl_read(), smtp_test_seam_ssl_write(), and smtp_test_seam_x509_check_host().

244  {
245  if(*test_err_ctr >= 0){
246  *test_err_ctr -= 1;
247  if(*test_err_ctr < 0){
248  return 1;
249  }
250  }
251  return 0;
252 }
+ Here is the caller graph for this function:

◆ smtp_test_seam_err_peek_error()

unsigned long smtp_test_seam_err_peek_error ( void  )

Allows the test harness to control when ERR_peek_error() returns a failure code.

Return values
0No error code on the error queue.
!0An error code exists on the error queue.

Definition at line 351 of file seams.c.

References ERR_peek_error, g_smtp_test_err_err_peek_error_ctr, and smtp_test_seam_dec_err_ctr().

351  {
353  return 1;
354  }
355  return ERR_peek_error();
356 }
int g_smtp_test_err_err_peek_error_ctr
Definition: seams.c:60
#define ERR_peek_error
Definition: seams.h:97
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_fclose()

int smtp_test_seam_fclose ( FILE *  stream)

Allows the test harness to control when fclose() fails.

Parameters
[in]streamFile stream to close.
Return values
0Successfully closed the file stream.
EOFAn error occurred while closing the file stream.

Definition at line 365 of file seams.c.

References fclose, g_smtp_test_err_fclose_ctr, and smtp_test_seam_dec_err_ctr().

365  {
367  errno = EBADF;
368  return EOF;
369  }
370  return fclose(stream);
371 }
int g_smtp_test_err_fclose_ctr
Definition: seams.c:65
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
#define fclose
Definition: seams.h:105
+ Here is the call graph for this function:

◆ smtp_test_seam_ferror()

int smtp_test_seam_ferror ( FILE *  stream)

Allows the test harness to control the file stream error indicator return value in ferror().

Parameters
[in]streamCheck for errors on this file stream.
Return values
0No errors detected on the file stream.
1An error occurred during a file stream operation.

Definition at line 382 of file seams.c.

References ferror, g_smtp_test_err_ferror_ctr, and smtp_test_seam_dec_err_ctr().

382  {
384  return 1;
385  }
386  return ferror(stream);
387 }
#define ferror
Definition: seams.h:113
int g_smtp_test_err_ferror_ctr
Definition: seams.c:70
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_gmtime_r()

struct tm* smtp_test_seam_gmtime_r ( const time_t *  timep,
struct tm *  result 
)

Allows the test harness to control when gmtime_r() fails.

Parameters
[in]timepTime value to convert to a struct tm.
[out]resultConverts the timep value into a UTC tm structure value and stores the results in this pointer.
Return values
tm*time_t value converted to a tm structure value.
NULLAn error occurred while converting the time.

Definition at line 399 of file seams.c.

References g_smtp_test_err_gmtime_r_ctr, gmtime_r, and smtp_test_seam_dec_err_ctr().

400  {
402  return NULL;
403  }
404  return gmtime_r(timep, result);
405 }
#define gmtime_r
Definition: seams.h:121
int g_smtp_test_err_gmtime_r_ctr
Definition: seams.c:75
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_hmac()

unsigned char* smtp_test_seam_hmac ( const EVP_MD *  evp_md,
const void *  key,
int  key_len,
const unsigned char *  d,
size_t  n,
unsigned char *  md,
unsigned int *  md_len 
)

Allows the test harness to control when HMAC() fails.

Parameters
[in]evp_mdHash function.
[in]keyHash key.
[in]key_lenNumber of bytes in key.
[in]dMessage data.
[in]nNumber of bytes in d.
[out]mdThe computed message authentication code.
[in]md_lenNumber of bytes in md.
Return values
uchar*Pointer to md.
NULLAn error occurred.

Definition at line 421 of file seams.c.

References g_smtp_test_err_hmac_ctr, HMAC, and smtp_test_seam_dec_err_ctr().

427  {
429  return NULL;
430  }
431  return HMAC(evp_md, key, key_len, d, n, md, md_len);
432 }
#define HMAC
Definition: seams.h:129
int g_smtp_test_err_hmac_ctr
Definition: seams.c:80
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_localtime_r()

struct tm* smtp_test_seam_localtime_r ( const time_t *  timep,
struct tm *  result 
)

Allows the test harness to control when localtime_r() fails.

Parameters
[in]timepTime value to convert to a struct tm.
[out]resultConverts the timep value into a local time tm structure value and stores the results in this pointer.
Return values
tm*time_t value converted to a tm structure value.
NULLAn error occurred while converting the time.

Definition at line 444 of file seams.c.

References g_smtp_test_err_localtime_r_ctr, localtime_r, and smtp_test_seam_dec_err_ctr().

445  {
447  return NULL;
448  }
449  return localtime_r(timep, result);
450 }
int g_smtp_test_err_localtime_r_ctr
Definition: seams.c:86
#define localtime_r
Definition: seams.h:137
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_malloc()

void* smtp_test_seam_malloc ( size_t  size)

Allows the test harness to control when malloc() fails.

Parameters
[in]sizeNumber of bytes to allocate.
Return values
void*Pointer to new allocated memory.
NULLMemory allocation failed.

Definition at line 460 of file seams.c.

References g_smtp_test_err_malloc_ctr, malloc, and smtp_test_seam_dec_err_ctr().

460  {
462  errno = ENOMEM;
463  return NULL;
464  }
465  return malloc(size);
466 }
#define malloc
Definition: seams.h:145
int g_smtp_test_err_malloc_ctr
Definition: seams.c:91
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_mktime()

time_t smtp_test_seam_mktime ( struct tm *  timeptr)

Allows the test harness to control when mktime() fails.

Parameters
[in]timeptrtm data structure to convert to time_t.
Return values
>=0Time since the epoch.
-1Failed to convert the time.

Definition at line 476 of file seams.c.

References g_smtp_test_err_mktime_ctr, mktime, and smtp_test_seam_dec_err_ctr().

476  {
478  return -1;
479  }
480  return mktime(timeptr);
481 }
int g_smtp_test_err_mktime_ctr
Definition: seams.c:96
#define mktime
Definition: seams.h:153
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_realloc()

void* smtp_test_seam_realloc ( void *  ptr,
size_t  size 
)

Allows the test harness to control when realloc() fails.

Parameters
[in]ptrPreviously allocated memory or NULL memory has not been allocated yet.
[in]sizeNumber of bytes to reallocate.
Return values
void*Pointer to new allocated memory.
NULLMemory allocation failed.

Definition at line 493 of file seams.c.

References g_smtp_test_err_realloc_ctr, realloc, and smtp_test_seam_dec_err_ctr().

494  {
496  errno = ENOMEM;
497  return NULL;
498  }
499  return realloc(ptr, size);
500 }
#define realloc
Definition: seams.h:161
int g_smtp_test_err_realloc_ctr
Definition: seams.c:101
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_recv()

long smtp_test_seam_recv ( int  socket,
void *  buffer,
size_t  length,
int  flags 
)

Allows the test harness to control when recv() fails.

Parameters
[in]socketTCP network socket.
[in]bufferStore received data in this buffer.
[in]lengthNumber of bytes in buffer.
[in]flagsSet this to 0.
Return values
>=0Number of bytes received.
-1Failed to receive bytes over the network.

Definition at line 513 of file seams.c.

References g_smtp_test_err_recv_bytes, g_smtp_test_err_recv_ctr, g_smtp_test_err_recv_rc, recv, smtp_test_seam_dec_err_ctr(), and strlen.

516  {
517  size_t bytes_inject_len;
518 
520  if(g_smtp_test_err_recv_rc != -1){
522  }
524  bytes_inject_len = strlen(g_smtp_test_err_recv_bytes);
525  assert(bytes_inject_len < length && bytes_inject_len < LONG_MAX);
526  memcpy(buffer, g_smtp_test_err_recv_bytes, bytes_inject_len);
527  return (long)bytes_inject_len;
528  }
529  errno = EBADF;
530  return -1;
531  }
532  return recv(socket, buffer, length, flags);
533 }
int g_smtp_test_err_recv_rc
Definition: seams.c:111
enum smtp_flag flags
Definition: smtp.c:154
int g_smtp_test_err_recv_ctr
Definition: seams.c:106
#define recv
Definition: seams.h:169
#define socket
Definition: seams.h:193
char g_smtp_test_err_recv_bytes[90]
Definition: seams.c:116
#define strlen
Definition: seams.h:273
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_select()

int smtp_test_seam_select ( int  nfds,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  errorfds,
struct timeval *  timeout 
)

Allows the test harness to control when select() fails.

Parameters
[in]nfdsCheck for file descriptors in range 0 to (nfds - 1) which have any of the read/write/error conditions.
[in]readfdsChecks for file descriptors in fd_set that have bytes ready for reading.
[in]writefdsChecks for file descriptors in fd_set that have bytes ready for writing.
[in]errorfdsChecks for file descriptors in fd_set that have errors pending.
[in]timeoutWait for the read/write/error conditions in blocking mode until this timeout or an interrupt occurs.
Return values
>=0Number of bits set in the bitmask.
-1An error occurred.

Definition at line 552 of file seams.c.

References g_smtp_test_err_select_ctr, select, and smtp_test_seam_dec_err_ctr().

556  {
558  errno = EINTR;
559  return -1;
560  }
561  return select(nfds, readfds, writefds, errorfds, timeout);
562 }
int g_smtp_test_err_select_ctr
Definition: seams.c:121
#define select
Definition: seams.h:177
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_send()

ssize_t smtp_test_seam_send ( int  socket,
const void *  buffer,
size_t  length,
int  flags 
)

Allows the test harness to control when send() fails.

Parameters
[in]socketTCP network socket.
[in]bufferData to send over the network.
[in]lengthNumber of bytes in buffer.
[in]flagsSet this to 0.
Return values
>=0Number of bytes sent.
-1Failed to send bytes over the network.

Definition at line 575 of file seams.c.

References g_smtp_test_err_send_ctr, g_smtp_test_send_one_byte, send, and smtp_test_seam_dec_err_ctr().

578  {
579  long sent_bytes;
580  size_t bytes_to_send;
581 
583  errno = EBADF;
584  sent_bytes = -1;
585  }
586  else{
587  bytes_to_send = length;
589  bytes_to_send = 1;
590  }
591  sent_bytes = send(socket, buffer, bytes_to_send, flags);
592  }
593  return sent_bytes;
594 }
enum smtp_flag flags
Definition: smtp.c:154
#define socket
Definition: seams.h:193
int g_smtp_test_send_one_byte
Definition: seams.c:131
#define send
Definition: seams.h:185
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
int g_smtp_test_err_send_ctr
Definition: seams.c:126
+ Here is the call graph for this function:

◆ smtp_test_seam_socket()

int smtp_test_seam_socket ( int  domain,
int  type,
int  protocol 
)

Allows the test harness to control when socket() fails.

Parameters
[in]domainSocket domain.
[in]typeSocket type.
[in]protocolSocket protocol.
Return values
!(-1)The file descriptor for the new socket.
-1Failed to create the socket.

Definition at line 606 of file seams.c.

References g_smtp_test_err_socket_ctr, smtp_test_seam_dec_err_ctr(), and socket.

608  {
610  errno = EINVAL;
611  return -1;
612  }
613  return socket(domain, type, protocol);
614 }
#define socket
Definition: seams.h:193
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
int g_smtp_test_err_socket_ctr
Definition: seams.c:154
+ Here is the call graph for this function:

◆ smtp_test_seam_sprintf()

int smtp_test_seam_sprintf ( char *  s,
const char *  format,
  ... 
)

Allows the test harness to control when sprintf() fails.

Parameters
[in]sBuffer to store the output contents to.
[in]formatFormat string defined in sprintf().
Return values
>=0Number of bytes copied to s, excluding the null-terminator.
<0Output or formatting error.

Definition at line 771 of file seams.c.

References g_smtp_test_err_sprintf_ctr, g_smtp_test_err_sprintf_rc, and smtp_test_seam_dec_err_ctr().

772  {
773  va_list ap;
774  int rc;
775 
777  errno = ENOMEM;
779  }
780  va_start(ap, format);
781  rc = vsprintf(s, format, ap);
782  va_end(ap);
783  return rc;
784 }
int g_smtp_test_err_sprintf_ctr
Definition: seams.c:204
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
int g_smtp_test_err_sprintf_rc
Definition: seams.c:209
+ Here is the call graph for this function:

◆ smtp_test_seam_ssl_connect()

int smtp_test_seam_ssl_connect ( SSL *  ssl)

Allows the test harness to control when SSL_connect() fails.

Parameters
[in]sslOpenSSL handle.
Return values
1TLS connection handshake successful.
<1TLS connection handshake failed.

Definition at line 624 of file seams.c.

References g_smtp_test_err_ssl_connect_ctr, smtp_test_seam_dec_err_ctr(), and SSL_connect.

624  {
626  return 0;
627  }
628  return SSL_connect(ssl);
629 }
int g_smtp_test_err_ssl_connect_ctr
Definition: seams.c:160
#define SSL_connect
Definition: seams.h:201
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_ssl_ctx_new()

SSL_CTX* smtp_test_seam_ssl_ctx_new ( const SSL_METHOD *  method)

Allows the test harness to control when SSL_CTX_new() fails.

Parameters
[in]methodTLS connection method.
Return values
SSL_CTX*Pointer to new TLS context.
NULLFailed to create new TLS context.

Definition at line 639 of file seams.c.

References g_smtp_test_err_ssl_ctx_new_ctr, smtp_test_seam_dec_err_ctr(), and SSL_CTX_new.

639  {
641  return NULL;
642  }
643  return SSL_CTX_new(method);
644 }
#define SSL_CTX_new
Definition: seams.h:209
int g_smtp_test_err_ssl_ctx_new_ctr
Definition: seams.c:166
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_ssl_do_handshake()

int smtp_test_seam_ssl_do_handshake ( SSL *  ssl)

Allows the test harness to control when SSL_do_handshake() fails.

Parameters
[in]sslOpenSSL handle.
Return values
1TLS handshake successful.
<1TLS handshake failed.

Definition at line 654 of file seams.c.

References g_smtp_test_err_ssl_do_handshake_ctr, smtp_test_seam_dec_err_ctr(), and SSL_do_handshake.

654  {
656  return 0;
657  }
658  return SSL_do_handshake(ssl);
659 }
#define SSL_do_handshake
Definition: seams.h:217
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
int g_smtp_test_err_ssl_do_handshake_ctr
Definition: seams.c:172
+ Here is the call graph for this function:

◆ smtp_test_seam_ssl_get_peer_certificate()

X509* smtp_test_seam_ssl_get_peer_certificate ( const SSL *  ssl)

Allows the test harness to control when SSL_get_peer_certificate() fails.

Parameters
[in]sslOpenSSL handle.
Return values
X509*Peer certficate which must get freed by using X509_free().
NULLFailed to get the peer certificate.

Definition at line 669 of file seams.c.

References g_smtp_test_err_ssl_get_peer_certificate_ctr, smtp_test_seam_dec_err_ctr(), and SSL_get_peer_certificate.

669  {
671  return NULL;
672  }
673  return SSL_get_peer_certificate(ssl);
674 }
int g_smtp_test_err_ssl_get_peer_certificate_ctr
Definition: seams.c:178
#define SSL_get_peer_certificate
Definition: seams.h:225
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_ssl_new()

SSL* smtp_test_seam_ssl_new ( SSL_CTX *  ctx)

Allows the test harness to control when SSL_new() fails.

Parameters
[in]ctxOpenSSL TLS context.
Return values
SSL*Pointer to a new TLS context.
NULLFailed to create new TLS context.

Definition at line 709 of file seams.c.

References g_smtp_test_err_ssl_new_ctr, smtp_test_seam_dec_err_ctr(), and SSL_new.

709  {
711  return NULL;
712  }
713  return SSL_new(ctx);
714 }
int g_smtp_test_err_ssl_new_ctr
Definition: seams.c:189
#define SSL_new
Definition: seams.h:241
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_ssl_read()

int smtp_test_seam_ssl_read ( SSL *  ssl,
void *  buf,
int  num 
)

Allows the test harness to control when SSL_read() fails.

Parameters
[in]sslOpenSSL TLS object.
[in]bufStore received data in this buffer.
[in]numNumber of bytes in buf.
Return values
>0Number of bytes successfully read from the TLS connection.
<=0Failed to read bytes on the TLS connection.

Definition at line 726 of file seams.c.

References g_smtp_test_err_recv_bytes, g_smtp_test_err_ssl_read_ctr, smtp_test_seam_dec_err_ctr(), SSL_read, and strlen.

728  {
729  size_t bytes_inject_len;
730 
733  bytes_inject_len = strlen(g_smtp_test_err_recv_bytes);
734  assert(bytes_inject_len < (size_t)num && bytes_inject_len < INT_MAX);
735  memcpy(buf, g_smtp_test_err_recv_bytes, bytes_inject_len);
736  return (int)bytes_inject_len;
737  }
738  return -1;
739  }
740  return SSL_read(ssl, buf, num);
741 }
int g_smtp_test_err_ssl_read_ctr
Definition: seams.c:194
#define SSL_read
Definition: seams.h:249
char g_smtp_test_err_recv_bytes[90]
Definition: seams.c:116
#define strlen
Definition: seams.h:273
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_ssl_write()

int smtp_test_seam_ssl_write ( SSL *  ssl,
const void *  buf,
int  num 
)

Allows the test harness to control when SSL_write() fails.

Parameters
[in]sslOpenSSL TLS object.
[in]bufData to write to the TLS connection.
[in]numNumber of bytes in buf.
Return values
>0Number of bytes successfully written to the TLS connection.
<=0Failed to write bytes to the TLS connection.

Definition at line 753 of file seams.c.

References g_smtp_test_err_ssl_write_ctr, smtp_test_seam_dec_err_ctr(), and SSL_write.

755  {
757  return -1;
758  }
759  return SSL_write(ssl, buf, num);
760 }
#define SSL_write
Definition: seams.h:257
int g_smtp_test_err_ssl_write_ctr
Definition: seams.c:199
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

◆ smtp_test_seam_strlen()

size_t smtp_test_seam_strlen ( const char *  s)

Allows the test harness to control the return value of strlen().

Parameters
[in]sNull-terminated string.
Returns
Length of s.

Definition at line 793 of file seams.c.

References g_smtp_test_strlen_custom_ret, g_smtp_test_strlen_ret_value, and strlen.

793  {
794  size_t result;
795 
798  }
799  else{
800  result = strlen(s);
801  }
802  return result;
803 }
int g_smtp_test_strlen_custom_ret
Definition: seams.c:214
size_t g_smtp_test_strlen_ret_value
Definition: seams.c:219
#define strlen
Definition: seams.h:273

◆ smtp_test_seam_time()

time_t smtp_test_seam_time ( time_t *  tloc)

Allows the test harness to control when time() fails.

Parameters
[out]tlocBuffer to hold the time_t results.
Return values
>=0Time in seconds since the Epoch.
-1Failed to store the time in tloc.

Definition at line 813 of file seams.c.

References g_smtp_test_time_custom_ret, g_smtp_test_time_ret_value, and time.

813  {
816  }
817  return time(tloc);
818 }
#define time
Definition: seams.h:281
int g_smtp_test_time_custom_ret
Definition: seams.c:224
time_t g_smtp_test_time_ret_value
Definition: seams.c:229

◆ smtp_test_seam_x509_check_host()

int smtp_test_seam_x509_check_host ( X509 *  cert,
const char *  name,
size_t  namelen,
unsigned int  flags,
char **  peername 
)

Allows the test harness to control when X509_check_host() fails.

Parameters
[in]certX509 certificate handle.
[in]nameServer name.
[in]namelenNumber of characters in name or 0 if null-terminated.
[in]flagsUsually set to 0.
[in]peernamePointer to CN from certificate stored in this buffer if not NULL.
Return values
1Successful host check.
0Failed host check.
-1Internal error.

Definition at line 690 of file seams.c.

References g_smtp_test_err_x509_check_host_ctr, smtp_test_seam_dec_err_ctr(), and X509_check_host.

694  {
696  return -1;
697  }
698  return X509_check_host(cert, name, namelen, flags, peername);
699 }
enum smtp_flag flags
Definition: smtp.c:154
int g_smtp_test_err_x509_check_host_ctr
Definition: seams.c:184
#define X509_check_host
Definition: seams.h:233
int smtp_test_seam_dec_err_ctr(int *const test_err_ctr)
Definition: seams.c:244
+ Here is the call graph for this function:

Variable Documentation

◆ g_smtp_test_err_bio_new_socket_ctr

int g_smtp_test_err_bio_new_socket_ctr = -1

◆ g_smtp_test_err_bio_should_retry_ctr

int g_smtp_test_err_bio_should_retry_ctr = -1

◆ g_smtp_test_err_bio_should_retry_rc

int g_smtp_test_err_bio_should_retry_rc = -1

◆ g_smtp_test_err_calloc_ctr

◆ g_smtp_test_err_close_ctr

int g_smtp_test_err_close_ctr = -1

◆ g_smtp_test_err_connect_ctr

int g_smtp_test_err_connect_ctr = -1

◆ g_smtp_test_err_err_peek_error_ctr

int g_smtp_test_err_err_peek_error_ctr = -1

◆ g_smtp_test_err_fclose_ctr

int g_smtp_test_err_fclose_ctr = -1

◆ g_smtp_test_err_ferror_ctr

int g_smtp_test_err_ferror_ctr = -1

◆ g_smtp_test_err_gmtime_r_ctr

int g_smtp_test_err_gmtime_r_ctr = -1

◆ g_smtp_test_err_hmac_ctr

int g_smtp_test_err_hmac_ctr = -1

◆ g_smtp_test_err_localtime_r_ctr

int g_smtp_test_err_localtime_r_ctr = -1

◆ g_smtp_test_err_malloc_ctr

◆ g_smtp_test_err_mktime_ctr

int g_smtp_test_err_mktime_ctr = -1

◆ g_smtp_test_err_realloc_ctr

◆ g_smtp_test_err_recv_bytes

char g_smtp_test_err_recv_bytes[90] = {0}

◆ g_smtp_test_err_recv_ctr

int g_smtp_test_err_recv_ctr = -1

◆ g_smtp_test_err_recv_rc

int g_smtp_test_err_recv_rc = -1

See g_smtp_test_err_recv_rc.

Definition at line 111 of file seams.c.

Referenced by smtp_test_seam_recv(), and test_failure_open().

◆ g_smtp_test_err_select_ctr

int g_smtp_test_err_select_ctr = -1

◆ g_smtp_test_err_send_ctr

◆ g_smtp_test_err_si_add_size_t_ctr

◆ g_smtp_test_err_si_mul_size_t_ctr

int g_smtp_test_err_si_mul_size_t_ctr = -1

◆ g_smtp_test_err_si_sub_size_t_ctr

int g_smtp_test_err_si_sub_size_t_ctr = -1

◆ g_smtp_test_err_socket_ctr

int g_smtp_test_err_socket_ctr = -1

◆ g_smtp_test_err_sprintf_ctr

int g_smtp_test_err_sprintf_ctr = -1

◆ g_smtp_test_err_sprintf_rc

int g_smtp_test_err_sprintf_rc = 0

◆ g_smtp_test_err_ssl_connect_ctr

int g_smtp_test_err_ssl_connect_ctr = -1

◆ g_smtp_test_err_ssl_ctx_new_ctr

int g_smtp_test_err_ssl_ctx_new_ctr = -1

◆ g_smtp_test_err_ssl_do_handshake_ctr

int g_smtp_test_err_ssl_do_handshake_ctr = -1

◆ g_smtp_test_err_ssl_get_peer_certificate_ctr

int g_smtp_test_err_ssl_get_peer_certificate_ctr = -1

◆ g_smtp_test_err_ssl_new_ctr

int g_smtp_test_err_ssl_new_ctr = -1

◆ g_smtp_test_err_ssl_read_ctr

int g_smtp_test_err_ssl_read_ctr = -1

◆ g_smtp_test_err_ssl_write_ctr

◆ g_smtp_test_err_x509_check_host_ctr

int g_smtp_test_err_x509_check_host_ctr = -1

◆ g_smtp_test_send_one_byte

int g_smtp_test_send_one_byte = 0

See g_smtp_test_send_one_byte.

Definition at line 131 of file seams.c.

Referenced by smtp_func_test_all_write(), and smtp_test_seam_send().

◆ g_smtp_test_strlen_custom_ret

◆ g_smtp_test_strlen_ret_value

◆ g_smtp_test_time_custom_ret

int g_smtp_test_time_custom_ret = 0

See g_smtp_test_time_custom_ret.

Definition at line 224 of file seams.c.

Referenced by smtp_test_seam_time(), and smtp_unit_test_date_rfc_2822().

◆ g_smtp_test_time_ret_value

time_t g_smtp_test_time_ret_value = 0

See g_smtp_test_time_ret_value.

Definition at line 229 of file seams.c.

Referenced by smtp_test_seam_time(), and smtp_unit_test_date_rfc_2822().