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

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