コード例 #1
0
ファイル: test_user.py プロジェクト: putyta/pyoidc
    def test_verify(self, srv):
        form = create_return_form_env("user", "hemligt", "query=foo")

        authn = UsernamePasswordMako(srv, "login.mako", tl, PASSWD,
                                     "authorization_endpoint")
        with LogCapture(level=logging.DEBUG) as logcap:
            response, success = authn.verify(parse_qs(form))
        assert query_string_compare(
            response.message.split("?")[1], "query=foo&upm_answer=true")

        headers = dict(response.headers)
        assert headers["Set-Cookie"].startswith('xyzxyz=')
        expected = {
            u'query': [u'query=foo'],
            u'login': ['user'],
            u'password': '******'
        }
        # We have to use eval() here to avoid intermittent
        # failures from dict ordering
        assert eval(logcap.records[0].msg[7:-1]) == expected
        expected = {
            u'query': [u'query=foo'],
            u'login': ['user'],
            u'password': '******'
        }
        assert eval(logcap.records[1].msg[5:]) == expected
        assert logcap.records[2].msg == 'Password verification succeeded.'
        expected = {u'query': [u'foo'], 'upm_answer': 'true'}
        assert eval(logcap.records[3].msg[8:]) == expected
コード例 #2
0
ファイル: test_user.py プロジェクト: putyta/pyoidc
    def test_verify_unauthorized(self, srv):
        form = create_return_form_env("user", "secret", "QUERY")

        authn = UsernamePasswordMako(srv, "login.mako", tl, PASSWD,
                                     "authorization_endpoint")
        response, state = authn.verify(parse_qs(form))
        assert isinstance(response, Unauthorized)
コード例 #3
0
ファイル: test_user.py プロジェクト: zizhang-wish/pyoidc
    def test_verify(self, srv):
        form = create_return_form_env("user", "hemligt", "query=foo")

        authn = UsernamePasswordMako(srv, "login.mako", tl, PASSWD,
                                     "authorization_endpoint")
        with LogCapture(level=logging.DEBUG) as logcap:
            response, success = authn.verify(compact(parse_qs(form)))
        assert query_string_compare(
            response.message.split("?")[1], "query=foo&upm_answer=true")

        headers = dict(response.headers)
        assert headers["Set-Cookie"].startswith("xyzxyz=")
        expected = {
            "query": "query=foo",
            "login": "******",
            "password": "******",
        }
        # We have to use eval() here to avoid intermittent
        # failures from dict ordering
        assert eval(logcap.records[0].msg[7:-1]) == expected
        expected2 = {
            "query": "query=foo",
            "login": "******",
            "password": "******",
        }
        assert eval(logcap.records[1].msg[5:]) == expected2
        assert logcap.records[2].msg == "Password verification succeeded."
        expected3 = {"query": ["foo"], "upm_answer": "true"}
        assert eval(logcap.records[3].msg[8:]) == expected3
コード例 #4
0
ファイル: test_user.py プロジェクト: Magosgruss/pyoidc
    def test_verify_unauthorized(self, srv):
        form = create_return_form_env("user", "secret", "QUERY")

        authn = UsernamePasswordMako(srv, "login.mako", tl, PASSWD,
                                     "authorization_endpoint")
        response, state = authn.verify(parse_qs(form))
        assert isinstance(response, Unauthorized)
コード例 #5
0
ファイル: test_user.py プロジェクト: putyta/pyoidc
    def test_authenticated_as(self, srv):
        form = create_return_form_env("user", "hemligt", "QUERY")

        authn = UsernamePasswordMako(srv, "login.mako", tl, PASSWD,
                                     "authorization_endpoint")
        response, success = authn.verify(parse_qs(form))

        headers = dict(response.headers)
        user, timestamp = authn.authenticated_as(headers["Set-Cookie"])
        assert user == {"uid": "user"}
コード例 #6
0
ファイル: test_user.py プロジェクト: Magosgruss/pyoidc
    def test_authenticated_as(self, srv):
        form = create_return_form_env("user", "hemligt", "QUERY")

        authn = UsernamePasswordMako(srv, "login.mako", tl, PASSWD,
                                     "authorization_endpoint")
        response, success = authn.verify(compact(parse_qs(form)))

        headers = dict(response.headers)
        user, timestamp = authn.authenticated_as(headers["Set-Cookie"])
        assert user == {"uid": "user"}
コード例 #7
0
ファイル: test_user.py プロジェクト: atidev/pyoidc
    def test_verify(self, srv):
        form = create_return_form_env("user", "hemligt", "query=foo")

        authn = UsernamePasswordMako(srv, "login.mako", tl, PASSWD,
                                     "authorization_endpoint")
        response, success = authn.verify(parse_qs(form))
        assert query_string_compare(
            response.message.split("?")[1], "query=foo&upm_answer=true")

        headers = dict(response.headers)
        assert headers["Set-Cookie"].startswith('xyzxyz=')
