Esempio n. 1
0
 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))
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 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",
     })
Esempio n. 5
0
 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",
     })
Esempio n. 6
0
 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",
     })
Esempio n. 7
0
 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",
     })
Esempio n. 8
0
 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",
         })
Esempio n. 9
0
 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",
     })
Esempio n. 10
0
 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",
         })
Esempio n. 11
0
 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",
         })
Esempio n. 12
0
 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",
         })
Esempio n. 13
0
 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",
         })
Esempio n. 14
0
 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",
     })
Esempio n. 15
0
 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",
         })
Esempio n. 16
0
 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"],
         })
Esempio n. 17
0
 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"],
     })
Esempio n. 18
0
 def test_posts_token_to_server(self):
     body = json.loads(_decoded(self.response.request.body))
     expected = {
         "token": "abc",
     }
     self.assertEqual(body, expected)
Esempio n. 19
0
 def _get_request_body(self):
     return json.loads(_decoded(responses.calls[0].request.body))
Esempio n. 20
0
 def test_posts_token_to_server(self):
     body = json.loads(_decoded(self.response.request.body))
     expected = {
         "token": "abc",
     }
     self.assertEqual(body, expected)
Esempio n. 21
0
 def _get_request_body(self):
     return json.loads(_decoded(responses.calls[0].request.body))