Skip to content

Commit

Permalink
Attempt to get tests working again on pywin32
Browse files Browse the repository at this point in the history
  • Loading branch information
jborean93 committed Nov 30, 2019
1 parent 20e85a6 commit 8895db2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion smbprotocol/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def connect(self):
server_mechs = list(
token['innerContextToken']['negTokenInit']['mechTypes']
)
if MechTypes.MS_KRB5 in server_mechs and MechTypes.KRB5:
if MechTypes.MS_KRB5 in server_mechs and MechTypes.KRB5 in server_mechs:
log.debug("Both MS_KRB5 and KRB5 received in the initial SPNGEO "
"token, removing MS_KRB5 to avoid duplication of work")
server_mechs.remove(MechTypes.MS_KRB5)
Expand Down
23 changes: 16 additions & 7 deletions tests/test_smbclient_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
ReparseTags,
)

HAS_SSPI = False
try:
import sspi
except ImportError:
pass


@pytest.mark.parametrize('path', [
'\\\\only_server',
Expand All @@ -53,20 +59,23 @@ def test_open_bad_path(path):
def test_reset_connection(smb_share):
smbclient.reset_connection_cache()

# Once we've reset the connection it should fail because we didn't set any credentials
expected = 'Failed to authenticate with server'
with pytest.raises(SMBAuthenticationError, match=expected):
smbclient.stat(smb_share)
# Once we've reset the connection it should fail because we didn't set any credentials.
# Won't work if pywin32 is installed as implicit auth is available.
if not HAS_SSPI:
expected = 'Failed to authenticate with server'
with pytest.raises(SMBAuthenticationError, match=expected):
smbclient.stat(smb_share)


def test_delete_session(smb_share):
server = ntpath.normpath(smb_share).split("\\")[2]
smbclient.delete_session(server)

# Once we've closed the connection it should fail because we didn't set any credentials
expected = 'Failed to authenticate with server'
with pytest.raises(SMBAuthenticationError, match=expected):
smbclient.stat(smb_share)
if not HAS_SSPI:
expected = 'Failed to authenticate with server'
with pytest.raises(SMBAuthenticationError, match=expected):
smbclient.stat(smb_share)


def test_copy_across_paths_raises(smb_share):
Expand Down

0 comments on commit 8895db2

Please sign in to comment.