aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_sendme.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2019-05-07 09:44:10 -0400
committerNick Mathewson <nickm@torproject.org>2019-05-22 11:47:20 -0400
commit44265dd6716887b997bb03d2db1641efd7ae9c19 (patch)
tree35c6f54c71deb7442f8d489c4e7b4f6a5d00a093 /src/test/test_sendme.c
parent69e0d5bfc7d52f223d686bcd87f629f01b03561a (diff)
downloadtor-44265dd6716887b997bb03d2db1641efd7ae9c19.tar.gz
tor-44265dd6716887b997bb03d2db1641efd7ae9c19.zip
sendme: Never fallback to v0 if unknown version
There was a missing cell version check against our max supported version. In other words, we do not fallback to v0 anymore in case we do know the SENDME version. We can either handle it or not, never fallback to the unauthenticated version in order to avoid gaming the authenticated logic. Add a unit tests making sure we properly test that and also test that we can always handle the default emit and accepted versions. Fixes #30428 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/test/test_sendme.c')
-rw-r--r--src/test/test_sendme.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/test/test_sendme.c b/src/test/test_sendme.c
index 463a0ec086..a36c904c28 100644
--- a/src/test/test_sendme.c
+++ b/src/test/test_sendme.c
@@ -122,9 +122,9 @@ test_v1_consensus_params(void *arg)
smartlist_add(current_md_consensus->net_params,
(void *) "sendme_accept_min_version=1");
/* Minimum acceptable value is 1. */
- tt_int_op(cell_version_is_valid(1), OP_EQ, true);
+ tt_int_op(cell_version_can_be_handled(1), OP_EQ, true);
/* Minimum acceptable value is 1 so a cell version of 0 is refused. */
- tt_int_op(cell_version_is_valid(0), OP_EQ, false);
+ tt_int_op(cell_version_can_be_handled(0), OP_EQ, false);
done:
free_mock_consensus();
@@ -239,6 +239,33 @@ test_cell_payload_pad(void *arg)
;
}
+static void
+test_cell_version_validation(void *arg)
+{
+ (void) arg;
+
+ /* We currently only support up to SENDME_MAX_SUPPORTED_VERSION so we are
+ * going to test the boundaries there. */
+
+ tt_assert(cell_version_can_be_handled(SENDME_MAX_SUPPORTED_VERSION));
+
+ /* Version below our supported should pass. */
+ tt_assert(cell_version_can_be_handled(SENDME_MAX_SUPPORTED_VERSION - 1));
+
+ /* Extra version from our supported should fail. */
+ tt_assert(!cell_version_can_be_handled(SENDME_MAX_SUPPORTED_VERSION + 1));
+
+ /* Simple check for version 0. */
+ tt_assert(cell_version_can_be_handled(0));
+
+ /* We MUST handle the default cell version that we emit or accept. */
+ tt_assert(cell_version_can_be_handled(SENDME_EMIT_MIN_VERSION_DEFAULT));
+ tt_assert(cell_version_can_be_handled(SENDME_ACCEPT_MIN_VERSION_DEFAULT));
+
+ done:
+ ;
+}
+
struct testcase_t sendme_tests[] = {
{ "v1_record_digest", test_v1_record_digest, TT_FORK,
NULL, NULL },
@@ -248,6 +275,8 @@ struct testcase_t sendme_tests[] = {
NULL, NULL },
{ "cell_payload_pad", test_cell_payload_pad, TT_FORK,
NULL, NULL },
+ { "cell_version_validation", test_cell_version_validation, TT_FORK,
+ NULL, NULL },
END_OF_TESTCASES
};