diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-11-19 15:45:12 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-11-20 09:26:47 -0500 |
commit | 89c355b38601e0eda4e999219946bf2431d5de51 (patch) | |
tree | 12f1c44a0dfad5492a0e282c43d78c70e87b3e34 /src/test/test_options_act.c | |
parent | a30d143228b4211fd24093c244117e07e9409de5 (diff) | |
download | tor-89c355b38601e0eda4e999219946bf2431d5de51.tar.gz tor-89c355b38601e0eda4e999219946bf2431d5de51.zip |
Some tests for log changes, commit, and rollback
Diffstat (limited to 'src/test/test_options_act.c')
-rw-r--r-- | src/test/test_options_act.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/test/test_options_act.c b/src/test/test_options_act.c index abc1c65481..0a9be28c54 100644 --- a/src/test/test_options_act.c +++ b/src/test/test_options_act.c @@ -6,6 +6,7 @@ #define CONFIG_PRIVATE #include "core/or/or.h" #include "app/config/config.h" +#include "lib/encoding/confline.h" #include "test/test.h" #include "test/log_test_helpers.h" @@ -167,11 +168,105 @@ test_options_act_create_dirs(void *arg) tor_free(msg); } +static void +test_options_act_log_transition(void *arg) +{ + (void)arg; + or_options_t *opts = mock_opts = options_new(); + or_options_t *old_opts = NULL; + opts->LogTimeGranularity = 1000; + opts->SafeLogging_ = SAFELOG_SCRUB_ALL; + struct log_transaction_t *lt = NULL; + char *msg = NULL; + MOCK(get_options, mock_get_options); + + tt_ptr_op(opts->Logs, OP_EQ, NULL); + config_line_append(&opts->Logs, "Log", "notice stdout"); + lt = options_start_log_transaction(NULL, &msg); + tt_assert(lt); + tt_assert(!msg); + + // commit, see that there is a change. + options_commit_log_transaction(lt); + lt=NULL; + tt_int_op(get_min_log_level(), OP_EQ, LOG_NOTICE); + + // Now drop to debug. + old_opts = opts; + opts = mock_opts = options_new(); + opts->LogTimeGranularity = 1000; + opts->SafeLogging_ = SAFELOG_SCRUB_ALL; + config_line_append(&opts->Logs, "Log", "debug stdout"); + lt = options_start_log_transaction(old_opts, &msg); + tt_assert(lt); + tt_assert(!msg); + + setup_full_capture_of_logs(LOG_NOTICE); + options_commit_log_transaction(lt); + lt=NULL; + expect_single_log_msg_containing("may contain sensitive information"); + tt_int_op(get_min_log_level(), OP_EQ, LOG_DEBUG); + + // Turn off SafeLogging + or_options_free(old_opts); + mock_clean_saved_logs(); + old_opts = opts; + opts = mock_opts = options_new(); + opts->SafeLogging_ = SAFELOG_SCRUB_NONE; + opts->LogTimeGranularity = 1000; + config_line_append(&opts->Logs, "Log", "debug stdout"); + lt = options_start_log_transaction(old_opts, &msg); + tt_assert(lt); + tt_assert(!msg); + options_commit_log_transaction(lt); + lt=NULL; + expect_single_log_msg_containing("may contain sensitive information"); + tt_int_op(get_min_log_level(), OP_EQ, LOG_DEBUG); + + // Try rolling back. + or_options_free(old_opts); + mock_clean_saved_logs(); + old_opts = opts; + opts = mock_opts = options_new(); + opts->SafeLogging_ = SAFELOG_SCRUB_NONE; + opts->LogTimeGranularity = 1000; + config_line_append(&opts->Logs, "Log", "notice stdout"); + lt = options_start_log_transaction(old_opts, &msg); + tt_assert(lt); + tt_assert(!msg); + options_rollback_log_transaction(lt); + expect_no_log_entry(); + lt = NULL; + tt_int_op(get_min_log_level(), OP_EQ, LOG_DEBUG); + + // Now try some bad options. + or_options_free(opts); + mock_clean_saved_logs(); + opts = mock_opts = options_new(); + opts->LogTimeGranularity = 1000; + config_line_append(&opts->Logs, "Log", "warn blaznert"); + lt = options_start_log_transaction(old_opts, &msg); + tt_assert(!lt); + tt_str_op(msg, OP_EQ, "Failed to init Log options. See logs for details."); + expect_single_log_msg_containing("Couldn't parse"); + tt_int_op(get_min_log_level(), OP_EQ, LOG_DEBUG); + + done: + UNMOCK(get_options); + or_options_free(opts); + or_options_free(old_opts); + tor_free(msg); + if (lt) + options_rollback_log_transaction(lt); + teardown_capture_of_logs(); +} + #ifndef COCCI #define T(name) { #name, test_options_act_##name, TT_FORK, NULL, NULL } #endif struct testcase_t options_act_tests[] = { T(create_dirs), + T(log_transition), END_OF_TESTCASES }; |