def test_authenticate_clean(self): ba = authentication.BasicProxyAuth(authentication.PassManNonAnon(), "test") headers = Headers() vals = ("basic", "foo", "bar") headers[ba.AUTH_HEADER] = authentication.assemble_http_basic_auth( *vals) assert ba.authenticate(headers) ba.clean(headers) assert ba.AUTH_HEADER not in headers headers[ba.AUTH_HEADER] = "" assert not ba.authenticate(headers) headers[ba.AUTH_HEADER] = "foo" assert not ba.authenticate(headers) vals = ("foo", "foo", "bar") headers[ba.AUTH_HEADER] = authentication.assemble_http_basic_auth( *vals) assert not ba.authenticate(headers) ba = authentication.BasicProxyAuth(authentication.PassMan(), "test") vals = ("basic", "foo", "bar") headers[ba.AUTH_HEADER] = authentication.assemble_http_basic_auth( *vals) assert not ba.authenticate(headers)
def test_authenticate_clean(self): ba = authentication.BasicProxyAuth(authentication.PassManNonAnon(), "test") headers = Headers() vals = ("basic", "foo", "bar") headers[ba.AUTH_HEADER] = authentication.assemble_http_basic_auth(*vals) assert ba.authenticate(headers) ba.clean(headers) assert ba.AUTH_HEADER not in headers headers[ba.AUTH_HEADER] = "" assert not ba.authenticate(headers) headers[ba.AUTH_HEADER] = "foo" assert not ba.authenticate(headers) vals = ("foo", "foo", "bar") headers[ba.AUTH_HEADER] = authentication.assemble_http_basic_auth(*vals) assert not ba.authenticate(headers) ba = authentication.BasicProxyAuth(authentication.PassMan(), "test") vals = ("basic", "foo", "bar") headers[ba.AUTH_HEADER] = authentication.assemble_http_basic_auth(*vals) assert not ba.authenticate(headers)
def test_simple(self): pm = authentication.PassManHtpasswd(tutils.test_data.path("data/htpasswd")) vals = ("basic", "test", "test") authentication.assemble_http_basic_auth(*vals) assert pm.test("test", "test") assert not pm.test("test", "foo") assert not pm.test("foo", "test") assert not pm.test("test", "") assert not pm.test("", "")
def test_simple(self): pm = authentication.PassManHtpasswd( tutils.test_data.path("mitmproxy/net/data/htpasswd")) vals = ("basic", "test", "test") authentication.assemble_http_basic_auth(*vals) assert pm.test("test", "test") assert not pm.test("test", "foo") assert not pm.test("foo", "test") assert not pm.test("test", "") assert not pm.test("", "")
def test_parse_http_basic_auth(): vals = ("basic", "foo", "bar") assert authentication.parse_http_basic_auth( authentication.assemble_http_basic_auth(*vals)) == vals assert not authentication.parse_http_basic_auth("") assert not authentication.parse_http_basic_auth("foo bar") v = "basic " + binascii.b2a_base64(b"foo").decode("ascii") assert not authentication.parse_http_basic_auth(v)
def test_parse_http_basic_auth(): vals = ("basic", "foo", "bar") assert authentication.parse_http_basic_auth( authentication.assemble_http_basic_auth(*vals) ) == vals assert not authentication.parse_http_basic_auth("") assert not authentication.parse_http_basic_auth("foo bar") v = "basic " + binascii.b2a_base64(b"foo").decode("ascii") assert not authentication.parse_http_basic_auth(v)
def test_auth(self): self.master.options.auth_singleuser = "******" assert self.pathod("202").status_code == 401 p = self.pathoc() with p.connect(): ret = p.request(""" get '/p/202' h'%s'='%s' """ % ( mitmproxy.net.http.authentication.BasicWebsiteAuth.AUTH_HEADER, authentication.assemble_http_basic_auth("basic", "test", "test") )) assert ret.status_code == 202