diff options
author | David Goulet <dgoulet@torproject.org> | 2017-01-13 11:20:31 -0500 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2017-07-13 16:49:08 -0400 |
commit | 93774dcb5458115652e0be5cdfaf198967b8a31e (patch) | |
tree | a2a8655730a5affb08ffc478aacc57451cd9e7da /src/test/test_helpers.c | |
parent | 74193b932115a82417dc312721ffe0a10a7ed6dc (diff) | |
download | tor-93774dcb5458115652e0be5cdfaf198967b8a31e.tar.gz tor-93774dcb5458115652e0be5cdfaf198967b8a31e.zip |
test: Add HS v2 service configuration unit tests
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/test/test_helpers.c')
-rw-r--r-- | src/test/test_helpers.c | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/test/test_helpers.c b/src/test/test_helpers.c index 22d9de3f5b..e885d27815 100644 --- a/src/test/test_helpers.c +++ b/src/test/test_helpers.c @@ -7,18 +7,21 @@ */ #define ROUTERLIST_PRIVATE +#define CONFIG_PRIVATE #define CONNECTION_PRIVATE #define MAIN_PRIVATE #include "orconfig.h" #include "or.h" +#include "buffers.h" +#include "config.h" +#include "confparse.h" #include "connection.h" #include "main.h" +#include "nodelist.h" #include "relay.h" #include "routerlist.h" -#include "nodelist.h" -#include "buffers.h" #include "test.h" #include "test_helpers.h" @@ -239,3 +242,38 @@ test_conn_get_connection(uint8_t state, uint8_t type, uint8_t purpose) return NULL; } +/* Helper function to parse a set of torrc options in a text format and return + * a newly allocated or_options_t object containing the configuration. On + * error, NULL is returned indicating that the conf couldn't be parsed + * properly. */ +or_options_t * +helper_parse_options(const char *conf) +{ + int ret = 0; + char *msg = NULL; + or_options_t *opt = NULL; + config_line_t *line = NULL; + + /* Kind of pointless to call this with a NULL value. */ + tt_assert(conf); + + opt = options_new(); + tt_assert(opt); + ret = config_get_lines(conf, &line, 1); + if (ret != 0) { + goto done; + } + ret = config_assign(&options_format, opt, line, 0, &msg); + if (ret != 0) { + goto done; + } + + done: + config_free_lines(line); + if (ret != 0) { + or_options_free(opt); + opt = NULL; + } + return opt; +} + |