def test_do_user_info_request(self): resp = AuthorizationResponse(code="code", state="state") grant = Grant(10) # expired grant grant.add_code(resp) resp2 = AccessTokenResponse( refresh_token="refresh_with_me", access_token="access", token_type="Bearer" ) token = Token(resp2) grant.tokens.append(token) self.client.grant["state0"] = grant with responses.RequestsMock() as rsps: rsps.add( responses.POST, "https://example.com/userinfo", content_type="application/json", json={ "name": "Melody Gardot", "email": "*****@*****.**", "verified": False, "nickname": "Melody", "sub": "some sub", }, ) resp3 = self.client.do_user_info_request(state="state0") assert isinstance(resp3, OpenIDSchema) assert _eq(resp3.keys(), ["name", "email", "verified", "nickname", "sub"]) assert resp3["name"] == "Melody Gardot"
def test_get_access_token_request(): resp = AuthorizationResponse(code="code", state="state") grant = Grant(1) grant.add_code(resp) client = Client() client.grant["openid"] = grant time.sleep(2) raises(GrantExpired, 'client.construct_AccessTokenRequest(state="openid")')
def test_client_get_grant(): cli = Client() resp = AuthorizationResponse(code="code", state="state") grant = Grant() grant.add_code(resp) cli.grant["state"] = grant gr1 = cli.grant_from_state("state") assert gr1.code == "code"
def test_do_user_info_request(self): resp = AuthorizationResponse(code="code", state="state") grant = Grant(10) # expired grant grant.add_code(resp) resp = AccessTokenResponse(refresh_token="refresh_with_me", access_token="access") token = Token(resp) grant.tokens.append(token) self.client.grant["state0"] = grant resp = self.client.do_user_info_request(state="state0") assert isinstance(resp, OpenIDSchema) assert _eq(resp.keys(), ['name', 'email', 'verified', 'nickname', 'sub']) assert resp["name"] == "Melody Gardot"
def test_do_user_info_request(self): resp = AuthorizationResponse(code="code", state="state") grant = Grant(10) # expired grant grant.add_code(resp) resp2 = AccessTokenResponse( refresh_token="refresh_with_me", access_token="access", token_type="Bearer" ) token = Token(resp2) grant.tokens.append(token) self.client.grant["state0"] = grant resp3 = self.client.do_user_info_request(state="state0") assert isinstance(resp3, OpenIDSchema) assert _eq(resp3.keys(), ["name", "email", "verified", "nickname", "sub"]) assert resp3["name"] == "Melody Gardot"
def test_do_user_info_request_http_errors(self): resp = AuthorizationResponse(code="code", state="state") grant = Grant(10) # expired grant grant.add_code(resp) resp2 = AccessTokenResponse( refresh_token="refresh_with_me", access_token="access", token_type="Bearer" ) token = Token(resp2) grant.tokens.append(token) self.client.grant["state0"] = grant with responses.RequestsMock() as rsps: rsps.add( responses.POST, "https://example.com/userinfo", status=405, headers={"Allow": "GET"}, ) with pytest.raises(CommunicationError) as excp: self.client.do_user_info_request(state="state0") assert excp.value.args[0] == "Server responded with HTTP Error Code 405" assert excp.value.args[1] == ["GET"]