diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-08-01 16:24:20 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-08-15 12:03:37 -0400 |
commit | 636aeb1f24fadd4c6c45dbfd1539f6312c91cc60 (patch) | |
tree | 363b999e32db823a41d858eb62af70c42d9acd99 /src | |
parent | ba78a3c800477efeb9abe8aac477f92bc2634570 (diff) | |
download | tor-636aeb1f24fadd4c6c45dbfd1539f6312c91cc60.tar tor-636aeb1f24fadd4c6c45dbfd1539f6312c91cc60.tar.gz |
Test for initializing ext_or_auth_cookie file
Diffstat (limited to 'src')
-rw-r--r-- | src/test/test_extorport.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/test/test_extorport.c b/src/test/test_extorport.c index 254ad0511..04524215e 100644 --- a/src/test/test_extorport.c +++ b/src/test/test_extorport.c @@ -7,6 +7,7 @@ #include "or.h" #include "buffers.h" #include "connection.h" +#include "config.h" #include "control.h" #include "ext_orport.h" #include "main.h" @@ -148,6 +149,51 @@ test_ext_or_write_command(void *arg) } static void +test_ext_or_init_auth(void *arg) +{ + or_options_t *options = get_options_mutable(); + const char *fn; + char *cp = NULL; + struct stat st; + char cookie0[32]; + (void)arg; + + /* Check default filename location */ + options->DataDirectory = tor_strdup("foo"); + cp = get_ext_or_auth_cookie_file_name(); + tt_str_op(cp, ==, "foo"PATH_SEPARATOR"extended_orport_auth_cookie"); + tor_free(cp); + + /* Shouldn't be initialized already, or our tests will be a bit + * meaningless */ + test_assert(tor_mem_is_zero(ext_or_auth_cookie, 32)); + + /* Now make sure we use a temporary file */ + fn = get_fname("ext_cookie_file"); + options->ExtORPortCookieAuthFile = tor_strdup(fn); + cp = get_ext_or_auth_cookie_file_name(); + tt_str_op(cp, ==, fn); + tor_free(cp); + + tt_int_op(0, ==, init_ext_or_cookie_authentication(1)); + tt_int_op(ext_or_auth_cookie_is_set, ==, 1); + cp = read_file_to_str(fn, RFTS_BIN, &st); + tt_ptr_op(cp, !=, NULL); + tt_int_op(st.st_size, ==, 64); + test_memeq(cp, "! Extended ORPort Auth Cookie !\x0a", 32); + test_memeq(cp+32, ext_or_auth_cookie, 32); + memcpy(cookie0, ext_or_auth_cookie, 32); + test_assert(!tor_mem_is_zero(ext_or_auth_cookie, 32)); + + /* Operation should be idempotent. */ + tt_int_op(0, ==, init_ext_or_cookie_authentication(1)); + test_memeq(cookie0, ext_or_auth_cookie, 32); + + done: + tor_free(cp); +} + +static void test_ext_or_cookie_auth(void *arg) { char *reply=NULL, *reply2=NULL, *client_hash=NULL, *client_hash2=NULL; @@ -409,6 +455,7 @@ test_ext_or_handshake(void *arg) struct testcase_t extorport_tests[] = { { "id_map", test_ext_or_id_map, TT_FORK, NULL, NULL }, { "write_command", test_ext_or_write_command, TT_FORK, NULL, NULL }, + { "init_auth", test_ext_or_init_auth, TT_FORK, NULL, NULL }, { "cookie_auth", test_ext_or_cookie_auth, TT_FORK, NULL, NULL }, { "cookie_auth_testvec", test_ext_or_cookie_auth_testvec, TT_FORK, NULL, NULL }, |