diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-06-23 11:40:20 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-06-23 12:34:33 +0000 |
commit | a48e0c4d1892eebf356108504c0b7fe6c0175b5e (patch) | |
tree | d901ec9b5def9f900d67a5ec449d22bd78ce29b4 /auto_tests/invalid_tcp_proxy_test.c | |
parent | 36e20e7e94760b48bee4894cced30814d72c1938 (diff) |
Add tests for what happens when passing an invalid proxy host.
Related: https://github.com/qTox/qTox/issues/5174
Diffstat (limited to 'auto_tests/invalid_tcp_proxy_test.c')
-rw-r--r-- | auto_tests/invalid_tcp_proxy_test.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/auto_tests/invalid_tcp_proxy_test.c b/auto_tests/invalid_tcp_proxy_test.c new file mode 100644 index 00000000..edbc3237 --- /dev/null +++ b/auto_tests/invalid_tcp_proxy_test.c | |||
@@ -0,0 +1,45 @@ | |||
1 | // Test to make sure that when UDP is disabled, and we set an invalid proxy, | ||
2 | // i.e. one that doesn't run a proxy server, then we don't get any connection. | ||
3 | #ifndef _XOPEN_SOURCE | ||
4 | #define _XOPEN_SOURCE 600 | ||
5 | #endif | ||
6 | |||
7 | #include "helpers.h" | ||
8 | |||
9 | static uint8_t const key[] = { | ||
10 | 0x15, 0xE9, 0xC3, 0x09, 0xCF, 0xCB, 0x79, 0xFD, | ||
11 | 0xDF, 0x0E, 0xBA, 0x05, 0x7D, 0xAB, 0xB4, 0x9F, | ||
12 | 0xE1, 0x5F, 0x38, 0x03, 0xB1, 0xBF, 0xF0, 0x65, | ||
13 | 0x36, 0xAE, 0x2E, 0x5B, 0xA5, 0xE4, 0x69, 0x0E, | ||
14 | }; | ||
15 | |||
16 | // Try to bootstrap for 30 seconds. | ||
17 | #define NUM_ITERATIONS (unsigned)(30.0 / (ITERATION_INTERVAL / 1000.0)) | ||
18 | |||
19 | int main(void) | ||
20 | { | ||
21 | setvbuf(stdout, nullptr, _IONBF, 0); | ||
22 | |||
23 | struct Tox_Options *opts = tox_options_new(nullptr); | ||
24 | tox_options_set_udp_enabled(opts, false); | ||
25 | tox_options_set_proxy_type(opts, TOX_PROXY_TYPE_SOCKS5); | ||
26 | tox_options_set_proxy_host(opts, "localhost"); | ||
27 | tox_options_set_proxy_port(opts, 51724); | ||
28 | Tox *tox = tox_new_log(opts, nullptr, nullptr); | ||
29 | tox_options_free(opts); | ||
30 | |||
31 | tox_add_tcp_relay(tox, "tox.ngc.zone", 33445, key, nullptr); | ||
32 | tox_bootstrap(tox, "tox.ngc.zone", 33445, key, nullptr); | ||
33 | |||
34 | printf("Waiting for connection\n"); | ||
35 | |||
36 | for (unsigned i = 0; i < NUM_ITERATIONS; i++) { | ||
37 | tox_iterate(tox, nullptr); | ||
38 | c_sleep(ITERATION_INTERVAL); | ||
39 | // None of the iterations should have a connection. | ||
40 | assert(tox_self_get_connection_status(tox) == TOX_CONNECTION_NONE); | ||
41 | } | ||
42 | |||
43 | tox_kill(tox); | ||
44 | return 0; | ||
45 | } | ||