def authorization_callback(request): data = json.loads(_decoded(request.body)) headers = {'Content-Type': 'application/json'} body = { 'redirect': 'https://relier/page?code=qed&state={}'.format(data["state"]) } return (200, headers, json.dumps(body))
def test_posts_code_to_server(self): body = json.loads(_decoded(self.response.request.body)) expected = { "client_secret": "cake", "code": "1234", "client_id": "abc" } self.assertEqual(body, expected)
def test_authorize_code_with_default_arguments(self): assertion = "A_FAKE_ASSERTION" code = self.client.authorize_code(assertion) self.assertEquals(code, "qed") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEquals(req_body, { "assertion": assertion, "client_id": self.client.client_id, "state": "x", })
def test_authorize_code_with_explicit_client_id(self): assertion = "A_FAKE_ASSERTION" code = self.client.authorize_code(assertion, client_id="cba") self.assertEquals(code, "qed") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEquals(req_body, { "assertion": assertion, "client_id": "cba", "state": "x", })
def test_authorize_token_with_explicit_client_id(self): assertion = "A_FAKE_ASSERTION" token = self.client.authorize_token(assertion, client_id="cba") self.assertEquals(token, "izatoken") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEquals(req_body, { "assertion": assertion, "client_id": "cba", "state": "x", "response_type": "token", })
def test_authorize_code_with_default_arguments(self): assertion = "A_FAKE_ASSERTION" code = self.client.authorize_code(assertion) self.assertEquals(code, "qed") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEquals( req_body, { "assertion": assertion, "client_id": self.client.client_id, "state": "x", })
def test_authorize_code_with_explicit_scope(self): assertion = "A_FAKE_ASSERTION" code = self.client.authorize_code(assertion, scope="profile:email") self.assertEquals(code, "qed") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEquals(req_body, { "assertion": assertion, "client_id": self.client.client_id, "state": "x", "scope": "profile:email", })
def test_authorize_token_with_default_arguments(self): assertion = "A_FAKE_ASSERTION" token = self.client.authorize_token(assertion) self.assertEqual(token, "izatoken") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEqual( req_body, { "assertion": assertion, "client_id": self.client.client_id, "state": AnyStringValue(), "response_type": "token", })
def test_authorize_code_with_explicit_scope(self): assertion = "A_FAKE_ASSERTION" code = self.client.authorize_code(assertion, scope="profile:email") self.assertEquals(code, "qed") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEquals( req_body, { "assertion": assertion, "client_id": self.client.client_id, "state": "x", "scope": "profile:email", })
def test_authorize_token_with_explicit_client_id(self): assertion = "A_FAKE_ASSERTION" token = self.client.authorize_token(assertion, client_id="cba") self.assertEquals(token, "izatoken") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEquals( req_body, { "assertion": assertion, "client_id": "cba", "state": "x", "response_type": "token", })
def test_authorize_code_with_session_object(self): session = mock.Mock() session.get_identity_assertion.return_value = "IDENTITY" code = self.client.authorize_code(session) session.get_identity_assertion.assert_called_once_with( audience=TEST_SERVER_URL, service=self.client.client_id) self.assertEquals(code, "qed") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEquals( req_body, { "assertion": "IDENTITY", "client_id": self.client.client_id, "state": "x", })
def test_authorize_code_with_session_object(self): session = mock.Mock() session.get_identity_assertion.return_value = "IDENTITY" code = self.client.authorize_code(session) session.get_identity_assertion.assert_called_once_with( audience=TEST_SERVER_URL, service=self.client.client_id ) self.assertEquals(code, "qed") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEquals(req_body, { "assertion": "IDENTITY", "client_id": self.client.client_id, "state": "x", })
def test_authorize_token_with_session_object(self): session = mock.Mock() session.get_identity_assertion.return_value = "IDENTITY" token = self.client.authorize_token(session) session.get_identity_assertion.assert_called_once_with( audience=TEST_SERVER_URL, service=self.client.client_id) self.assertEqual(token, "izatoken") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEqual( req_body, { "assertion": "IDENTITY", "client_id": self.client.client_id, "state": AnyStringValue(), "response_type": "token", })
def test_authorize_code_with_pkce_challenge(self): assertion = "A_FAKE_ASSERTION" challenge, verifier = self.client.generate_pkce_challenge() self.assertEqual(sorted(challenge), ["code_challenge", "code_challenge_method"]) self.assertEqual(sorted(verifier), ["code_verifier"]) code = self.client.authorize_code(assertion, **challenge) self.assertEquals(code, "qed") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEquals( req_body, { "assertion": assertion, "client_id": self.client.client_id, "state": "x", "code_challenge": challenge["code_challenge"], "code_challenge_method": challenge["code_challenge_method"], })
def test_authorize_code_with_pkce_challenge(self): assertion = "A_FAKE_ASSERTION" challenge, verifier = self.client.generate_pkce_challenge() self.assertEqual(sorted(challenge), ["code_challenge", "code_challenge_method"]) self.assertEqual(sorted(verifier), ["code_verifier"]) code = self.client.authorize_code(assertion, **challenge) self.assertEquals(code, "qed") req_body = json.loads(_decoded(responses.calls[0].request.body)) self.assertEquals(req_body, { "assertion": assertion, "client_id": self.client.client_id, "state": "x", "code_challenge": challenge["code_challenge"], "code_challenge_method": challenge["code_challenge_method"], })
def test_posts_token_to_server(self): body = json.loads(_decoded(self.response.request.body)) expected = { "token": "abc", } self.assertEqual(body, expected)
def _get_request_body(self): return json.loads(_decoded(responses.calls[0].request.body))