aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Sommerseth2022-04-20 16:30:50 +0200
committerGert Doering2022-04-21 09:31:13 +0200
commitabe49856d81f51136d543539202a0bf8fb946474 (patch)
tree9f69ee496ba9d176531d8f352236aa9c6cf0c8db /tests
parent9febbcbbcf3b1a786a1e77145d30a43eb7996dc4 (diff)
downloadopenvpn-abe49856d81f51136d543539202a0bf8fb946474.zip
openvpn-abe49856d81f51136d543539202a0bf8fb946474.tar.gz
The Great Reformatting of 2022
It was agreed it was time to do a full reformat fix-up of the whole source tree again. Over time (since late 2016) small changes has not adhered to our uncrustify defined coding style. This realigns to our current standards. Signed-off-by: David Sommerseth <davids@openvpn.net> Acked-by: Gert Doering <gert@greenie.muc.de> Message-Id: <20220420143050.52790-1-openvpn@sf.lists.topphemmelig.net> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg24123.html Signed-off-by: Gert Doering <gert@greenie.muc.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit_tests/openvpn/test_crypto.c10
-rw-r--r--tests/unit_tests/openvpn/test_misc.c6
-rw-r--r--tests/unit_tests/openvpn/test_ncp.c2
-rw-r--r--tests/unit_tests/openvpn/test_provider.c60
-rw-r--r--tests/unit_tests/openvpn/test_tls_crypt.c2
-rw-r--r--tests/unit_tests/plugins/auth-pam/test_search_and_replace.c21
6 files changed, 55 insertions, 46 deletions
diff --git a/tests/unit_tests/openvpn/test_crypto.c b/tests/unit_tests/openvpn/test_crypto.c
index ca17054..83572b8 100644
--- a/tests/unit_tests/openvpn/test_crypto.c
+++ b/tests/unit_tests/openvpn/test_crypto.c
@@ -144,7 +144,7 @@ static uint8_t good_prf[32] = {0xd9, 0x8c, 0x85, 0x18, 0xc8, 0x5e, 0x94, 0x69,
0xb1, 0x56, 0x7e, 0x4b, 0x4b, 0x14, 0x59, 0xe6,
0xa9, 0x04, 0xac, 0x2d, 0xda, 0xb7, 0x2d, 0x67};
-static const char* ipsumlorem = "Lorem ipsum dolor sit amet, consectetur "
+static const char *ipsumlorem = "Lorem ipsum dolor sit amet, consectetur "
"adipisici elit, sed eiusmod tempor incidunt "
"ut labore et dolore magna aliqua.";
@@ -406,7 +406,7 @@ test_mssfix_mtu_calculation(void **state)
o.authname = "none";
init_key_type(&kt, o.ciphername, o.authname, false, false);
- for (int i = 990;i <= 1010;i++)
+ 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
@@ -432,7 +432,7 @@ test_mssfix_mtu_calculation(void **state)
/* 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++)
+ 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
@@ -453,7 +453,7 @@ test_mssfix_mtu_calculation(void **state)
}
}
o.comp.alg = COMP_ALG_UNDEF;
-#endif
+#endif /* ifdef USE_COMP */
/* tls client, auth SHA1, cipher AES-256-GCM */
o.authname = "SHA1";
@@ -463,7 +463,7 @@ test_mssfix_mtu_calculation(void **state)
o.use_peer_id = true;
init_key_type(&kt, o.ciphername, o.authname, true, false);
- for (int i=900;i <= 1200;i++)
+ for (int i = 900; i <= 1200; i++)
{
/* For stream ciphers, the value should not be influenced by block
* sizes or similar but always have the same difference */
diff --git a/tests/unit_tests/openvpn/test_misc.c b/tests/unit_tests/openvpn/test_misc.c
index f6eb4ff..636fc45 100644
--- a/tests/unit_tests/openvpn/test_misc.c
+++ b/tests/unit_tests/openvpn/test_misc.c
@@ -43,9 +43,9 @@ test_compat_lzo_string(void **state)
{
struct gc_arena gc = gc_new();
- const char* input = "V4,dev-type tun,link-mtu 1457,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server";
+ const char *input = "V4,dev-type tun,link-mtu 1457,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server";
- const char* output = options_string_compat_lzo(input, &gc);
+ const char *output = options_string_compat_lzo(input, &gc);
assert_string_equal(output, "V4,dev-type tun,link-mtu 1458,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server,comp-lzo");
@@ -70,7 +70,7 @@ test_compat_lzo_string(void **state)
assert_string_equal(output, "V4,dev-type tun,link-mtu 1000,tun-mtu 1400,proto UDPv4,auth SHA1,keysize 128,key-method 2,tls-server,comp-lzo");
gc_free(&gc);
-};
+}
const struct CMUnitTest misc_tests[] = {
cmocka_unit_test(test_compat_lzo_string),
diff --git a/tests/unit_tests/openvpn/test_ncp.c b/tests/unit_tests/openvpn/test_ncp.c
index 6456d26..18c4036 100644
--- a/tests/unit_tests/openvpn/test_ncp.c
+++ b/tests/unit_tests/openvpn/test_ncp.c
@@ -49,7 +49,7 @@ const char *aes_ciphers = "AES-256-GCM:AES-128-GCM";
* leads to having to include even more unrelated code */
bool
key_state_export_keying_material(struct tls_session *session,
- const char* label, size_t label_size,
+ const char *label, size_t label_size,
void *ekm, size_t ekm_size)
{
ASSERT(0);
diff --git a/tests/unit_tests/openvpn/test_provider.c b/tests/unit_tests/openvpn/test_provider.c
index 7f34df7..0b0952e 100644
--- a/tests/unit_tests/openvpn/test_provider.c
+++ b/tests/unit_tests/openvpn/test_provider.c
@@ -51,39 +51,40 @@ static int mgmt_callback_called;
static OSSL_PROVIDER *prov[2];
/* public keys for testing -- RSA and EC */
-static const char * const pubkey1 = "-----BEGIN PUBLIC KEY-----\n"
- "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7GWP6RLCGlvmVioIqYI6\n"
- "LUR4owA7sJ/nJxBAk+/xzD6gqgSigBsTqeb+gdZwkKjY1N4w2DUA0r5i8Eja/BWN\n"
- "xMZtC5nxK4MACtMqIwvlzfk130NhFXKtlZj2cyFBXqDdRyeg1ZrUQagcHVcgcReP\n"
- "9yiePgfO7NUOQk8edEeOR53SFCgnLBQQ9dGWtZN0hO/5BN6NSm/fd6vq0VjTRP5a\n"
- "BAH/BnqX9/3jV0jh8N9AE59mI1rjVVQ9VDnuAPkS8dLfdC661/CNxt0YWByTIgt1\n"
- "+qjW4LUvLbnU/rlPhuJ1SBZg+z/JtDBCKfs7syu5WYFqRvNFg7/91Rr/NwxvW/1h\n"
- "8QIDAQAB\n"
- "-----END PUBLIC KEY-----\n";
-
-static const char * const pubkey2 = "-----BEGIN PUBLIC KEY-----\n"
- "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEO85iXW+HgnUkwlj1DohNVw0GsnGIh1gZ\n"
- "u95ff1JiUaJIkYNIkZA+hwIPFVH5aJcSCv3SPIeDS2VUAESNKHZJBQ==\n"
- "-----END PUBLIC KEY-----\n";
+static const char *const pubkey1 = "-----BEGIN PUBLIC KEY-----\n"
+ "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA7GWP6RLCGlvmVioIqYI6\n"
+ "LUR4owA7sJ/nJxBAk+/xzD6gqgSigBsTqeb+gdZwkKjY1N4w2DUA0r5i8Eja/BWN\n"
+ "xMZtC5nxK4MACtMqIwvlzfk130NhFXKtlZj2cyFBXqDdRyeg1ZrUQagcHVcgcReP\n"
+ "9yiePgfO7NUOQk8edEeOR53SFCgnLBQQ9dGWtZN0hO/5BN6NSm/fd6vq0VjTRP5a\n"
+ "BAH/BnqX9/3jV0jh8N9AE59mI1rjVVQ9VDnuAPkS8dLfdC661/CNxt0YWByTIgt1\n"
+ "+qjW4LUvLbnU/rlPhuJ1SBZg+z/JtDBCKfs7syu5WYFqRvNFg7/91Rr/NwxvW/1h\n"
+ "8QIDAQAB\n"
+ "-----END PUBLIC KEY-----\n";
+
+static const char *const pubkey2 = "-----BEGIN PUBLIC KEY-----\n"
+ "MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEO85iXW+HgnUkwlj1DohNVw0GsnGIh1gZ\n"
+ "u95ff1JiUaJIkYNIkZA+hwIPFVH5aJcSCv3SPIeDS2VUAESNKHZJBQ==\n"
+ "-----END PUBLIC KEY-----\n";
static const char *pubkeys[] = {pubkey1, pubkey2};
static const char *prov_name = "ovpn.xkey";
-static const char* test_msg = "Lorem ipsum dolor sit amet, consectetur "
+static const char *test_msg = "Lorem ipsum dolor sit amet, consectetur "
"adipisici elit, sed eiusmod tempor incidunt "
"ut labore et dolore magna aliqua.";
-static const char* test_msg_b64 =
+static const char *test_msg_b64 =
"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2ljaS"
"BlbGl0LCBzZWQgZWl1c21vZCB0ZW1wb3IgaW5jaWR1bnQgdXQgbGFib3JlIGV0IGRv"
"bG9yZSBtYWduYSBhbGlxdWEu";
/* Sha256 digest of test_msg excluding NUL terminator */
-static const uint8_t test_digest[] =
- {0x77, 0x38, 0x65, 0x00, 0x1e, 0x96, 0x48, 0xc6, 0x57, 0x0b, 0xae,
- 0xc0, 0xb7, 0x96, 0xf9, 0x66, 0x4d, 0x5f, 0xd0, 0xb7, 0xdb, 0xf3,
- 0x3a, 0xbf, 0x02, 0xcc, 0x78, 0x61, 0x83, 0x20, 0x20, 0xee};
+static const uint8_t test_digest[] = {
+ 0x77, 0x38, 0x65, 0x00, 0x1e, 0x96, 0x48, 0xc6, 0x57, 0x0b, 0xae,
+ 0xc0, 0xb7, 0x96, 0xf9, 0x66, 0x4d, 0x5f, 0xd0, 0xb7, 0xdb, 0xf3,
+ 0x3a, 0xbf, 0x02, 0xcc, 0x78, 0x61, 0x83, 0x20, 0x20, 0xee
+};
static const char *test_digest_b64 = "dzhlAB6WSMZXC67At5b5Zk1f0Lfb8zq/Asx4YYMgIO4=";
@@ -92,9 +93,10 @@ static const char *test_digest_b64 = "dzhlAB6WSMZXC67At5b5Zk1f0Lfb8zq/Asx4YYMgIO
* --- the smallest size of the actual signature with the above
* keys.
*/
-static const uint8_t good_sig[] =
- {0xd8, 0xa7, 0xd9, 0x81, 0xd8, 0xaa, 0xd8, 0xad, 0x20, 0xd9, 0x8a, 0xd8,
- 0xa7, 0x20, 0xd8, 0xb3, 0xd9, 0x85, 0xd8, 0xb3, 0xd9, 0x85, 0x0};
+static const uint8_t good_sig[] = {
+ 0xd8, 0xa7, 0xd9, 0x81, 0xd8, 0xaa, 0xd8, 0xad, 0x20, 0xd9, 0x8a, 0xd8,
+ 0xa7, 0x20, 0xd8, 0xb3, 0xd9, 0x85, 0xd8, 0xb3, 0xd9, 0x85, 0x0
+};
static const char *good_sig_b64 = "2KfZgdiq2K0g2YrYpyDYs9mF2LPZhQA=";
@@ -155,8 +157,8 @@ management_query_pk_sig(struct management *man, const char *b64_data,
const char *expected_tbs = test_digest_b64;
if (strstr(algorithm, "data=message"))
{
- expected_tbs = test_msg_b64;
- assert_non_null(strstr(algorithm, "hashalg=SHA256"));
+ expected_tbs = test_msg_b64;
+ assert_non_null(strstr(algorithm, "hashalg=SHA256"));
}
assert_string_equal(b64_data, expected_tbs);
@@ -238,14 +240,14 @@ digest_sign(EVP_PKEY *pkey)
}
/* sign with sig = NULL to get required siglen */
- assert_int_equal(EVP_DigestSign(mctx, sig, &siglen, (uint8_t*)test_msg, strlen(test_msg)), 1);
+ assert_int_equal(EVP_DigestSign(mctx, sig, &siglen, (uint8_t *)test_msg, strlen(test_msg)), 1);
assert_true(siglen > 0);
if ((sig = test_calloc(1, siglen)) == NULL)
{
fail_msg("Out of memory");
}
- assert_int_equal(EVP_DigestSign(mctx, sig, &siglen, (uint8_t*)test_msg, strlen(test_msg)), 1);
+ assert_int_equal(EVP_DigestSign(mctx, sig, &siglen, (uint8_t *)test_msg, strlen(test_msg)), 1);
done:
if (mctx)
@@ -357,7 +359,7 @@ xkey_provider_test_generic_sign_cb(void **state)
pubkey = load_pubkey(pubkeys[i]);
assert_true(pubkey != NULL);
- EVP_PKEY *privkey = xkey_load_generic_key(NULL, (void*)dummy, pubkey, xkey_sign, xkey_free);
+ EVP_PKEY *privkey = xkey_load_generic_key(NULL, (void *)dummy, pubkey, xkey_sign, xkey_free);
assert_true(privkey != NULL);
xkey_sign_called = 0;
@@ -394,7 +396,7 @@ main(void)
uninit_test();
return ret;
}
-#else
+#else /* ifdef HAVE_XKEY_PROVIDER */
int
main(void)
{
diff --git a/tests/unit_tests/openvpn/test_tls_crypt.c b/tests/unit_tests/openvpn/test_tls_crypt.c
index 12ea945..82bb0a2 100644
--- a/tests/unit_tests/openvpn/test_tls_crypt.c
+++ b/tests/unit_tests/openvpn/test_tls_crypt.c
@@ -581,7 +581,7 @@ test_tls_crypt_v2_write_client_key_file_metadata(void **state)
/* Test writing the client key */
expect_string(__wrap_buffer_write_file, filename, filename);
expect_memory(__wrap_buffer_write_file, pem, test_client_key_metadata,
- strlen(test_client_key_metadata));
+ strlen(test_client_key_metadata));
will_return(__wrap_buffer_write_file, true);
/* Key generation re-reads the created file as a sanity check */
diff --git a/tests/unit_tests/plugins/auth-pam/test_search_and_replace.c b/tests/unit_tests/plugins/auth-pam/test_search_and_replace.c
index e80bffb..34a9a88 100644
--- a/tests/unit_tests/plugins/auth-pam/test_search_and_replace.c
+++ b/tests/unit_tests/plugins/auth-pam/test_search_and_replace.c
@@ -9,7 +9,8 @@
#include "utils.h"
static void
-pass_any_null_param__returns_null() {
+pass_any_null_param__returns_null()
+{
char DUMMY[] = "DUMMY";
@@ -19,7 +20,8 @@ pass_any_null_param__returns_null() {
}
static void
-pass_any_empty_string__returns_null() {
+pass_any_empty_string__returns_null()
+{
char DUMMY[] = "DUMMY";
char EMPTY[] = "";
@@ -30,7 +32,8 @@ pass_any_empty_string__returns_null() {
}
static void
-replace_single_char__one_time__match_is_replaced() {
+replace_single_char__one_time__match_is_replaced()
+{
char *replaced = searchandreplace("X","X","Y");
assert_non_null(replaced);
@@ -40,7 +43,8 @@ replace_single_char__one_time__match_is_replaced() {
}
static void
-replace_single_char__multiple_times__match_all_matches_are_replaced() {
+replace_single_char__multiple_times__match_all_matches_are_replaced()
+{
char *replaced = searchandreplace("XaX","X","Y");
assert_non_null(replaced);
@@ -50,7 +54,8 @@ replace_single_char__multiple_times__match_all_matches_are_replaced() {
}
static void
-replace_longer_text__multiple_times__match_all_matches_are_replaced() {
+replace_longer_text__multiple_times__match_all_matches_are_replaced()
+{
char *replaced = searchandreplace("XXaXX","XX","YY");
assert_non_null(replaced);
@@ -60,7 +65,8 @@ replace_longer_text__multiple_times__match_all_matches_are_replaced() {
}
static void
-pattern_not_found__returns_original() {
+pattern_not_found__returns_original()
+{
char *replaced = searchandreplace("abc","X","Y");
assert_non_null(replaced);
@@ -71,7 +77,8 @@ pattern_not_found__returns_original() {
int
-main(void) {
+main(void)
+{
const struct CMUnitTest tests[] = {
cmocka_unit_test(pass_any_null_param__returns_null),
cmocka_unit_test(pass_any_empty_string__returns_null),