def test_ntlm_iov_not_available(): expected = "The system is missing the GSSAPI IOV extension headers or NTLM is being requested, cannot utilitze " \ "wrap_iov and unwrap_iov" with pytest.raises(FeatureMissingError, match=re.escape(expected)): ntlm.NTLMProxy('user', 'pass', options=spnego.NegotiateOptions.wrapping_iov)
def test_ntlm_no_encoding_flags(): negotiate = memoryview(bytearray(get_data('ntlm_negotiate'))) negotiate[12:16] = b"\x00\x00\x00\x00" n = ntlm.NTLMProxy('user', 'pass') with pytest.raises( SpnegoError, match= "Neither NEGOTIATE_OEM or NEGOTIATE_UNICODE flags were set, cannot derive " "encoding for text fields"): n._step_accept_negotiate(negotiate.tobytes())
def test_ntlm_sign_qop_invalid(): n = ntlm.NTLMProxy('user', 'pass') with pytest.raises(UnsupportedQop, match="Unsupported QoP value 1 specified for NTLM"): n.sign(b"data", qop=1)
def test_ntlm_unwrap_iov_fail(): n = ntlm.NTLMProxy('user', 'pass') with pytest.raises(OperationNotAvailableError, match="NTLM does not offer IOV wrapping"): n.unwrap_iov([])
def test_ntlm_wrap_no_sign_or_seal(): n = ntlm.NTLMProxy('user', 'pass') with pytest.raises(OperationNotAvailableError, match="NTLM wrap without integrity or confidentiality"): n.wrap(b"data")
def test_ntlm_invalid_protocol(): with pytest.raises( ValueError, match= "Invalid protocol 'fake', must be ntlm, kerberos, or negotiate"): ntlm.NTLMProxy('user', 'pass', protocol='fake')
def test_ntlm_invalid_usage(): with pytest.raises( ValueError, match="Invalid usage 'test', must be initiate or accept"): ntlm.NTLMProxy('user', 'pass', usage='test')
def test_context_no_store(usage): with pytest.raises( OperationNotAvailableError, match="Retrieving NTLM store without NTLM_USER_FILE set to a " "filepath"): ntlm.NTLMProxy(None, None, usage=usage)
def test_invalid_lm_compat_level(level, monkeypatch): monkeypatch.setenv('LM_COMPAT_LEVEL', to_native(level)) expected = "Invalid LM_COMPAT_LEVEL %s, must be between 0 and 5" % level with pytest.raises(SpnegoError, match=re.escape(expected)): ntlm.NTLMProxy("user", "pass")