Esempio n. 1
0
def test_get_or_post():
    uri = u'https://localhost:8092/authorization'
    method = 'GET'
    values = {'acr_values': u'PASSWORD',
              'state': 'urn:uuid:92d81fb3-72e8-4e6c-9173-c360b782148a',
              'redirect_uri': 'https://localhost:8666/919D3F697FDAAF138124B83E09ECB0B7',
              'response_type': 'code', 'client_id': u'ok8tx7ulVlNV',
              'scope': 'openid profile email address phone'}
    request = AuthorizationRequest(**values)

    path, body, ret_kwargs = util.get_or_post(uri, method, request)

    assert url_compare(path,
                       u"https://localhost:8092/authorization?acr_values=PASSWORD&state=urn%3Auuid%3A92d81fb3-72e8-4e6c-9173-c360b782148a&redirect_uri=https%3A%2F%2Flocalhost%3A8666%2F919D3F697FDAAF138124B83E09ECB0B7&response_type=code&client_id=ok8tx7ulVlNV&scope=openid+profile+email+address+phone")
    assert not body
    assert not ret_kwargs

    method = 'POST'
    uri = u'https://localhost:8092/token'
    values = {
        'redirect_uri': 'https://localhost:8666/919D3F697FDAAF138124B83E09ECB0B7',
        'code': 'Je1iKfPN1vCiN7L43GiXAuAWGAnm0mzA7QIjl/YLBBZDB9wefNExQlLDUIIDM2rT2t+gwuoRoapEXJyY2wrvg9cWTW2vxsZU+SuWzZlMDXc=',
        'grant_type': 'authorization_code'}
    request = AccessTokenRequest(**values)
    kwargs = {'scope': '',
              'state': 'urn:uuid:92d81fb3-72e8-4e6c-9173-c360b782148a',
              'authn_method': 'client_secret_basic', 'key': [],
              'headers': {
                  'Authorization': 'Basic b2s4dHg3dWxWbE5WOjdlNzUyZDU1MTc0NzA0NzQzYjZiZWJkYjU4ZjU5YWU3MmFlMGM5NDM4YTY1ZmU0N2IxMDA3OTM1'}
              }

    path, body, ret_kwargs = util.get_or_post(uri, method, request, **kwargs)

    assert path == u'https://localhost:8092/token'
    assert url_compare("http://test/#{}".format(body),
                       'http://test/#code=Je1iKfPN1vCiN7L43GiXAuAWGAnm0mzA7QIjl%2FYLBBZDB9wefNExQlLDUIIDM2rT2t%2BgwuoRoapEXJyY2wrvg9cWTW2vxsZU%2BSuWzZlMDXc%3D&grant_type=authorization_code&redirect_uri=https%3A%2F%2Flocalhost%3A8666%2F919D3F697FDAAF138124B83E09ECB0B7')
    assert ret_kwargs == {'scope': '',
                          'state': 'urn:uuid:92d81fb3-72e8-4e6c-9173-c360b782148a',
                          'authn_method': 'client_secret_basic', 'key': [],
                          'headers': {
                              'Content-type': 'application/x-www-form-urlencoded',
                              'Authorization': 'Basic b2s4dHg3dWxWbE5WOjdlNzUyZDU1MTc0NzA0NzQzYjZiZWJkYjU4ZjU5YWU3MmFlMGM5NDM4YTY1ZmU0N2IxMDA3OTM1'}}

    method = 'UNSUPORTED'
    with pytest.raises(UnSupported):
        util.get_or_post(uri, method, request, **kwargs)
Esempio n. 2
0
 def test_request_info_simple_get(self):
     uri, body, h_args, cis = self.client.request_info(AuthorizationRequest,
                                                       method="GET")
     assert url_compare(
         uri, '{}?redirect_uri={}&response_type=code&client_id=1'.format(
             self.authorization_endpoint, quote(self.redirect_uri,
                                                safe="")))
     assert body is None
     assert h_args == {}
Esempio n. 3
0
 def test_request_info_simple_get(self):
     uri, body, h_args, cis = self.client.request_info(AuthorizationRequest,
                                                       method="GET")
     assert url_compare(uri,
                        '{}?redirect_uri={}&response_type=code&client_id=1'.format(
                            self.authorization_endpoint,
                            quote(self.redirect_uri, safe="")))
     assert body is None
     assert h_args == {}
Esempio n. 4
0
    def test_request_info_with_req_and_extra_args(self):
        uri, body, h_args, cis = self.client.request_info(
            AuthorizationRequest, method="GET", request_args={"state": "init"}, extra_args={"rock": "little"}
        )

        expected = "{}?state=init&redirect_uri={}&response_type=code&client_id=1&rock=little"
        assert url_compare(uri, expected.format(self.authorization_endpoint, quote(self.redirect_uri, safe="")))
        assert body is None
        assert h_args == {}
        assert isinstance(cis, AuthorizationRequest)
