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

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