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

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