Esempio n. 5
0
    def test_request_info_simple_get_with_extra_args(self):
        uri, body, h_args, cis = self.client.request_info(
            AuthorizationRequest, method="GET", extra_args={"rock": "little"})

        assert url_compare(uri,
                           '{}?redirect_uri={}&response_type=code&client_id=1&rock=little'.format(
                               self.authorization_endpoint,
                               quote(self.redirect_uri, safe="")))
        assert body is None
        assert h_args == {}
        assert isinstance(cis, AuthorizationRequest)
Esempio n. 6
0
    def test_request_info_simple_get_with_extra_args(self):
        uri, body, h_args, cis = self.client.request_info(
            AuthorizationRequest, method="GET", extra_args={"rock": "little"})

        assert url_compare(
            uri,
            '{}?redirect_uri={}&response_type=code&client_id=1&rock=little'.
            format(self.authorization_endpoint,
                   quote(self.redirect_uri, safe="")))
        assert body is None
        assert h_args == {}
        assert isinstance(cis, AuthorizationRequest)
Esempio n. 7
0
    def test_begin(self):
        sid, loc = self.consumer.begin("http://localhost:8087",
                                       "http://localhost:8088/authorization")

        # state is dynamic
        params = {"scope": "openid",
                  "state": sid,
                  "redirect_uri": "http://localhost:8087/authz",
                  "response_type": "code",
                  "client_id": "number5"}

        url = "http://localhost:8088/authorization?{}".format(urlencode(params))
        assert url_compare(loc, url)
    def test_begin(self):
        sid, loc = self.consumer.begin("http://localhost:8087",
                                       "http://localhost:8088/authorization")

        # state is dynamic
        params = {"scope": "openid",
                  "state": sid,
                  "redirect_uri": "http://localhost:8087/authz",
                  "response_type": "code",
                  "client_id": "number5"}

        url = "http://localhost:8088/authorization?{}".format(urlencode(params))
        assert url_compare(loc, url)
Esempio n. 9
0
    def test_request_info_simple_get_with_req_args(self):
        uri, body, h_args, cis = self.client.request_info(
            AuthorizationRequest, method="GET", request_args={"state": "init"}
        )

        assert url_compare(
            uri,
            "{}?state=init&redirect_uri={}&response_type=code&client_id=1".format(
                self.authorization_endpoint, quote(self.redirect_uri, safe="")
            ),
        )
        assert body is None
        assert h_args == {}
        assert isinstance(cis, AuthorizationRequest)
Esempio n. 10
0
    def test_request_info_with_req_and_extra_args(self):
        uri, body, h_args, cis = self.client.request_info(
            AuthorizationRequest,
            method="GET",
            request_args={"state": "init"},
            extra_args={"rock": "little"})

        expected = '{}?state=init&redirect_uri={}&response_type=code&client_id=1&rock=little'
        assert url_compare(
            uri,
            expected.format(self.authorization_endpoint,
                            quote(self.redirect_uri, safe="")))
        assert body is None
        assert h_args == {}
        assert isinstance(cis, AuthorizationRequest)
Esempio n. 11
0
    def test_client_get_access_token_request(self):
        self.consumer.client_secret = "secret0"
        _state = "state"
        self.consumer.redirect_uris = ["https://www.example.com/oic/cb"]

        resp1 = AuthorizationResponse(code="auth_grant", state=_state)
        self.consumer.parse_response(AuthorizationResponse,
                                     resp1.to_urlencoded(),
                                     "urlencoded")
        resp2 = AccessTokenResponse(access_token="token1",
                                    token_type="Bearer", expires_in=0,
                                    state=_state)
        self.consumer.parse_response(AccessTokenResponse, resp2.to_urlencoded(),
                                     "urlencoded")

        url, body, http_args = self.consumer.get_access_token_request(_state)
        assert url_compare(url, "http://localhost:8088/token")
        expected_params = 'redirect_uri=https%3A%2F%2Fwww.example.com%2Foic%2Fcb&client_id=number5&state=state&code=auth_grant&grant_type=authorization_code&client_secret=secret0'

        assert query_string_compare(body, expected_params)
        assert http_args == {'headers': {
            'Content-Type': 'application/x-www-form-urlencoded'}}
Esempio n. 12
0
    def test_client_get_access_token_request(self):
        self.consumer.client_secret = "secret0"
        _state = "state"
        self.consumer.redirect_uris = ["https://www.example.com/oic/cb"]

        resp1 = AuthorizationResponse(code="auth_grant", state=_state)
        self.consumer.parse_response(AuthorizationResponse,
                                     resp1.to_urlencoded(),
                                     "urlencoded")
        resp2 = AccessTokenResponse(access_token="token1",
                                    token_type="Bearer", expires_in=0,
                                    state=_state)
        self.consumer.parse_response(AccessTokenResponse, resp2.to_urlencoded(),
                                     "urlencoded")

        url, body, http_args = self.consumer.get_access_token_request(_state)
        assert url_compare(url, "http://localhost:8088/token")
        expected_params = "code=auth_grant&client_secret=secret0&" \
                          "grant_type=authorization_code&client_id=number5&" \
                          "redirect_uri=https%3A%2F%2Fwww.example.com%2Foic%2Fcb"

        assert query_string_compare(body, expected_params)
        assert http_args == {'headers': {
            'Content-Type': 'application/x-www-form-urlencoded'}}
