Blame SOURCES/0005-ipatests-test-Samba-mount-with-NTLM-authentication_rhbz#1932289.patch

ccffd0
From 80ccac79b9d123e158a5ba60f9853611d0854188 Mon Sep 17 00:00:00 2001
ccffd0
From: Sergey Orlov <sorlov@redhat.com>
ccffd0
Date: Wed, 17 Feb 2021 16:48:33 +0100
ccffd0
Subject: [PATCH] ipatests: test Samba mount with NTLM authentication
ccffd0
ccffd0
Related to https://pagure.io/freeipa/issue/8636
ccffd0
ccffd0
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
ccffd0
---
ccffd0
 ipatests/pytest_ipa/integration/__init__.py | 17 ++++++
ccffd0
 ipatests/test_integration/test_smb.py       | 63 +++++++++++++++++++++
ccffd0
 2 files changed, 80 insertions(+)
ccffd0
ccffd0
diff --git a/ipatests/pytest_ipa/integration/__init__.py b/ipatests/pytest_ipa/integration/__init__.py
ccffd0
index 55291ae8b..f62b667bd 100644
ccffd0
--- a/ipatests/pytest_ipa/integration/__init__.py
ccffd0
+++ b/ipatests/pytest_ipa/integration/__init__.py
ccffd0
@@ -28,12 +28,14 @@ import os
ccffd0
 import tempfile
ccffd0
 import shutil
ccffd0
 import re
ccffd0
+import functools
ccffd0
 
ccffd0
 import pytest
ccffd0
 from pytest_multihost import make_multihost_fixture
ccffd0
 
ccffd0
 from ipapython import ipautil
ccffd0
 from ipaplatform.paths import paths
ccffd0
+from . import fips
ccffd0
 from .config import Config
ccffd0
 from .env_config import get_global_config
ccffd0
 from . import tasks
ccffd0
@@ -478,3 +480,18 @@ def del_compat_attrs(cls):
ccffd0
         del cls.ad_subdomains
ccffd0
         del cls.ad_treedomains
ccffd0
     del cls.ad_domains
ccffd0
+
ccffd0
+
ccffd0
+def skip_if_fips(reason='Not supported in FIPS mode', host='master'):
ccffd0
+    if callable(reason):
ccffd0
+        raise TypeError('Invalid decorator usage, add "()"')
ccffd0
+
ccffd0
+    def decorator(test_method):
ccffd0
+        @functools.wraps(test_method)
ccffd0
+        def wrapper(instance, *args, **kwargs):
ccffd0
+            if fips.is_fips_enabled(getattr(instance, host)):
ccffd0
+                pytest.skip(reason)
ccffd0
+            else:
ccffd0
+                test_method(instance, *args, **kwargs)
ccffd0
+        return wrapper
ccffd0
+    return decorator
ccffd0
diff --git a/ipatests/test_integration/test_smb.py b/ipatests/test_integration/test_smb.py
ccffd0
index 37725ab15..749a96325 100644
ccffd0
--- a/ipatests/test_integration/test_smb.py
ccffd0
+++ b/ipatests/test_integration/test_smb.py
ccffd0
@@ -19,6 +19,7 @@ from ipatests.test_integration.base import IntegrationTest
ccffd0
 from ipatests.pytest_ipa.integration import tasks
ccffd0
 from ipaplatform.osinfo import osinfo
ccffd0
 from ipaplatform.paths import paths
ccffd0
+from ipatests.pytest_ipa.integration import skip_if_fips
ccffd0
 
ccffd0
 
ccffd0
 def wait_smbd_functional(host):
ccffd0
@@ -378,6 +379,68 @@ class TestSMB(IntegrationTest):
ccffd0
         finally:
ccffd0
             self.cleanup_mount(mountpoint)
ccffd0
 
ccffd0
+    def check_repeated_smb_mount(self, options):
ccffd0
+        mountpoint = '/mnt/smb'
ccffd0
+        unc = '//{}/homes'.format(self.smbserver.hostname)
ccffd0
+        test_file = 'ntlm_test'
ccffd0
+        test_file_server_path = '/home/{}/{}'.format(self.ipa_user1, test_file)
ccffd0
+        test_file_client_path = '{}/{}'.format(mountpoint, test_file)
ccffd0
+
ccffd0
+        self.smbclient.run_command(['mkdir', '-p', mountpoint])
ccffd0
+        self.smbserver.put_file_contents(test_file_server_path, '')
ccffd0
+        try:
ccffd0
+            for i in [1, 2]:
ccffd0
+                res = self.smbclient.run_command([
ccffd0
+                    'mount', '-t', 'cifs', unc, mountpoint, '-o', options],
ccffd0
+                    raiseonerr=False)
ccffd0
+                assert res.returncode == 0, (
ccffd0
+                    'Mount failed at iteration {}. Output: {}'
ccffd0
+                    .format(i, res.stdout_text + res.stderr_text))
ccffd0
+                assert self.smbclient.transport.file_exists(
ccffd0
+                    test_file_client_path)
ccffd0
+                self.smbclient.run_command(['umount', mountpoint])
ccffd0
+        finally:
ccffd0
+            self.cleanup_mount(mountpoint)
ccffd0
+            self.smbserver.run_command(['rm', '-f', test_file_server_path])
ccffd0
+
ccffd0
+    @skip_if_fips()
ccffd0
+    def test_ntlm_authentication_with_auto_domain(self):
ccffd0
+        """Repeatedly try to authenticate with username and password with
ccffd0
+        automatic domain discovery.
ccffd0
+
ccffd0
+        This is a regression test for https://pagure.io/freeipa/issue/8636
ccffd0
+        """
ccffd0
+        tasks.kdestroy_all(self.smbclient)
ccffd0
+
ccffd0
+        mount_options = 'user={user},pass={password},domainauto'.format(
ccffd0
+            user=self.ipa_user1,
ccffd0
+            password=self.ipa_user1_password
ccffd0
+        )
ccffd0
+
ccffd0
+        self.check_repeated_smb_mount(mount_options)
ccffd0
+
ccffd0
+    @skip_if_fips()
ccffd0
+    def test_ntlm_authentication_with_upn_with_lowercase_domain(self):
ccffd0
+        tasks.kdestroy_all(self.smbclient)
ccffd0
+
ccffd0
+        mount_options = 'user={user}@{domain},pass={password}'.format(
ccffd0
+            user=self.ipa_user1,
ccffd0
+            password=self.ipa_user1_password,
ccffd0
+            domain=self.master.domain.name.lower()
ccffd0
+        )
ccffd0
+        self.check_repeated_smb_mount(mount_options)
ccffd0
+
ccffd0
+    @skip_if_fips()
ccffd0
+    def test_ntlm_authentication_with_upn_with_uppercase_domain(self):
ccffd0
+        tasks.kdestroy_all(self.smbclient)
ccffd0
+
ccffd0
+        mount_options = 'user={user}@{domain},pass={password}'.format(
ccffd0
+            user=self.ipa_user1,
ccffd0
+            password=self.ipa_user1_password,
ccffd0
+            domain=self.master.domain.name.upper()
ccffd0
+        )
ccffd0
+        self.check_repeated_smb_mount(mount_options)
ccffd0
+
ccffd0
     def test_uninstall_samba(self):
ccffd0
         self.smbserver.run_command(['ipa-client-samba', '--uninstall', '-U'])
ccffd0
         res = self.smbserver.run_command(
ccffd0
-- 
ccffd0
2.29.2
ccffd0