LCOV - code coverage report
Current view: top level - test - test_proto_haproxy.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 28 28 100.0 %
Date: 2021-11-24 03:28:48 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* Copyright (c) 2019-2021, The Tor Project, Inc. */
       2             : /* See LICENSE for licensing information */
       3             : 
       4             : /**
       5             :  * \file test_proto_haproxy.c
       6             :  * \brief Tests for our HAProxy protocol parser code
       7             :  */
       8             : 
       9             : #define PROTO_HAPROXY_PRIVATE
      10             : 
      11             : #include "test/test.h"
      12             : #include "core/proto/proto_haproxy.h"
      13             : #include "test/log_test_helpers.h"
      14             : 
      15             : static void
      16           1 : test_format_proxy_header_line(void *arg)
      17             : {
      18           1 :   tor_addr_t addr;
      19           1 :   tor_addr_port_t *addr_port = NULL;
      20           1 :   char *output = NULL;
      21             : 
      22           1 :   (void) arg;
      23             : 
      24             :   /* IPv4 address. */
      25           1 :   tor_addr_parse(&addr, "192.168.1.2");
      26           1 :   addr_port = tor_addr_port_new(&addr, 8000);
      27           1 :   output = haproxy_format_proxy_header_line(addr_port);
      28             : 
      29           1 :   tt_str_op(output, OP_EQ, "PROXY TCP4 0.0.0.0 192.168.1.2 0 8000\r\n");
      30             : 
      31           1 :   tor_free(addr_port);
      32           1 :   tor_free(output);
      33             : 
      34             :   /* IPv6 address. */
      35           1 :   tor_addr_parse(&addr, "123:45:6789::5005:11");
      36           1 :   addr_port = tor_addr_port_new(&addr, 8000);
      37           1 :   output = haproxy_format_proxy_header_line(addr_port);
      38             : 
      39           1 :   tt_str_op(output, OP_EQ, "PROXY TCP6 :: 123:45:6789::5005:11 0 8000\r\n");
      40             : 
      41           1 :   tor_free(addr_port);
      42           1 :   tor_free(output);
      43             : 
      44             :   /* UNIX socket address. */
      45           1 :   memset(&addr, 0, sizeof(addr));
      46           1 :   addr.family = AF_UNIX;
      47           1 :   addr_port = tor_addr_port_new(&addr, 8000);
      48           1 :   output = haproxy_format_proxy_header_line(addr_port);
      49             : 
      50             :   /* If it's not an IPv4 or IPv6 address, haproxy_format_proxy_header_line
      51             :    * must return NULL. */
      52           1 :   tt_ptr_op(output, OP_EQ, NULL);
      53             : 
      54           1 :   tor_free(addr_port);
      55           1 :   tor_free(output);
      56             : 
      57           1 :  done:
      58           1 :   tor_free(addr_port);
      59           1 :   tor_free(output);
      60           1 : }
      61             : 
      62             : struct testcase_t proto_haproxy_tests[] = {
      63             :   { "format_proxy_header_line", test_format_proxy_header_line, 0, NULL, NULL },
      64             : 
      65             :   END_OF_TESTCASES
      66             : };

Generated by: LCOV version 1.14