Hash :
5e750f29
Author :
Date :
2019-03-24T16:47:46
Enable -Weverything and eliminate warnings Only a few warnings have been disabled in the Makefile. Also changed the smtp_attachment_add_mem interface to use a size_t for the datasz parameter.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
/**
* @file
* @brief Test the smtp-client library.
* @author James Humphrey (mail@somnisoft.com)
* @version 1.00
*
* This smtp-client testing framework has 100% branch coverage on POSIX
* systems. It requires a Postfix SMTP server that supports all of the
* connection security and authentication methods. These functional tests
* also require the user to manually check and ensure that the destination
* addresses received all of the test emails.
*
* This software has been placed into the public domain using CC0.
*
* @section test_seams_countdown_global
*
* The test harnesses control most of the test seams through the use of
* global counter values.
*
* Setting a global counter to -1 will make the test seam function operate
* as it normally would. If set to a positive value, the value will continue
* to decrement every time the function gets called. When the counter reaches
* 0, the test seam will force the function to return an error value.
*
* For example, initially setting the counter to 0 will force the test seam
* to return an error condition the first time it gets called. Setting the
* value to 1 initially will force the test seam to return an error condition
* on the second time it gets called.
*/
#ifndef SMTP_TEST_H
#define SMTP_TEST_H
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "../src/smtp.h"
#ifdef SMTP_OPENSSL
# include <openssl/bio.h>
# include <openssl/err.h>
# include <openssl/ssl.h>
# include <openssl/x509.h>
# include <openssl/x509v3.h>
#endif /* SMTP_OPENSSL */
struct smtp_command;
struct str_getdelimfd;
int
smtp_si_add_size_t(const size_t a,
const size_t b,
size_t *const result);
int
smtp_si_sub_size_t(const size_t a,
const size_t b,
size_t *const result);
int
smtp_si_mul_size_t(const size_t a,
const size_t b,
size_t *const result);
size_t
smtp_base64_decode(const char *const buf,
unsigned char **decode);
char *
smtp_base64_encode(const char *const buf,
size_t buflen);
char *
smtp_bin2hex(const unsigned char *const s,
size_t slen);
enum smtp_status_code
smtp_write(struct smtp *const smtp,
const char *const buf,
size_t len);
int
smtp_str_getdelimfd(struct str_getdelimfd *const gdfd);
int
smtp_str_getdelimfd_set_line_and_buf(struct str_getdelimfd *const gdfd,
size_t copy_len);
void
smtp_str_getdelimfd_free(struct str_getdelimfd *const gdfd);
char *
smtp_stpcpy(char *s1,
const char *s2);
void *
smtp_reallocarray(void *ptr,
size_t nmemb,
size_t size);
char *
smtp_strdup(const char *s);
char *
smtp_str_replace(const char *const search,
const char *const replace,
const char *const s);
size_t
smtp_utf8_charlen(char c);
int
smtp_str_has_nonascii_utf8(const char *const s);
size_t
smtp_strnlen_utf8(const char *s,
size_t maxlen);
size_t
smtp_fold_whitespace_get_offset(const char *const s,
unsigned int maxlen);
char *
smtp_fold_whitespace(const char *const s,
unsigned int maxlen);
char *
smtp_chunk_split(const char *const s,
size_t chunklen,
const char *const end);
char *
smtp_ffile_get_contents(FILE *stream,
size_t *bytes_read);
char *
smtp_file_get_contents(const char *const filename,
size_t *bytes_read);
int
smtp_parse_cmd_line(char *const line,
struct smtp_command *const cmd);
int
smtp_date_rfc_2822(char *const date);
int
smtp_address_validate_email(const char *const email);
int
smtp_address_validate_name(const char *const name);
int
smtp_attachment_validate_name(const char *const name);
int
smtp_header_key_validate(const char *const key);
int
smtp_header_value_validate(const char *const value);
/* test seams */
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);
/**
* Counter for @ref smtp_test_seam_bio_new_socket.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_bio_new_socket_ctr;
/**
* Counter for @ref smtp_test_seam_bio_should_retry.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_bio_should_retry_ctr;
/**
* Value to force the BIO_should_retry() function to return.
*
* This value will only get returned if
* @ref g_smtp_test_err_bio_should_retry_ctr
* has a value of 0 and this does not have a value of -1.
*/
extern int g_smtp_test_err_bio_should_retry_rc;
/**
* Counter for @ref smtp_test_seam_calloc.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_calloc_ctr;
/**
* Counter for @ref smtp_test_seam_close.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_close_ctr;
/**
* Counter for @ref smtp_test_seam_connect.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_connect_ctr;
/**
* Counter for @ref smtp_test_seam_err_peek_error.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_err_peek_error_ctr;
/**
* Counter for @ref smtp_test_seam_fclose.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_fclose_ctr;
/**
* Counter for @ref smtp_test_seam_ferror.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_ferror_ctr;
/**
* Counter for @ref smtp_test_seam_gmtime_r.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_gmtime_r_ctr;
/**
* Counter for @ref smtp_test_seam_hmac.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_hmac_ctr;
/**
* Counter for @ref smtp_test_seam_localtime_r.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_localtime_r_ctr;
/**
* Counter for @ref smtp_test_seam_malloc.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_malloc_ctr;
/**
* Counter for @ref smtp_test_seam_mktime.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_mktime_ctr;
/**
* Counter for @ref smtp_test_seam_realloc.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_realloc_ctr;
/**
* Counter for @ref smtp_test_seam_recv.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_recv_ctr;
/**
* Value to force the recv() function to return.
*
* This value will only get returned if
* @ref g_smtp_test_err_recv_ctr
* has a value of 0 and this does not have a value of -1.
*/
extern int g_smtp_test_err_recv_rc;
/**
* Set the received bytes in recv() and SSL_read() to this value if it
* contains a null-terminated string at least one bytes long.
*
* This makes it easier to inject a bad server response for testing the
* smtp-client handling of those bad responses.
*
* See @ref test_seams_countdown_global for more details.
*/
extern char g_smtp_test_err_recv_bytes[90];
/**
* Counter for @ref smtp_test_seam_select.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_select_ctr;
/**
* Counter for @ref smtp_test_seam_send.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_send_ctr;
/**
* Indicate if we should only send one byte at a time.
*/
extern int g_smtp_test_send_one_byte;
/**
* Counter for @ref smtp_si_add_size_t.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_si_add_size_t_ctr;
/**
* Counter for @ref smtp_si_sub_size_t.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_si_sub_size_t_ctr;
/**
* Counter for @ref smtp_si_mul_size_t.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_si_mul_size_t_ctr;
/**
* Counter for @ref smtp_test_seam_socket.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_socket_ctr;
/**
* Counter for @ref smtp_test_seam_ssl_connect.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_ssl_connect_ctr;
/**
* Counter for @ref smtp_test_seam_ssl_ctx_new.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_ssl_ctx_new_ctr;
/**
* Counter for @ref smtp_test_seam_ssl_do_handshake.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_ssl_do_handshake_ctr;
/**
* Counter for @ref smtp_test_seam_ssl_get_peer_certificate.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_ssl_get_peer_certificate_ctr;
/**
* Counter for @ref smtp_test_seam_x509_check_host.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_x509_check_host_ctr;
/**
* Counter for @ref smtp_test_seam_ssl_new.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_ssl_new_ctr;
/**
* Counter for @ref smtp_test_seam_ssl_read.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_ssl_read_ctr;
/**
* Counter for @ref smtp_test_seam_ssl_write.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_ssl_write_ctr;
/**
* Counter for @ref smtp_test_seam_sprintf.
*
* See @ref test_seams_countdown_global for more details.
*/
extern int g_smtp_test_err_sprintf_ctr;
/**
* Value to force the sprintf() function to return.
*
* This value will only get returned if @ref g_smtp_test_err_sprintf_ctr has
* a value of 0.
*/
extern int g_smtp_test_err_sprintf_rc;
/**
* Indicates if the strlen() function should return a test value.
*
* This can get set to one of two values:
* - 0 - The strlen() function will operate normally.
* - !0 - The strlen() function will return the value specified in
* @ref g_smtp_test_strlen_ret_value.
*/
extern int g_smtp_test_strlen_custom_ret;
/**
* Value to force the strlen() function to return.
*
* This value will only get returned if @ref g_smtp_test_strlen_custom_ret
* has been set.
*/
extern size_t g_smtp_test_strlen_ret_value;
/**
* Indicates if the time() function should return a custom value.
*
* This can get set to one of two values:
* - 0 - The time() function will operate normally.
* - !0 - The time() function will return the value specified in
* @ref g_smtp_test_time_ret_value.
*/
extern int g_smtp_test_time_custom_ret;
/**
* Value to force the time() function to return.
*
* This value will only get returned if @ref g_smtp_test_time_custom_ret has
* a positive value.
*/
extern time_t g_smtp_test_time_ret_value;
#endif /* SMTP_TEST_H */