From 743c7b46e463bef666dc84e9f513eb7dee7f59f6 Mon Sep 17 00:00:00 2001
From: Florence Blanc-Renaud <flo@redhat.com>
Date: Tue, 17 Sep 2024 14:48:58 +0200
Subject: [PATCH] test_adtrust_install: add --use-krb5-ccache to smbclient
 command

With samba 4.20.4 the smbclient commands needs a ccache otherwise it
prompts for a password.

Fixes: https://pagure.io/freeipa/issue/9666
Signed-off-by: Florence Blanc-Renaud <flo@redhat.com>
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
---
 .../test_integration/test_adtrust_install.py  | 28 ++++++++++++-------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/ipatests/test_integration/test_adtrust_install.py b/ipatests/test_integration/test_adtrust_install.py
index de252db1705ad940c3b5ee4df967d7c17a4203a7..79a91dfaa61276de74b10777c6d44b5942ed1be0 100644
--- a/ipatests/test_integration/test_adtrust_install.py
+++ b/ipatests/test_integration/test_adtrust_install.py
@@ -873,17 +873,25 @@ class TestIpaAdTrustInstall(IntegrationTest):
              "path", "/freeipa4234"])
         self.master.run_command(["touch", "before"])
         self.master.run_command(["touch", "after"])
-        self.master.run_command(
-            ["smbclient", "--use-kerberos=desired",
-             "-c=put before", "//{}/share".format(
-                 self.master.hostname)]
-        )
+        # Find cache for the admin user
+        cache_args = []
+        cache = tasks.get_credential_cache(self.master)
+        if cache:
+            cache_args = ["--use-krb5-ccache", cache]
+
+        cmd_args = ["smbclient", "--use-kerberos=desired"]
+        cmd_args.extend(cache_args)
+        cmd_args.extend([
+            "-c=put before", "//{}/share".format(self.master.hostname)
+        ])
+        self.master.run_command(cmd_args)
         self.master.run_command(
             ["net", "conf", "setparm", "share",
              "valid users", "@admins"])
-        result = self.master.run_command(
-            ["smbclient", "--use-kerberos=desired",
-             "-c=put after", "//{}/share".format(
-                 self.master.hostname)]
-        )
+        cmd_args = ["smbclient", "--use-kerberos=desired"]
+        cmd_args.extend(cache_args)
+        cmd_args.extend([
+            "-c=put after", "//{}/share".format(self.master.hostname)
+        ])
+        result = self.master.run_command(cmd_args)
         assert msg not in result.stdout_text
-- 
2.46.2