コード例 #8
0
ファイル: test_user.py プロジェクト: Omosofe/pyoidc
    def test_verify(self, srv):
        form = create_return_form_env("user", "hemligt", "query=foo")

        authn = UsernamePasswordMako(srv, "login.mako", tl, PASSWD,
                                     "authorization_endpoint")
        response, success = authn.verify(parse_qs(form))
        assert query_string_compare(response.message.split("?")[1],
                                    "query=foo&upm_answer=true")

        headers = dict(response.headers)
        assert headers["Set-Cookie"].startswith('xyzxyz=')
コード例 #9
0
ファイル: test_user.py プロジェクト: putyta/pyoidc
    def test_not_authenticated(self, srv):
        form = create_return_form_env("user", "hemligt", "QUERY")

        authn = UsernamePasswordMako(srv, "login.mako", tl, PASSWD,
                                     "authorization_endpoint")
        response, state = authn.verify(parse_qs(form))

        headers = dict(response.headers)
        kaka = headers["Set-Cookie"]

        kaka = kaka.replace("1", "x")
        assert authn.authenticated_as(kaka) == (None, 0)
コード例 #10
0
def test_6():
    form = create_return_form_env("user", "secret", "QUERY")
    srv = SRV()
    srv.symkey = rndstr(16)
    srv.seed = rndstr()
    srv.iv = os.urandom(16)
    srv.cookie_name = "xyzxyz"

    authn = UsernamePasswordMako(srv, "login.mako", tl, PASSWD,
                                 "authorization_endpoint")
    response = authn.verify(parse_qs(form))
    assert isinstance(response, Unauthorized)
コード例 #11
0
ファイル: test_user.py プロジェクト: Magosgruss/pyoidc
    def test_not_authenticated(self, srv):
        form = create_return_form_env("user", "hemligt", "QUERY")

        authn = UsernamePasswordMako(srv, "login.mako", tl, PASSWD,
                                     "authorization_endpoint")
        response, state = authn.verify(compact(parse_qs(form)))

        headers = dict(response.headers)
        kaka = headers["Set-Cookie"]

        kaka = kaka.replace("1", "x")
        assert authn.authenticated_as(kaka) == (None, 0)
コード例 #12
0
def test_3():
    form = create_return_form_env("user", "hemligt", "query=foo")
    srv = SRV()
    srv.symkey = rndstr(16)
    srv.seed = rndstr()
    srv.iv = os.urandom(16)
    srv.cookie_name = "xyzxyz"

    authn = UsernamePasswordMako(srv, "login.mako", tl, PASSWD,
                                 "authorization_endpoint")
    response = authn.verify(parse_qs(form))
    assert response.message == "authorization_endpoint?query=foo&upm_answer=true"
    print len(response.headers) == 2
    flag = 0
    for param, val in response.headers:
        if param == "Set-Cookie":
            assert val.startswith('xyzxyz=')
            flag = 1
    assert flag == 1
コード例 #13
0
ファイル: test_user.py プロジェクト: Magosgruss/pyoidc
    def test_verify(self, srv):
        form = create_return_form_env("user", "hemligt", "query=foo")

        authn = UsernamePasswordMako(srv, "login.mako", tl, PASSWD,
                                     "authorization_endpoint")
        with LogCapture(level=logging.DEBUG) as logcap:
            response, success = authn.verify(compact(parse_qs(form)))
        assert query_string_compare(response.message.split("?")[1],
                                    "query=foo&upm_answer=true")

        headers = dict(response.headers)
        assert headers["Set-Cookie"].startswith('xyzxyz=')
        expected = {u'query': u'query=foo', u'login': u'user',
                    u'password': '******'}
        # We have to use eval() here to avoid intermittent
        # failures from dict ordering
        assert eval(logcap.records[0].msg[7:-1]) == expected
        expected = {u'query': u'query=foo', u'login': u'user',
                    u'password': '******'}
        assert eval(logcap.records[1].msg[5:]) == expected
        assert logcap.records[2].msg == 'Password verification succeeded.'
        expected = {u'query': [u'foo'], 'upm_answer': 'true'}
        assert eval(logcap.records[3].msg[8:]) == expected
コード例 #14
0
def test_5():
    form = create_return_form_env("user", "hemligt", "QUERY")
    srv = SRV()
    srv.symkey = rndstr(16)
    srv.seed = rndstr()
    srv.iv = os.urandom(16)
    srv.cookie_name = "xyzxyz"

    authn = UsernamePasswordMako(srv, "login.mako", tl, PASSWD,
                                 "authorization_endpoint")
    response = authn.verify(parse_qs(form))

    kaka = ""
    for param, val in response.headers:
        if param == "Set-Cookie":
            kaka = val
            break

    kaka = kaka.replace("1", "x")
    try:
        _ = authn.authenticated_as(kaka)
        assert False
    except Exception:
        assert True