diff --git a/smbprotocol/session.py b/smbprotocol/session.py index 72ed7977edae93a57f159c9ba96f5a4895f12e4d..c5e724699cc0d787f3f3ce9da3eef28c96836aad 100644 --- a/smbprotocol/session.py +++ b/smbprotocol/session.py @@ -289,7 +289,7 @@ class Session(object): 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) diff --git a/tests/test_smbclient_os.py b/tests/test_smbclient_os.py index fccb9dd5d7fe0436909b62f997983da06c22e02e..1ffb40a2105f55309d67aa3b67ee15229081e192 100644 --- a/tests/test_smbclient_os.py +++ b/tests/test_smbclient_os.py @@ -39,6 +39,12 @@ from smbprotocol.reparse_point import ( ReparseTags, ) +HAS_SSPI = False +try: + import sspi +except ImportError: + pass + @pytest.mark.parametrize('path', [ '\\\\only_server', @@ -53,10 +59,12 @@ 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): @@ -64,9 +72,10 @@ def test_delete_session(smb_share): 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):