diff options
author | Maximilian Hils <git@maximilianhils.com> | 2017-05-04 16:24:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-04 16:24:57 +0200 |
commit | d734f6bbd680749449f2a7b28e4b23d25deba9ee (patch) | |
tree | 073ae49879a5f04bf4084190cc53c4dd323e53df /test | |
parent | 40f387eb48c192391fcf265e05d0605217b58ea7 (diff) | |
parent | 154e8ac0fc1b1553beaba2a73de1130e681a61c0 (diff) | |
download | mitmproxy-d734f6bbd680749449f2a7b28e4b23d25deba9ee.tar.gz mitmproxy-d734f6bbd680749449f2a7b28e4b23d25deba9ee.tar.bz2 mitmproxy-d734f6bbd680749449f2a7b28e4b23d25deba9ee.zip |
Merge pull request #2286 from charlesdhdt/master
Added LDAP Auth
Diffstat (limited to 'test')
-rw-r--r-- | test/mitmproxy/addons/test_proxyauth.py | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/test/mitmproxy/addons/test_proxyauth.py b/test/mitmproxy/addons/test_proxyauth.py index 86621709..58e059ad 100644 --- a/test/mitmproxy/addons/test_proxyauth.py +++ b/test/mitmproxy/addons/test_proxyauth.py @@ -1,4 +1,5 @@ import binascii +import ldap3 import pytest @@ -41,6 +42,20 @@ def test_configure(): ctx.configure(up, proxyauth=None) assert not up.nonanonymous + ctx.configure(up, proxyauth="ldap:fake_server:fake_dn:fake_group") + assert up.ldapserver + + ctx.configure(up, proxyauth="ldap:fake_server:uid=?,dc=example,dc=com:person") + assert up.ldapserver + ctx.configure(up, proxyauth="ldaps:fake_server.com:uid=?,dc=example,dc=com:person") + assert up.ldapserver + + with pytest.raises(exceptions.OptionsError): + ctx.configure(up, proxyauth="ldap:fake_serveruid=?dc=example,dc=com:person") + + with pytest.raises(exceptions.OptionsError): + ctx.configure(up, proxyauth="ldapssssssss:fake_server.com:uid=?,dc=example,dc=com:person") + with pytest.raises(exceptions.OptionsError): ctx.configure( up, @@ -67,7 +82,7 @@ def test_configure(): ctx.configure(up, proxyauth="any", mode="socks5") -def test_check(): +def test_check(monkeypatch): up = proxyauth.ProxyAuth() with taddons.context() as ctx: ctx.configure(up, proxyauth="any", mode="regular") @@ -109,6 +124,27 @@ def test_check(): ) assert not up.check(f) + ctx.configure( + up, + proxyauth="ldap:fake-server:cn=?,ou=test,o=lab:test" + ) + conn = ldap3.Connection("fake-server", user="cn=user0,ou=test,o=lab", password="password", client_strategy=ldap3.MOCK_SYNC) + conn.bind() + conn.strategy.add_entry('cn=user0,ou=test,o=lab', {'userPassword': 'test0', 'sn': 'user0_sn', 'revision': 0, 'objectClass': 'test'}) + + def conn_mp(ldap, user, password, **kwargs): + return conn + + monkeypatch.setattr(ldap3, "Connection", conn_mp) + f.request.headers["Proxy-Authorization"] = proxyauth.mkauth( + "user0", "test0" + ) + assert up.check(f) + f.request.headers["Proxy-Authorization"] = proxyauth.mkauth( + "", "" + ) + assert not up.check(f) + def test_authenticate(): up = proxyauth.ProxyAuth() |