[gnome-remote-desktop] tests/tpm: Skip tests when TPM module not compatible



commit 2cb04c481e100a7756edbb535eb3847284e3cb6c
Author: Jonas Ådahl <jadahl gmail com>
Date:   Fri Aug 5 23:09:18 2022 +0200

    tests/tpm: Skip tests when TPM module not compatible

 tests/tpm-test.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)
---
diff --git a/tests/tpm-test.c b/tests/tpm-test.c
index 8bbcc87d..f9af78d4 100644
--- a/tests/tpm-test.c
+++ b/tests/tpm-test.c
@@ -48,6 +48,24 @@ test_tpm_caps (void)
     }
 }
 
+static gboolean
+check_compatibility (GrdTpm *tpm)
+{
+  g_autoptr (GError) error = NULL;
+
+  if (!grd_tpm_check_capabilities (tpm, &error))
+    {
+      if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
+        return FALSE;
+      else
+        g_error ("Failed tocheck TPM 2.0 compatibility: %s", error->message);
+    }
+  else
+    {
+      return TRUE;
+    }
+}
+
 static void
 test_tpm_write (void)
 {
@@ -63,6 +81,12 @@ test_tpm_write (void)
   if (!tpm)
     g_error ("Failed to create TPM credentials manager: %s", error->message);
 
+  if (!check_compatibility (tpm))
+    {
+      g_test_skip ("TPM module not compatible");
+      return;
+    }
+
   if (!grd_tpm_create_primary (tpm, &primary_handle, &error))
     g_error ("Failed to create primary: %s", error->message);
 
@@ -101,12 +125,18 @@ test_tpm_read (void)
   g_autofree TPML_DIGEST *pcr_digest = NULL;
   g_autofree char *secret = NULL;
 
-  g_assert_nonnull (secret_variant);
-
   tpm = grd_tpm_new (GRD_TPM_MODE_READ, &error);
   if (!tpm)
     g_error ("Failed to create TPM credentials reader: %s", error->message);
 
+  if (!check_compatibility (tpm))
+    {
+      g_test_skip ("TPM module not compatible");
+      return;
+    }
+
+  g_assert_nonnull (secret_variant);
+
   if (!grd_tpm_read_pcr (tpm, &pcr_selection, &pcr_digest, &error))
     g_error ("Failed to read PCR: %s", error->message);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]