Skip to contentSkip to conversation

unit: Add graceful fail of pem, tls and key tests

PATCH Applied Brian Gix 2 participants 2 messages Feb 26, 2020 – Mar 12, 2020

lore
Share & tools
lore

Brian Gix

author
#0 lore raw

PATCH 1/1 unit: Add graceful fail of pem, tls and key tests

Unit tests for PEM, TLS and KEY require the pkcs8_key_parser module to be running in the kernel, however not all kernels have this running by default. This checks for this possibility and aborts these tests with exit(1) rather than an assert, and includes instruction to correct the issue.

---
 unit/test-key.c |  9 +++++++++
 unit/test-pem.c |  9 +++++++++
 unit/test-tls.c | 12 +++++++++++-
 3 files changed, 29 insertions(+), 1 deletion(-)
unit/test-key.c +9 -0
index 697ff47..240a02c 100644
@@ -569,6 +569,15 @@ static void test_key_crypto(const void *data)
 
 	privkey = l_pem_load_private_key(CERTDIR "cert-client-key-pkcs8.pem",
 						NULL, NULL);
+	if (!privkey) {
+		l_info("* Some kernel versions do not automatically load\n"
+			"* the pkcs8_key_parser module. If the system running\n"
+			"* test has not loaded this module, a failure here is\n"
+			"* likely. Running \"modprobe pkcs8_key_parser\" may\n"
+			"* correct this issue.\n");
+		exit(1);
+	}
+
 	assert(privkey);
 	success = l_key_get_info(privkey, rsa, hash, &keybits, &is_public);
 	assert(success);
unit/test-pem.c +9 -0
index d39003e..a1e8110 100644
@@ -216,6 +216,15 @@ static void test_priv_key_from_data(const void *data)
 	key = l_pem_load_private_key_from_data(raw_private_key,
 						strlen(raw_private_key),
 						"abc", &is_encrypted);
+	if (!key) {
+		l_info("* Some kernel versions do not automatically load\n"
+			"* the pkcs8_key_parser module. If the system running\n"
+			"* test has not loaded this module, a failure here is\n"
+			"* likely. Running \"modprobe pkcs8_key_parser\" may\n"
+			"* correct this issue.\n");
+		exit(1);
+	}
+
 	assert(key);
 	assert(is_encrypted);
 
unit/test-tls.c +11 -1
index 1d47787..3519376 100644
@@ -562,8 +562,18 @@ static void test_tls_with_ver(const struct tls_conn_test *test,
 			l_pem_load_private_key(test->server_key_path,
 						test->server_key_passphrase,
 						NULL);
-		assert(server_cert);
+		if (!server_key) {
+			l_info("* Some kernel versions do not automatically\n"
+				"* load the pkcs8_key_parser module. If the\n"
+				"* system running test has not loaded this\n"
+				"* module, a failure here is likely. Running\n"
+				"* \"modprobe pkcs8_key_parser\" may correct\n"
+				"* this issue.\n");
+			exit(1);
+		}
+
 		assert(server_key);
+		assert(server_cert);
 
 		assert(l_tls_set_auth_data(s[0].tls, server_cert, server_key));
 	}
Signature · 1 line
2.21.1
#1 lore raw

Hi Brian,

Quoted 11 lines · Brian Gix

Unit tests for PEM, TLS and KEY require the pkcs8_key_parser module to be running in the kernel, however not all kernels have this running by default. This checks for this possibility and aborts these tests with exit(1) rather than an assert, and includes instruction to correct the issue.

---
  unit/test-key.c |  9 +++++++++
  unit/test-pem.c |  9 +++++++++
  unit/test-tls.c | 12 +++++++++++-
  3 files changed, 29 insertions(+), 1 deletion(-)

Applied, thanks.

Regards,
-Denis