test_native_spa_pkce_auth0.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import os
  2. import unittest
  3. from . import base
  4. class TestNativeAuth0Test(base.Sample, base.Browser, unittest.TestCase):
  5. def setUp(self):
  6. super().setUp()
  7. self.client_id = os.environ.get("AUTH0_PKCE_CLIENT_ID")
  8. self.idp_domain = os.environ.get("AUTH0_DOMAIN")
  9. if not self.client_id or not self.idp_domain:
  10. self.skipTest("native auth0 is not configured properly")
  11. def test_login(self):
  12. # redirect_uri is http://
  13. os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = "1"
  14. self.run_sample(
  15. "native_spa_pkce_auth0.py", {
  16. "OAUTH_CLIENT_ID": self.client_id,
  17. "OAUTH_IDP_DOMAIN": self.idp_domain,
  18. }
  19. )
  20. authorize_url = self.wait_for_pattern("https://")
  21. redirect_uri = self.authorize_auth0(authorize_url, "http://")
  22. self.write(redirect_uri)
  23. last_line = self.wait_for_end()
  24. import ast
  25. response = ast.literal_eval(last_line)
  26. self.assertIn("access_token", response)
  27. self.assertIn("id_token", response)
  28. self.assertIn("scope", response)
  29. self.assertIn("openid", response["scope"])
  30. self.assertIn("expires_in", response)
  31. self.assertIn("expires_at", response)
  32. self.assertIn("token_type", response)
  33. self.assertEqual("Bearer", response["token_type"])