def test_username_bad_domain_smbsr(self): junk_dconf = { "password_secret": "123", "username": "******" } junk_session = 123 with self.assertRaises(cifutils.CIFSException) as cm: cifutils.getCIFCredentials(junk_dconf, junk_session) expected_message = ("A maximum of 2 tokens are expected " "(<domain>\<username>). 3 were given.") the_exception = cm.exception self.assertEqual(the_exception.errstr, expected_message)
def mount(self, mountpoint=None): mountpoint = self.makeMountPoint(mountpoint) new_env, domain = cifutils.getCIFCredentials(self.dconf, self.session) options = self.getMountOptions(domain) if options: options = ",".join(str(x) for x in options if x) try: util.ioretry(lambda: util.pread(["mount.cifs", self.remoteserver, mountpoint, "-o", options], new_env=new_env), errlist=[errno.EPIPE, errno.EIO], maxretry=2, nofail=True) except util.CommandException as inst: raise SMBException("mount failed with return code %d" % inst.code) # Sanity check to ensure that the user has at least RO access to the # mounted share. Windows sharing and security settings can be tricky. try: util.listdir(mountpoint) except util.CommandException: try: self.unmount(mountpoint, True) except SMBException: util.logException('SMBSR.unmount()') raise SMBException("Permission denied. " "Please check user privileges.")
def test_empty_credentials_and_domain_for_bad_dconf(self): junk_dconf = {"junk1": "123"} junk_session = 123 credentials, domain = cifutils.getCIFCredentials(junk_dconf, junk_session, prefix="cifs") self.assertEquals(credentials, None) self.assertEquals(domain, None)
def test_password_and_username_domain_smbsr(self): junk_dconf = {"password": "******", "username": "******"} junk_session = 123 credentials, domain = cifutils.getCIFCredentials( junk_dconf, junk_session) expected_credentials = {"USER": "******", "PASSWD": "123"} self.assertEquals(credentials, expected_credentials) self.assertEquals(domain, "citrix")
def test_password_and_username(self): junk_dconf = {"cifspassword": "******", "username": "******"} junk_session = 123 credentials, domain = cifutils.getCIFCredentials(junk_dconf, junk_session, prefix="cifs") expected_credentials = {"USER": "******", "PASSWD": "123"} self.assertEquals(credentials, expected_credentials) self.assertEquals(domain, None)
def test_password_secret_and_username_smbsr(self, get_secret): junk_dconf = {"password_secret": "123", "username": "******"} junk_session = 123 get_secret.return_value = 'winter2019' credentials, domain = cifutils.getCIFCredentials( junk_dconf, junk_session) expected_credentials = {"USER": "******", "PASSWD": "winter2019"} get_secret.assert_called_with(junk_session, "123") self.assertEquals(credentials, expected_credentials) self.assertEquals(domain, None)
def mountOverSMB(self, mountcmd): """This function raises util.CommandException""" new_env, domain = cifutils.getCIFCredentials(self.dconf, self.session, prefix="cifs") util.pread(mountcmd, True, new_env=new_env) try: if not self.is_smbversion_specified: # Store the successful smb version in PBD config self.updateSMBVersInPBDConfig() except Exception as exc: util.SMlog("Exception: %s" % str(exc)) if self._checkmount(): util.pread(["umount", self.mountpoint]) raise util.CommandException
def mount(self, mountpoint=None): mountpoint = self.makeMountPoint(mountpoint) new_env, domain = cifutils.getCIFCredentials(self.dconf, self.session) options = self.getMountOptions(domain) if options: options = ",".join(str(x) for x in options if x) try: util.ioretry(lambda: util.pread(["mount.cifs", self.remoteserver, mountpoint, "-o", options], new_env=new_env), errlist=[errno.EPIPE, errno.EIO], maxretry=2, nofail=True) except util.CommandException, inst: raise SMBException("mount failed with return code %d" % inst.code)