Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
    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("", "")
Пример #4
0
    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("", "")
Пример #5
0
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)
Пример #6
0
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)
Пример #7
0
 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
Пример #8
0
 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