From 034e042ac95da4c8a21535059f43d1fe49f4fbaa Mon Sep 17 00:00:00 2001 From: Robin Newton Date: Fri, 15 Dec 2023 14:52:39 +0000 Subject: [PATCH] CA-386281 CIFS username can be omitted in ISO SR ISOSR falling over when no username is given is a regression that looks to have been introduced in commit cbd7226b012d145b52ef50c45c69987d4050b12a when the use of a credentials file was removed. The ISOSR unit tests were already covered cases of not having credentials - as evinced by having "guest" in the expected mount options. However, they were doing this in a rather confused way that hid the bug by supplying a username regardless. Now only the credentials tests do this. Signed-off-by: Robin Newton --- drivers/ISOSR.py | 7 +++---- tests/test_ISOSR.py | 13 +++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/ISOSR.py b/drivers/ISOSR.py index 296cbca20..f591d2371 100755 --- a/drivers/ISOSR.py +++ b/drivers/ISOSR.py @@ -546,13 +546,12 @@ def appendCIFSMountOptions(self, mountcmd): if not cifutils.containsCredentials(self.dconf, prefix="cifs"): options.append('guest') + domain = None + else: + _, domain = cifutils.splitDomainAndUsername(self.dconf['username']) options.append(self.getSMBVersion()) - username, domain = ( - cifutils.splitDomainAndUsername(self.dconf['username']) - ) - if domain: options.append('domain=' + domain) except: diff --git a/tests/test_ISOSR.py b/tests/test_ISOSR.py index 03a49618d..456e5ca5d 100644 --- a/tests/test_ISOSR.py +++ b/tests/test_ISOSR.py @@ -194,16 +194,14 @@ class TestISOSR_overSMB(unittest.TestCase): def create_smbisosr(self, location='\\aServer\aLocation', atype=None, sr_uuid='asr_uuid', server='\\aServer', - serverpath='/aServerpath', username='aUsername', - password='aPassword', vers=None, options='', + serverpath='/aServerpath', + vers=None, options='', dconf_update={}): srcmd = mock.Mock() srcmd.dconf = { 'location': location, 'server': server, 'serverpath': serverpath, - 'username': username, - 'password': password, 'options': options } if vers: @@ -252,7 +250,7 @@ def test_attach_with_smb_credentials(self, context, _checkmount, pread, Positive case, over XC/XE CLI with version 1.0. """ context.setup_error_codes() - update = {'cifspassword': 'winter2019'} + update = {'username': 'dot', 'cifspassword': 'winter2019'} smbsr = self.create_smbisosr(atype='cifs', vers='1.0', dconf_update=update) _checkmount.side_effect = [False, True] @@ -260,7 +258,7 @@ def test_attach_with_smb_credentials(self, context, _checkmount, pread, pread.assert_called_with(['mount.cifs', '\\aServer\x07Location', '/var/run/sr-mount/asr_uuid', '-o', 'cache=none,vers=1.0'], True, - new_env={'PASSWD': 'winter2019', 'USER': 'aUsername'}) + new_env={'PASSWD': 'winter2019', 'USER': 'dot'}) @testlib.with_context @mock.patch('util.makedirs') @@ -274,9 +272,8 @@ def test_attach_with_smb_credentials_domain(self, context, Positive case, over XC/XE CLI with version 1.0. """ context.setup_error_codes() - update = {'cifspassword': 'winter2019'} + update = {'username': r'citrix\jsmith', 'cifspassword': 'winter2019'} smbsr = self.create_smbisosr(atype='cifs', vers='1.0', - username=r'citrix\jsmith', dconf_update=update) _checkmount.side_effect = [False, True] smbsr.attach(None)