[gnome-autoar/wip/oholy/compressor-encryption: 2/2] tests: Add password argument for test utils




commit 9c22c01795452d06b213767d6ed7cb6cc528daba
Author: Ondrej Holy <oholy redhat com>
Date:   Wed Jun 2 10:07:01 2021 +0200

    tests: Add password argument for test utils
    
    The test utils doesn't support encrypted archives as it is not possible
    to specify password currently. Let's simply add an password argument to
    have a simple way to test this feature.

 tests/test-create.c  | 11 +++++++----
 tests/test-extract.c | 20 ++++++++++++++++++--
 2 files changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/tests/test-create.c b/tests/test-create.c
index a5bd325..d4139ca 100644
--- a/tests/test-create.c
+++ b/tests/test-create.c
@@ -53,16 +53,16 @@ main (int argc,
   g_autoptr (GFile) output_file = NULL;
   int i;
 
-  if (argc < 5) {
-    g_printerr ("Usage: %s format filter output_dir source ...\n", argv[0]);
+  if (argc < 6) {
+    g_printerr ("Usage: %s format filter passphrase output_dir source ...\n", argv[0]);
     return 255;
   }
 
   setlocale (LC_ALL, "");
 
-  output_file = g_file_new_for_commandline_arg (argv[3]);
+  output_file = g_file_new_for_commandline_arg (argv[4]);
 
-  for (i = 4; i < argc; ++i) {
+  for (i = 5; i < argc; ++i) {
     source_files = g_list_prepend (source_files,
                                    g_file_new_for_commandline_arg (argv[i]));
   }
@@ -74,6 +74,9 @@ main (int argc,
                                       atoi (argv[1]),
                                       atoi (argv[2]),
                                       TRUE);
+  if (argv[3][0] != '\0')
+    autoar_compressor_set_passphrase (compressor, argv[3]);
+
   g_signal_connect (compressor, "decide-dest", G_CALLBACK (my_handler_decide_dest), NULL);
   g_signal_connect (compressor, "progress", G_CALLBACK (my_handler_progress), NULL);
   g_signal_connect (compressor, "error", G_CALLBACK (my_handler_error), NULL);
diff --git a/tests/test-extract.c b/tests/test-extract.c
index f92c999..6e84045 100644
--- a/tests/test-extract.c
+++ b/tests/test-extract.c
@@ -83,6 +83,17 @@ my_handler_completed (AutoarExtractor *extractor,
   g_print ("\nCompleted!\n");
 }
 
+static gchar *
+my_handler_request_passphrase (AutoarExtractor *extractor,
+                               gpointer data)
+{
+  const gchar *passphrase = data;
+
+  g_print ("Passphrase requested!\n");
+
+  return g_strdup (passphrase);
+}
+
 int
 main (int argc,
       char *argv[])
@@ -91,9 +102,10 @@ main (int argc,
   char *content;
   g_autoptr (GFile) source = NULL;
   g_autoptr (GFile) output = NULL;
+  g_autofree gchar *passphrase = NULL;
 
-  if (argc < 3) {
-    g_printerr ("Usage: %s archive_file output_dir\n",
+  if (argc < 3 || argc > 4) {
+    g_printerr ("Usage: %s archive_file output_dir passphrase\n",
                 argv[0]);
     return 255;
   }
@@ -104,6 +116,9 @@ main (int argc,
 
   source = g_file_new_for_commandline_arg (argv[1]);
   output = g_file_new_for_commandline_arg (argv[2]);
+  if (argc == 4 && argv[3][0] != '\0')
+    passphrase = g_strdup (argv[3]);
+
   extractor = autoar_extractor_new (source, output);
 
   autoar_extractor_set_delete_after_extraction (extractor, FALSE);
@@ -114,6 +129,7 @@ main (int argc,
   g_signal_connect (extractor, "conflict", G_CALLBACK (my_handler_conflict), NULL);
   g_signal_connect (extractor, "error", G_CALLBACK (my_handler_error), NULL);
   g_signal_connect (extractor, "completed", G_CALLBACK (my_handler_completed), NULL);
+  g_signal_connect (extractor, "request-passphrase", G_CALLBACK (my_handler_request_passphrase), passphrase);
 
   autoar_extractor_start (extractor, NULL);
 


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