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

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