aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-05-22 11:48:43 -0400
committerNick Mathewson <nickm@torproject.org>2019-05-22 11:48:43 -0400
commite6b862e6a8bf690571f192efc66f06ed5cb4696d (patch)
tree40813f9e349fe68bc4026c0f669bac1d32d72541 /src/test
parent21b051d1cbf5d60ccbeaf24925c4ff446d493523 (diff)
parent0cad83bea4019b3c448756d718f5b65718e81f6e (diff)
downloadtor-e6b862e6a8bf690571f192efc66f06ed5cb4696d.tar.gz
tor-e6b862e6a8bf690571f192efc66f06ed5cb4696d.zip
Merge branch 'ticket30428_041_02_squashed'
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_relaycell.c7
-rw-r--r--src/test/test_sendme.c65
2 files changed, 48 insertions, 24 deletions
diff --git a/src/test/test_relaycell.c b/src/test/test_relaycell.c
index 0623583511..c65279fb25 100644
--- a/src/test/test_relaycell.c
+++ b/src/test/test_relaycell.c
@@ -17,6 +17,7 @@
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/connection_edge.h"
+#include "core/or/sendme.h"
#include "core/or/relay.h"
#include "test/test.h"
#include "test/log_test_helpers.h"
@@ -812,7 +813,11 @@ test_circbw_relay(void *arg)
ASSERT_UNCOUNTED_BW();
/* Sendme on circuit with non-full window: counted */
- PACK_CELL(0, RELAY_COMMAND_SENDME, "Data1234");
+ PACK_CELL(0, RELAY_COMMAND_SENDME, "");
+ /* Recording a cell, the window is updated after decryption so off by one in
+ * order to record and then we process it with the proper window. */
+ circ->cpath->package_window = 901;
+ sendme_record_cell_digest_on_circ(TO_CIRCUIT(circ), circ->cpath);
circ->cpath->package_window = 900;
connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
circ->cpath);
diff --git a/src/test/test_sendme.c b/src/test/test_sendme.c
index d40fbaf862..fa5ae115ac 100644
--- a/src/test/test_sendme.c
+++ b/src/test/test_sendme.c
@@ -46,26 +46,12 @@ static void
test_v1_record_digest(void *arg)
{
or_circuit_t *or_circ = NULL;
- origin_circuit_t *orig_circ = NULL;
circuit_t *circ = NULL;
(void) arg;
- /* Create our dummy circuits. */
- orig_circ = origin_circuit_new();
- tt_assert(orig_circ);
+ /* Create our dummy circuit. */
or_circ = or_circuit_new(1, NULL);
-
- /* Start by pointing to the origin circuit. */
- circ = TO_CIRCUIT(orig_circ);
- circ->purpose = CIRCUIT_PURPOSE_S_REND_JOINED;
-
- /* We should never note SENDME digest on origin circuit. */
- sendme_record_cell_digest(circ);
- tt_assert(!circ->sendme_last_digests);
- /* We do not need the origin circuit for now. */
- orig_circ = NULL;
- circuit_free_(circ);
/* Points it to the OR circuit now. */
circ = TO_CIRCUIT(or_circ);
@@ -73,23 +59,23 @@ test_v1_record_digest(void *arg)
* in order to catched the CIRCWINDOW_INCREMENT-nth cell. Try something that
* shouldn't be noted. */
circ->package_window = CIRCWINDOW_INCREMENT;
- sendme_record_cell_digest(circ);
+ sendme_record_cell_digest_on_circ(circ, NULL);
tt_assert(!circ->sendme_last_digests);
/* This should work now. Package window at CIRCWINDOW_INCREMENT + 1. */
circ->package_window++;
- sendme_record_cell_digest(circ);
+ sendme_record_cell_digest_on_circ(circ, NULL);
tt_assert(circ->sendme_last_digests);
tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 1);
/* Next cell in the package window shouldn't do anything. */
circ->package_window++;
- sendme_record_cell_digest(circ);
+ sendme_record_cell_digest_on_circ(circ, NULL);
tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 1);
/* The next CIRCWINDOW_INCREMENT should add one more digest. */
circ->package_window = (CIRCWINDOW_INCREMENT * 2) + 1;
- sendme_record_cell_digest(circ);
+ sendme_record_cell_digest_on_circ(circ, NULL);
tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 2);
done:
@@ -136,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();
@@ -157,11 +143,13 @@ test_v1_build_cell(void *arg)
or_circ = or_circuit_new(1, NULL);
circ = TO_CIRCUIT(or_circ);
+ circ->sendme_last_digests = smartlist_new();
cell_digest = crypto_digest_new();
tt_assert(cell_digest);
crypto_digest_add_bytes(cell_digest, "AAAAAAAAAAAAAAAAAAAA", 20);
crypto_digest_get_digest(cell_digest, (char *) digest, sizeof(digest));
+ smartlist_add(circ->sendme_last_digests, tor_memdup(digest, sizeof(digest)));
/* SENDME v1 payload is 3 bytes + 20 bytes digest. See spec. */
ret = build_cell_payload_v1(digest, payload);
@@ -171,6 +159,8 @@ test_v1_build_cell(void *arg)
/* An empty payload means SENDME version 0 thus valid. */
tt_int_op(sendme_is_valid(circ, payload, 0), OP_EQ, true);
+ /* Current phoney digest should have been popped. */
+ tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 0);
/* An unparseable cell means invalid. */
setup_full_capture_of_logs(LOG_INFO);
@@ -188,7 +178,7 @@ test_v1_build_cell(void *arg)
/* Note the wrong digest in the circuit, cell should fail validation. */
circ->package_window = CIRCWINDOW_INCREMENT + 1;
- sendme_record_cell_digest(circ);
+ sendme_record_cell_digest_on_circ(circ, NULL);
tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 1);
setup_full_capture_of_logs(LOG_INFO);
tt_int_op(sendme_is_valid(circ, payload, sizeof(payload)), OP_EQ, false);
@@ -200,7 +190,7 @@ test_v1_build_cell(void *arg)
/* Record the cell digest into the circuit, cell should validate. */
memcpy(or_circ->crypto.sendme_digest, digest, sizeof(digest));
circ->package_window = CIRCWINDOW_INCREMENT + 1;
- sendme_record_cell_digest(circ);
+ sendme_record_cell_digest_on_circ(circ, NULL);
tt_int_op(smartlist_len(circ->sendme_last_digests), OP_EQ, 1);
tt_int_op(sendme_is_valid(circ, payload, sizeof(payload)), OP_EQ, true);
/* After a validation, the last digests is always popped out. */
@@ -253,6 +243,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 },
@@ -262,6 +279,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
};