diff options
author | Suphanat Chunhapanya <haxx.pop@gmail.com> | 2019-09-10 15:32:08 +0800 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2020-01-06 13:39:10 -0500 |
commit | 41b9dca07bb7dea4758cf97f9bbff7a52b09ebf4 (patch) | |
tree | e19beb0c79fcf1d2c11c32eea64533a9aa466bca /src/test/test_proto_haproxy.c | |
parent | 119004e87d6303de5e90e7dfad87dd89bae6bd5f (diff) | |
download | tor-41b9dca07bb7dea4758cf97f9bbff7a52b09ebf4.tar.gz tor-41b9dca07bb7dea4758cf97f9bbff7a52b09ebf4.zip |
test: Implement haproxy
Diffstat (limited to 'src/test/test_proto_haproxy.c')
-rw-r--r-- | src/test/test_proto_haproxy.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/test/test_proto_haproxy.c b/src/test/test_proto_haproxy.c new file mode 100644 index 0000000000..653bf67e23 --- /dev/null +++ b/src/test/test_proto_haproxy.c @@ -0,0 +1,66 @@ +/* Copyright (c) 2019, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file test_proto_haproxy.c + * \brief Tests for our HAProxy protocol parser code + */ + +#define PROTO_HAPROXY_PRIVATE + +#include "test/test.h" +#include "core/proto/proto_haproxy.h" +#include "test/log_test_helpers.h" + +static void +test_format_proxy_header_line(void *arg) +{ + tor_addr_t addr; + tor_addr_port_t *addr_port = NULL; + char *output = NULL; + + (void) arg; + + /* IPv4 address. */ + tor_addr_parse(&addr, "192.168.1.2"); + addr_port = tor_addr_port_new(&addr, 8000); + output = haproxy_format_proxy_header_line(addr_port); + + tt_str_op(output, OP_EQ, "PROXY TCP4 0.0.0.0 192.168.1.2 0 8000\r\n"); + + tor_free(addr_port); + tor_free(output); + + /* IPv6 address. */ + tor_addr_parse(&addr, "123:45:6789::5005:11"); + addr_port = tor_addr_port_new(&addr, 8000); + output = haproxy_format_proxy_header_line(addr_port); + + tt_str_op(output, OP_EQ, "PROXY TCP6 :: 123:45:6789::5005:11 0 8000\r\n"); + + tor_free(addr_port); + tor_free(output); + + /* UNIX socket address. */ + memset(&addr, 0, sizeof(addr)); + addr.family = AF_UNIX; + addr_port = tor_addr_port_new(&addr, 8000); + output = haproxy_format_proxy_header_line(addr_port); + + /* If it's not an IPv4 or IPv6 address, haproxy_format_proxy_header_line + * must return NULL. */ + tt_ptr_op(output, OP_EQ, NULL); + + tor_free(addr_port); + tor_free(output); + + done: + tor_free(addr_port); + tor_free(output); +} + +struct testcase_t proto_haproxy_tests[] = { + { "format_proxy_header_line", test_format_proxy_header_line, 0, NULL, NULL }, + + END_OF_TESTCASES +}; |