unit-test: fix test_crypto when USE_COMP is not defined
PATCH 1/1 unit-test: fix test_crypto when USE_COMP is not defined
This unit-test did not consider the case when USE_COMP is not defined, thus generating a compiler error.
Adapt the test to the case when no compression is available and while at it, decompose the expected MTU values by featureso that it is easier to understand.
--- tests/unit_tests/openvpn/test_crypto.c | 52 +++++++++++++++----------- 1 file changed, 31 insertions(+), 21 deletions(-)
tests/unit_tests/openvpn/test_crypto.c +31 -21
@@ -255,7 +255,7 @@ test_occ_mtu_calculation(void **state) o.ciphername ="none" ; o.authname ="none" ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1400 ); +assert_int_equal (linkmtu, o.ce.tun_mtu);/* Static key OCC examples */ o.shared_secret_file ="not null" ;
@@ -264,44 +264,51 @@ test_occ_mtu_calculation(void **state) o.ciphername ="none" ; o.authname ="none" ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1408 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +8 );/* secret, cipher AES-128-CBC, auth none */ o.ciphername ="AES-128-CBC" ; o.authname ="none" ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1440 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +8 +32 );/* secret, cipher none, auth SHA256 */ o.ciphername ="none" ; o.authname ="SHA256" ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1440 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +8 +32 ); -/* --secret, cipher BF-CBC, auth SHA1 */ +/* secret, cipher BF-CBC, auth SHA1 */ o.ciphername ="BF-CBC" ; o.authname ="SHA1" ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1444 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +8 +36 ); -/* --secret, cipher BF-CBC, auth SHA1, tcp-client */ +/* secret, cipher BF-CBC, auth SHA1, tcp-client */ o.ce.proto =PROTO_TCP_CLIENT ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1446 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +8 +36 +2 ); o.ce.proto =PROTO_UDP ; -/* --secret, comp-lzo yes, cipher BF-CBC, auth SHA1 */ +int comp_bytes =0 ; +#if defined(USE_COMP ) +/* secret, comp-lzo yes, cipher BF-CBC, auth SHA1 */ o.comp.alg =COMP_ALG_LZO ; + comp_bytes =1 ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1445 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +8 + comp_bytes +36 ); +#endif -/* --secret, comp-lzo yes, cipher BF-CBC, auth SHA1, fragment 1200 */ +/* secret, comp-lzo yes, cipher BF-CBC, auth SHA1, fragment 1200 */ o.ce.fragment =1200 ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1449 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +8 + comp_bytes +36 +4 ); + comp_bytes =0 ; +#if defined(USE_COMP ) o.comp.alg =COMP_ALG_UNDEF ; +#endif o.ce.fragment =0 ;/* TLS mode */
@@ -309,32 +316,32 @@ test_occ_mtu_calculation(void **state) o.tls_client = true; o.pull = true; -/* tls client, cipher AES-128-CBC, auth SHA1, tls-auth*/ +/* tls client, cipher AES-128-CBC, auth SHA1, tls-auth */ o.authname ="SHA1" ; o.ciphername ="AES-128-CBC" ; o.tls_auth_file ="dummy" ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1457 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +5 +8 +32 +12 );/* tls client, cipher AES-128-CBC, auth SHA1 */ o.tls_auth_file =NULL ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1457 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +5 +8 +32 +12 );/* tls client, cipher none, auth none */ o.authname ="none" ; o.ciphername ="none" ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1405 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +5 );/* tls client, auth none, cipher none, no-replay */ o.replay = false; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1401 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +1 ); o.replay = true;
@@ -343,19 +350,22 @@ test_occ_mtu_calculation(void **state) o.authname ="SHA1" ; o.ciphername ="AES-256-GCM" ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1449 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +5 +44 ); + o.ce.fragment =1200 ; +#if defined(USE_COMP )/* tls client, auth SHA1, cipher AES-256-GCM, fragment, comp-lzo yes */ o.comp.alg =COMP_ALG_LZO ; - o.ce.fragment =1200 ; + comp_bytes =1 ; +#endif linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1454 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +5 +44 +4 + comp_bytes);/* tls client, auth SHA1, cipher AES-256-GCM, fragment, comp-lzo yes, socks */ o.ce.socks_proxy_server ="socks.example.com" ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1464 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +5 +44 +4 + comp_bytes +10 );gc_free (&gc); }
Signature · 1 line
2.34.1
Am 20.01.22 um 11:11 schrieb Antonio Quartulli:
Quoted 44 lines
This unit-test did not consider the case when
USE_COMPis not defined, thus generating a compiler error.Adapt the test to the case when no compression is available and while at it, decompose the expected MTU values by featureso that it is easier to understand.
Cc Arne Schwabe <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>--- tests/unit_tests/openvpn/test_crypto.c | 52 +++++++++++++++----------- 1 file changed, 31 insertions(+), 21 deletions(-)tests/unit_tests/openvpn/test_crypto.c +3
-3@@ -255,7 +255,7 @@ test_occ_mtu_calculation(void **state) o.ciphername ="none" ; o.authname ="none" ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1400 ); +assert_int_equal (linkmtu, o.ce.tun_mtu);/* Static key OCC examples */ o.shared_secret_file ="not null" ;@@ -264,44 +264,51 @@ test_occ_mtu_calculation(void **state) o.ciphername ="none" ; o.authname ="none" ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1408 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +8 );/* secret, cipher AES-128-CBC, auth none */ o.ciphername ="AES-128-CBC" ; o.authname ="none" ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1440 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +8 +32 );/* secret, cipher none, auth SHA256 */ o.ciphername ="none" ; o.authname ="SHA256" ; linkmtu =calc_options_string_link_mtu (&o, &f);
tests/unit_tests/openvpn/test_crypto.c test_occ_mtu_calculation(void **state) · line 285
Quoted 10 lines
tests/unit_tests/openvpn/test_crypto.c +3
-3-assert_int_equal (linkmtu,1440 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +8 +32 ); -/* --secret, cipher BF-CBC, auth SHA1 */ +/* secret, cipher BF-CBC, auth SHA1 */ o.ciphername ="BF-CBC" ; o.authname ="SHA1" ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1444 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +8 +36 );
if you want semantic things here that should be + 20 /* sha1 */ + 16 /*bf-cbc */
Quoted 10 lines
tests/unit_tests/openvpn/test_crypto.c +2
-2-/* --secret, cipher BF-CBC, auth SHA1, tcp-client */ +/* secret, cipher BF-CBC, auth SHA1, tcp-client */ o.ce.proto =PROTO_TCP_CLIENT ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1446 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +8 +36 +2 ); o.ce.proto =PROTO_UDP ;
tests/unit_tests/openvpn/test_crypto.c test_occ_mtu_calculation(void **state) · line 301
Quoted 10 lines
tests/unit_tests/openvpn/test_crypto.c +6
-2-/* --secret, comp-lzo yes, cipher BF-CBC, auth SHA1 */ +int comp_bytes =0 ; +#if defined(USE_COMP ) +/* secret, comp-lzo yes, cipher BF-CBC, auth SHA1 */ o.comp.alg =COMP_ALG_LZO ; + comp_bytes =1 ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1445 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +8 + comp_bytes +36 ); +#endif
why the extra variable and not just +1?
tests/unit_tests/openvpn/test_crypto.c test_occ_mtu_calculation(void **state) · line 307
Quoted 8 lines
tests/unit_tests/openvpn/test_crypto.c +2
-2-/* --secret, comp-lzo yes, cipher BF-CBC, auth SHA1, fragment 1200 */ +/* secret, comp-lzo yes, cipher BF-CBC, auth SHA1, fragment 1200 */ o.ce.fragment =1200 ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1449 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +8 + comp_bytes +36 +4 );
I would rather have this also under COMP_DEF than to add this different tests depending on compile flags.
Quoted 10 lines
tests/unit_tests/openvpn/test_crypto.c +3
-0+ comp_bytes =0 ; +#if defined(USE_COMP ) o.comp.alg =COMP_ALG_UNDEF ; +#endif o.ce.fragment =0 ;/* TLS mode */ @@ -309,32 +316,32 @@ test_occ_mtu_calculation(void **state) o.tls_client = true; o.pull = true;
tests/unit_tests/openvpn/test_crypto.c test_occ_mtu_calculation(void **state) · line 325
Quoted 10 lines
tests/unit_tests/openvpn/test_crypto.c +2
-2-/* tls client, cipher AES-128-CBC, auth SHA1, tls-auth*/ +/* tls client, cipher AES-128-CBC, auth SHA1, tls-auth */ o.authname ="SHA1" ; o.ciphername ="AES-128-CBC" ; o.tls_auth_file ="dummy" ; linkmtu =calc_options_string_link_mtu (&o, &f); -assert_int_equal (linkmtu,1457 ); +assert_int_equal (linkmtu, o.ce.tun_mtu +5 +8 +32 +12 );
I think this one is wrong sha1 is 20 and aes-128-cbc is 16.
If we really want to split the magic nubmers, we should split them in the right way, otherwise it becomes more confsuing than it is helpful.
Arne
PATCH v2 1/1 unit-test: fix test_crypto when USE_COMP is not defined
In reply to Antonio QuartulliThis unit-test did not consider the case when USE_COMP is not defined, thus generating a compiler error.
Adapt the test to the case when no compression is available.
---
v2:
* restore original MTU numbers - this can be addressed by another patch
tests/unit_tests/openvpn/test_crypto.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
tests/unit_tests/openvpn/test_crypto.c +11 -5
@@ -278,30 +278,34 @@ test_occ_mtu_calculation(void **state) linkmtu =calc_options_string_link_mtu (&o, &f);assert_int_equal (linkmtu,1440 ); -/* --secret, cipher BF-CBC, auth SHA1 */ +/* secret, cipher BF-CBC, auth SHA1 */ o.ciphername ="BF-CBC" ; o.authname ="SHA1" ; linkmtu =calc_options_string_link_mtu (&o, &f);assert_int_equal (linkmtu,1444 ); -/* --secret, cipher BF-CBC, auth SHA1, tcp-client */ +/* secret, cipher BF-CBC, auth SHA1, tcp-client */ o.ce.proto =PROTO_TCP_CLIENT ; linkmtu =calc_options_string_link_mtu (&o, &f);assert_int_equal (linkmtu,1446 ); o.ce.proto =PROTO_UDP ; -/* --secret, comp-lzo yes, cipher BF-CBC, auth SHA1 */ +#if defined(USE_COMP ) +/* secret, comp-lzo yes, cipher BF-CBC, auth SHA1 */ o.comp.alg =COMP_ALG_LZO ; linkmtu =calc_options_string_link_mtu (&o, &f);assert_int_equal (linkmtu,1445 ); +#endif -/* --secret, comp-lzo yes, cipher BF-CBC, auth SHA1, fragment 1200 */ +/* secret, comp-lzo yes, cipher BF-CBC, auth SHA1, fragment 1200 */ o.ce.fragment =1200 ; linkmtu =calc_options_string_link_mtu (&o, &f);assert_int_equal (linkmtu,1449 ); +#if defined(USE_COMP ) o.comp.alg =COMP_ALG_UNDEF ; +#endif o.ce.fragment =0 ;/* TLS mode */
@@ -309,7 +313,7 @@ test_occ_mtu_calculation(void **state) o.tls_client = true; o.pull = true; -/* tls client, cipher AES-128-CBC, auth SHA1, tls-auth*/ +/* tls client, cipher AES-128-CBC, auth SHA1, tls-auth */ o.authname ="SHA1" ; o.ciphername ="AES-128-CBC" ; o.tls_auth_file ="dummy" ;
@@ -346,6 +350,7 @@ test_occ_mtu_calculation(void **state)assert_int_equal (linkmtu,1449 ); +#if defined(USE_COMP )/* tls client, auth SHA1, cipher AES-256-GCM, fragment, comp-lzo yes */ o.comp.alg =COMP_ALG_LZO ; o.ce.fragment =1200 ;
@@ -356,6 +361,7 @@ test_occ_mtu_calculation(void **state) o.ce.socks_proxy_server ="socks.example.com" ; linkmtu =calc_options_string_link_mtu (&o, &f);assert_int_equal (linkmtu,1464 ); +#endif gc_free (&gc); }
Signature · 1 line
2.34.1
Hi,
Quoted 7 lines · Antonio Quartulli
This unit-test did not consider the case when
USE_COMPis not defined, thus generating a compiler error.Adapt the test to the case when no compression is available.
Cc Arne Schwabe <[email protected]...>Signed-off-by Antonio Quartulli <[email protected]...>
NAK. Github says it now fails at "make check" time.
[ RUN ] test_occ_mtu_calculation [ ERROR ] --- 0x5a8 != 0x5a9 [ FAILED ] test_occ_mtu_calculation [==========] 6 test(s) run. [ LINE ] --- test_crypto.c:304: error: Failure! [ PASSED ] 5 test(s). [ FAILED ] 1 test(s), listed below: [ FAILED ] test_occ_mtu_calculation
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...PATCH v3 1/1 unit-test: fix test_crypto when USE_COMP is not defined
In reply to Antonio QuartulliThis unit-test did not consider the case when USE_COMP is not defined, thus generating a compiler error.
Adapt the test to the case when no compression is available.
---
v2:
* restore original MTU numbers - this can be addressed by another patch v3:
* skip *ALL* tests assuming encryption enabled
tests/unit_tests/openvpn/test_crypto.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
tests/unit_tests/openvpn/test_crypto.c +12 -6
@@ -278,38 +278,41 @@ test_occ_mtu_calculation(void **state) linkmtu =calc_options_string_link_mtu (&o, &f);assert_int_equal (linkmtu,1440 ); -/* --secret, cipher BF-CBC, auth SHA1 */ +/* secret, cipher BF-CBC, auth SHA1 */ o.ciphername ="BF-CBC" ; o.authname ="SHA1" ; linkmtu =calc_options_string_link_mtu (&o, &f);assert_int_equal (linkmtu,1444 ); -/* --secret, cipher BF-CBC, auth SHA1, tcp-client */ +/* secret, cipher BF-CBC, auth SHA1, tcp-client */ o.ce.proto =PROTO_TCP_CLIENT ; linkmtu =calc_options_string_link_mtu (&o, &f);assert_int_equal (linkmtu,1446 ); o.ce.proto =PROTO_UDP ; -/* --secret, comp-lzo yes, cipher BF-CBC, auth SHA1 */ +#if defined(USE_COMP ) o.comp.alg =COMP_ALG_LZO ; + +/* secret, comp-lzo yes, cipher BF-CBC, auth SHA1 */ linkmtu =calc_options_string_link_mtu (&o, &f);assert_int_equal (linkmtu,1445 ); -/* --secret, comp-lzo yes, cipher BF-CBC, auth SHA1, fragment 1200 */ +/* secret, comp-lzo yes, cipher BF-CBC, auth SHA1, fragment 1200 */ o.ce.fragment =1200 ; linkmtu =calc_options_string_link_mtu (&o, &f);assert_int_equal (linkmtu,1449 ); o.comp.alg =COMP_ALG_UNDEF ; o.ce.fragment =0 ; +#endif /* TLS mode */ o.shared_secret_file =NULL ; o.tls_client = true; o.pull = true; -/* tls client, cipher AES-128-CBC, auth SHA1, tls-auth*/ +/* tls client, cipher AES-128-CBC, auth SHA1, tls-auth */ o.authname ="SHA1" ; o.ciphername ="AES-128-CBC" ; o.tls_auth_file ="dummy" ;
@@ -346,8 +349,10 @@ test_occ_mtu_calculation(void **state)assert_int_equal (linkmtu,1449 ); -/* tls client, auth SHA1, cipher AES-256-GCM, fragment, comp-lzo yes */ +#if defined(USE_COMP ) o.comp.alg =COMP_ALG_LZO ; + +/* tls client, auth SHA1, cipher AES-256-GCM, fragment, comp-lzo yes */ o.ce.fragment =1200 ; linkmtu =calc_options_string_link_mtu (&o, &f);assert_int_equal (linkmtu,1454 );
@@ -356,6 +361,7 @@ test_occ_mtu_calculation(void **state) o.ce.socks_proxy_server ="socks.example.com" ; linkmtu =calc_options_string_link_mtu (&o, &f);assert_int_equal (linkmtu,1464 ); +#endif gc_free (&gc); }
Signature · 1 line
2.34.1
This looks better, and actually works :-)
Your patch has been applied to the master branch.
commit 33d9c7ace354693168c093550bd5a9f4dfed4078
Author: Antonio Quartulli Date: Fri Jan 21 15:43:13 2022 +0100
unit-test: fix test_crypto when USE_COMP is not defined
Signed-off-by: Antonio Quartulli <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg23628.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering