richardphibel / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone

Blame SOURCES/0024-Add-unittest-for-setting-up-repo-with-empty-keyfile-RhBug1994614.patch

1ff477
From 551a83052ff92fa975f1015e2fc25b174f85b0e6 Mon Sep 17 00:00:00 2001
1ff477
From: Aleš Matěj <amatej@redhat.com>
1ff477
Date: Tue, 26 Oct 2021 09:33:51 +0200
1ff477
Subject: [PATCH] Add unittest for setting up repo with empty keyfile (RhBug:1994614)
1ff477
1ff477
The test ensures we don't crash when the keyfile is empty/not loaded.
1ff477
Test for: https://github.com/rpm-software-management/libdnf/commit/be66d0908d939ddaf3022c5489012bd1dbdb0075
1ff477
1ff477
RHEL bug:
1ff477
https://bugzilla.redhat.com/show_bug.cgi?id=1994614
1ff477
Fedora bug:
1ff477
https://bugzilla.redhat.com/show_bug.cgi?id=1946024
1ff477
---
1ff477
 tests/libdnf/dnf-self-test.c | 21 +++++++++++++++++++++
1ff477
 1 file changed, 21 insertions(+)
1ff477
1ff477
diff --git a/tests/libdnf/dnf-self-test.c b/tests/libdnf/dnf-self-test.c
1ff477
index 32a21e6..5295837 100644
1ff477
--- a/tests/libdnf/dnf-self-test.c
1ff477
+++ b/tests/libdnf/dnf-self-test.c
1ff477
@@ -199,6 +199,26 @@ ch_test_repo_func(void)
1ff477
     g_object_unref(context);
1ff477
 }
1ff477
 
1ff477
+static void
1ff477
+dnf_repo_setup_with_empty_keyfile(void)
1ff477
+{
1ff477
+    DnfContext *context = dnf_context_new();
1ff477
+    dnf_context_set_release_ver(context, "33");
1ff477
+    DnfRepo *repo = dnf_repo_new(context);
1ff477
+    GKeyFile *empty_key_file = g_key_file_new();
1ff477
+
1ff477
+    dnf_repo_set_keyfile(repo, empty_key_file);
1ff477
+
1ff477
+    GError *error = NULL;
1ff477
+    // Empty key file is not an errror, there is just no configuration to be loaded.
1ff477
+    g_assert(dnf_repo_setup(repo, &error));
1ff477
+    g_assert_no_error(error);
1ff477
+
1ff477
+    g_object_unref(repo);
1ff477
+    g_object_unref(context);
1ff477
+    g_key_file_free(empty_key_file);
1ff477
+}
1ff477
+
1ff477
 static guint _allow_cancel_updates = 0;
1ff477
 static guint _action_updates = 0;
1ff477
 static guint _package_progress_updates = 0;
1ff477
@@ -1217,6 +1237,7 @@ main(int argc, char **argv)
1ff477
     g_test_add_func("/libdnf/lock", dnf_lock_func);
1ff477
     g_test_add_func("/libdnf/lock[threads]", dnf_lock_threads_func);
1ff477
     g_test_add_func("/libdnf/repo", ch_test_repo_func);
1ff477
+    g_test_add_func("/libdnf/repo_empty_keyfile", dnf_repo_setup_with_empty_keyfile);
1ff477
     g_test_add_func("/libdnf/state", dnf_state_func);
1ff477
     g_test_add_func("/libdnf/state[child]", dnf_state_child_func);
1ff477
     g_test_add_func("/libdnf/state[parent-1-step]", dnf_state_parent_one_step_proxy_func);
1ff477
--
1ff477
libgit2 1.1.0
1ff477