summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Perry <mikeperry-git@torproject.org>2022-02-17 17:36:46 +0000
committerMike Perry <mikeperry-git@torproject.org>2022-02-22 19:28:36 +0000
commit01bda6c23f58947ad1e20ea6367a5c260f53dfab (patch)
tree843bf189c3de8db2bfae6f59f4af13c9556b1863
parent8f4bd8730c1df180e0ef2f5e6565c21b37ae593a (diff)
downloadtor-01bda6c23f58947ad1e20ea6367a5c260f53dfab.tar.gz
tor-01bda6c23f58947ad1e20ea6367a5c260f53dfab.zip
Add test for sendme_inc validation.
-rw-r--r--src/test/test_hs_descriptor.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/test/test_hs_descriptor.c b/src/test/test_hs_descriptor.c
index ecb7da2450..469e3c39f9 100644
--- a/src/test/test_hs_descriptor.c
+++ b/src/test/test_hs_descriptor.c
@@ -840,6 +840,44 @@ test_build_authorized_client(void *arg)
testing_disable_prefilled_rng();
}
+static void
+test_validate_sendme(void *arg)
+{
+ (void)arg;
+
+ /* Test basic operation: factors of 2X in either direction are OK */
+ cc_sendme_inc = 31;
+ tt_assert(congestion_control_validate_sendme_increment(15));
+ tt_assert(congestion_control_validate_sendme_increment(62));
+
+ /* Test basic operation: Exceeding 2X fails */
+ cc_sendme_inc = 31;
+ tt_assert(!congestion_control_validate_sendme_increment(14));
+ tt_assert(!congestion_control_validate_sendme_increment(63));
+
+ /* Test potential overflow conditions */
+ cc_sendme_inc = 129;
+ tt_assert(congestion_control_validate_sendme_increment(255));
+ tt_assert(congestion_control_validate_sendme_increment(64));
+ tt_assert(!congestion_control_validate_sendme_increment(63));
+
+ cc_sendme_inc = 127;
+ tt_assert(!congestion_control_validate_sendme_increment(255));
+ tt_assert(congestion_control_validate_sendme_increment(254));
+
+ cc_sendme_inc = 255;
+ tt_assert(congestion_control_validate_sendme_increment(255));
+ tt_assert(congestion_control_validate_sendme_increment(127));
+ tt_assert(!congestion_control_validate_sendme_increment(126));
+
+ /* Test 0 case */
+ cc_sendme_inc = 1;
+ tt_assert(!congestion_control_validate_sendme_increment(0));
+
+done:
+ ;
+}
+
struct testcase_t hs_descriptor[] = {
/* Encoding tests. */
{ "cert_encoding", test_cert_encoding, TT_FORK,
@@ -860,6 +898,8 @@ struct testcase_t hs_descriptor[] = {
NULL, NULL },
{ "decode_bad_signature", test_decode_bad_signature, TT_FORK,
NULL, NULL },
+ { "validate_sendme", test_validate_sendme, TT_FORK,
+ NULL, NULL },
/* Misc. */
{ "version", test_supported_version, TT_FORK,