[Openvpn-devel] Add unit test for mssfix with compression involved

Message ID 20220214003321.3741582-1-arne@rfc2549.org
State Accepted
Headers show
Series [Openvpn-devel] Add unit test for mssfix with compression involved | expand

Commit Message

Arne Schwabe Feb. 13, 2022, 1:33 p.m. UTC
---
 tests/unit_tests/openvpn/test_crypto.c | 28 ++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

Comments

Gert Doering Feb. 13, 2022, 8:32 p.m. UTC | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

Have not done all the calculations myself, but passes the unit tests
for "with compression" (default), "without LZO" and "with no compression".

Your patch has been applied to the master branch.

commit de152bccc00daf7aebfa97e376ec2e37c3e1f574
Author: Arne Schwabe
Date:   Mon Feb 14 01:33:21 2022 +0100

     Add unit test for mssfix with compression involved

     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20220214003321.3741582-1-arne@rfc2549.org>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg23777.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/tests/unit_tests/openvpn/test_crypto.c b/tests/unit_tests/openvpn/test_crypto.c
index 7fb9d624..ca170547 100644
--- a/tests/unit_tests/openvpn/test_crypto.c
+++ b/tests/unit_tests/openvpn/test_crypto.c
@@ -426,6 +426,34 @@  test_mssfix_mtu_calculation(void **state)
             assert_int_equal(f.mss_fix, 927);
         }
     }
+#ifdef USE_COMP
+    o.comp.alg = COMP_ALG_LZO;
+
+    /* Same but with compression added. Compression adds one byte extra to the
+     * payload so the payload should be reduced by compared to the no
+     * compression calculation before */
+    for (int i = 990;i <= 1010;i++)
+    {
+        /* 992 - 1008 should end up with the same mssfix value all they
+         * all result in the same CBC block size/padding and <= 991 and >=1008
+         * should be one block less and more respectively */
+        o.ce.mssfix = i;
+        frame_calculate_dynamic(&f, &kt, &o, NULL);
+        if (i <= 991)
+        {
+            assert_int_equal(f.mss_fix, 910);
+        }
+        else if (i >= 1008)
+        {
+            assert_int_equal(f.mss_fix, 942);
+        }
+        else
+        {
+            assert_int_equal(f.mss_fix, 926);
+        }
+    }
+    o.comp.alg = COMP_ALG_UNDEF;
+#endif
 
     /* tls client, auth SHA1, cipher AES-256-GCM */
     o.authname = "SHA1";