Esempio n. 13
0
def test_url_compare():
    # reorder query params is still the same url
    assert url_compare("http://example.com?baz=xyz&foo=bar",
                       "http://example.com?foo=bar&baz=xyz")
Esempio n. 14
0
 def test_request(self):
     req = DummyMessage(req_str="Fair",
                        req_str_list=["game"]).request("http://example.com")
     assert url_compare(req,
                        "http://example.com?req_str=Fair&req_str_list=game")
 def test_request(self):
     req = DummyMessage(req_str="Fair",
                        req_str_list=["game"]).request("http://example.com")
     assert url_compare(req,
                        "http://example.com?req_str=Fair&req_str_list=game")
Esempio n. 16
0
def test_url_compare():
    # reorder query params is still the same url
    assert url_compare("http://example.com?baz=xyz&foo=bar",
                       "http://example.com?foo=bar&baz=xyz")
Esempio n. 17
0
def test_get_or_post():
    uri = u'https://localhost:8092/authorization'
    method = 'GET'
    values = {
        'acr_values': u'PASSWORD',
        'state': 'urn:uuid:92d81fb3-72e8-4e6c-9173-c360b782148a',
        'redirect_uri':
        'https://localhost:8666/919D3F697FDAAF138124B83E09ECB0B7',
        'response_type': 'code',
        'client_id': u'ok8tx7ulVlNV',
        'scope': 'openid profile email address phone'
    }
    request = AuthorizationRequest(**values)

    path, body, ret_kwargs = util.get_or_post(uri, method, request)

    assert url_compare(
        path,
        u"https://localhost:8092/authorization?acr_values=PASSWORD&state=urn%3Auuid%3A92d81fb3-72e8-4e6c-9173-c360b782148a&redirect_uri=https%3A%2F%2Flocalhost%3A8666%2F919D3F697FDAAF138124B83E09ECB0B7&response_type=code&client_id=ok8tx7ulVlNV&scope=openid+profile+email+address+phone"
    )
    assert not body
    assert not ret_kwargs

    method = 'POST'
    uri = u'https://localhost:8092/token'
    values = {
        'redirect_uri':
        'https://localhost:8666/919D3F697FDAAF138124B83E09ECB0B7',
        'code':
        'Je1iKfPN1vCiN7L43GiXAuAWGAnm0mzA7QIjl/YLBBZDB9wefNExQlLDUIIDM2rT2t+gwuoRoapEXJyY2wrvg9cWTW2vxsZU+SuWzZlMDXc=',
        'grant_type': 'authorization_code'
    }
    request = AccessTokenRequest(**values)
    kwargs = {
        'scope': '',
        'state': 'urn:uuid:92d81fb3-72e8-4e6c-9173-c360b782148a',
        'authn_method': 'client_secret_basic',
        'key': [],
        'headers': {
            'Authorization':
            'Basic b2s4dHg3dWxWbE5WOjdlNzUyZDU1MTc0NzA0NzQzYjZiZWJkYjU4ZjU5YWU3MmFlMGM5NDM4YTY1ZmU0N2IxMDA3OTM1'
        }
    }

    path, body, ret_kwargs = util.get_or_post(uri, method, request, **kwargs)

    assert path == u'https://localhost:8092/token'
    assert url_compare(
        "http://test/#{}".format(body),
        'http://test/#code=Je1iKfPN1vCiN7L43GiXAuAWGAnm0mzA7QIjl%2FYLBBZDB9wefNExQlLDUIIDM2rT2t%2BgwuoRoapEXJyY2wrvg9cWTW2vxsZU%2BSuWzZlMDXc%3D&grant_type=authorization_code&redirect_uri=https%3A%2F%2Flocalhost%3A8666%2F919D3F697FDAAF138124B83E09ECB0B7'
    )
    assert ret_kwargs == {
        'scope': '',
        'state': 'urn:uuid:92d81fb3-72e8-4e6c-9173-c360b782148a',
        'authn_method': 'client_secret_basic',
        'key': [],
        'headers': {
            'Content-Type':
            'application/x-www-form-urlencoded',
            'Authorization':
            'Basic b2s4dHg3dWxWbE5WOjdlNzUyZDU1MTc0NzA0NzQzYjZiZWJkYjU4ZjU5YWU3MmFlMGM5NDM4YTY1ZmU0N2IxMDA3OTM1'
        }
    }

    method = 'UNSUPORTED'
    with pytest.raises(UnSupported):
        util.get_or_post(uri, method, request, **kwargs)