Esempio n. 1
0
 def test_get_request_with_redirect_response(self):
     next_ = fake.url()
     request = self.factory.get(reverse("lizard_auth_server.jwt"), {"portal": self.portal.sso_key, "next": next_})
     self.user.user_profile.portals.add(self.portal)
     request.user = self.user
     response = JWTView.as_view()(request)
     expected_status_code = 302
     actual_status_code = response.status_code
     self.assertEqual(expected_status_code, actual_status_code)
     self.assertTrue(JWTView.is_url(response.url))
     self.assertTrue(response.url.startswith(next_))
     self.assertTrue("access_token=" in response.url)
Esempio n. 2
0
 def test_get_request_without_portal_access(self):
     request = self.factory.get(reverse("lizard_auth_server.jwt"), {"portal": self.portal.sso_key})
     request.user = self.user
     response = JWTView.as_view()(request)
     expected_status_code = 400
     actual_status_code = response.status_code
     self.assertEqual(expected_status_code, actual_status_code)
Esempio n. 3
0
 def test_token_with_default_exp(self):
     self.user.user_profile.portals.add(self.portal)
     token = JWTView.get_token(self.user, self.portal)
     expected_payload = {'username': self.user.username}
     actual_payload = jwt.decode(token, self.portal.sso_secret)
     self.assertTrue(isinstance(actual_payload.pop('exp'), int))
     self.assertDictEqual(expected_payload, actual_payload)
Esempio n. 4
0
 def test_get_request_without_portal_parameters(self):
     request = self.factory.get(reverse("lizard_auth_server.jwt"), )
     self.user.user_profile.portals.add(self.portal)
     request.user = self.user
     response = JWTView.as_view()(request)
     expected_status_code = 400
     actual_status_code = response.status_code
     self.assertEqual(expected_status_code, actual_status_code)
Esempio n. 5
0
 def test_get_request_without_portal_parameters(self):
     request = self.factory.get(reverse("lizard_auth_server.jwt"))
     self.user.user_profile.portals.add(self.portal)
     request.user = self.user
     response = JWTView.as_view()(request)
     expected_status_code = 400
     actual_status_code = response.status_code
     self.assertEqual(expected_status_code, actual_status_code)
Esempio n. 6
0
 def test_get_request_with_invalid_portal_parameter(self):
     random_sso_key = GenKey("Portal", "sso_key")
     request = self.factory.get(reverse("lizard_auth_server.jwt"), {"portal": random_sso_key})
     self.user.user_profile.portals.add(self.portal)
     request.user = self.user
     response = JWTView.as_view()(request)
     expected_status_code = 400
     actual_status_code = response.status_code
     self.assertEqual(expected_status_code, actual_status_code)
Esempio n. 7
0
 def test_get_request_as_anonymous_user(self):
     request = self.factory.get(reverse("lizard_auth_server.jwt"), {"portal": self.portal.sso_key})
     request.user = AnonymousUser()
     response = JWTView.as_view()(request)
     expected_status_code = 302
     actual_status_code = response.status_code
     self.assertEqual(expected_status_code, actual_status_code)
     expected_url = reverse("django.contrib.auth.views.login")
     self.assertTrue(response.url.startswith(expected_url))
Esempio n. 8
0
 def test_token_with_exp_as_datetime(self):
     epoch = datetime.utcfromtimestamp(0)
     dt = datetime.utcnow() + 2 * JWT_EXPIRATION_DELTA
     exp = int((dt - epoch).total_seconds())
     self.user.user_profile.portals.add(self.portal)
     token = JWTView.get_token(self.user, self.portal, dt)
     expected_payload = {'username': self.user.username, 'exp': exp}
     actual_payload = jwt.decode(token, self.portal.sso_secret)
     self.assertDictEqual(expected_payload, actual_payload)
Esempio n. 9
0
 def test_token_with_default_exp(self):
     self.user.user_profile.portals.add(self.portal)
     token = JWTView.get_token(self.user, self.portal)
     expected_payload = {"username": self.user.username}
     actual_payload = jwt.decode(token,
                                 self.portal.sso_secret,
                                 algorithms=["HS256"])
     self.assertTrue(isinstance(actual_payload.pop("exp"), int))
     self.assertDictEqual(expected_payload, actual_payload)
Esempio n. 10
0
 def test_get_request_with_redirect_response(self):
     next_ = fake.url()
     request = self.factory.get(
         reverse("lizard_auth_server.jwt"),
         {
             "portal": self.portal.sso_key,
             "next": next_,
         },
     )
     self.user.user_profile.portals.add(self.portal)
     request.user = self.user
     response = JWTView.as_view()(request)
     expected_status_code = 302
     actual_status_code = response.status_code
     self.assertEqual(expected_status_code, actual_status_code)
     self.assertTrue(JWTView.is_url(response.url))
     self.assertTrue(response.url.startswith(next_))
     self.assertTrue("access_token=" in response.url)
Esempio n. 11
0
 def test_get_request_with_invalid_next_parameter(self):
     request = self.factory.get(
         reverse("lizard_auth_server.jwt"), {"portal": self.portal.sso_key, "next": fake.uri_path()}
     )
     self.user.user_profile.portals.add(self.portal)
     request.user = self.user
     response = JWTView.as_view()(request)
     expected_status_code = 400
     actual_status_code = response.status_code
     self.assertEqual(expected_status_code, actual_status_code)
Esempio n. 12
0
 def test_token_with_exp_as_datetime(self):
     epoch = datetime.utcfromtimestamp(0)
     dt = datetime.utcnow() + 2 * JWT_EXPIRATION_DELTA
     exp = int((dt - epoch).total_seconds())
     self.user.user_profile.portals.add(self.portal)
     token = JWTView.get_token(self.user, self.portal, dt)
     expected_payload = {"username": self.user.username, "exp": exp}
     actual_payload = jwt.decode(token,
                                 self.portal.sso_secret,
                                 algorithms=["HS256"])
     self.assertDictEqual(expected_payload, actual_payload)
Esempio n. 13
0
 def test_get_request_without_portal_access(self):
     request = self.factory.get(
         reverse("lizard_auth_server.jwt"),
         {
             "portal": self.portal.sso_key,
         },
     )
     request.user = self.user
     response = JWTView.as_view()(request)
     expected_status_code = 400
     actual_status_code = response.status_code
     self.assertEqual(expected_status_code, actual_status_code)
Esempio n. 14
0
 def test_get_request_as_anonymous_user(self):
     request = self.factory.get(
         reverse("lizard_auth_server.jwt"),
         {
             "portal": self.portal.sso_key,
         },
     )
     request.user = AnonymousUser()
     response = JWTView.as_view()(request)
     expected_status_code = 302
     actual_status_code = response.status_code
     self.assertEqual(expected_status_code, actual_status_code)
     expected_url = reverse("login")
     self.assertTrue(response.url.startswith(expected_url))
Esempio n. 15
0
 def test_get_request_with_invalid_portal_parameter(self):
     random_sso_key = GenKey("Portal", "sso_key")
     request = self.factory.get(
         reverse("lizard_auth_server.jwt"),
         {
             "portal": random_sso_key,
         },
     )
     self.user.user_profile.portals.add(self.portal)
     request.user = self.user
     response = JWTView.as_view()(request)
     expected_status_code = 400
     actual_status_code = response.status_code
     self.assertEqual(expected_status_code, actual_status_code)
Esempio n. 16
0
 def test_get_request_with_invalid_next_parameter(self):
     request = self.factory.get(
         reverse("lizard_auth_server.jwt"),
         {
             "portal": self.portal.sso_key,
             "next": fake.uri_path(),
         },
     )
     self.user.user_profile.portals.add(self.portal)
     request.user = self.user
     response = JWTView.as_view()(request)
     expected_status_code = 400
     actual_status_code = response.status_code
     self.assertEqual(expected_status_code, actual_status_code)
Esempio n. 17
0
 def test_get_request_with_text_response(self):
     request = self.factory.get(reverse("lizard_auth_server.jwt"), {"portal": self.portal.sso_key})
     self.user.user_profile.portals.add(self.portal)
     request.user = self.user
     response = JWTView.as_view()(request)
     expected_status_code = 200
     actual_status_code = response.status_code
     self.assertEqual(expected_status_code, actual_status_code)
     expected_content_type = "text/plain"
     actual_content_type = response.get("Content-Type")
     self.assertEqual(expected_content_type, actual_content_type)
     token = response.content
     payload = jwt.decode(token, self.portal.sso_secret)
     self.assertTrue(payload["username"] == self.user.username)
     self.assertTrue("exp" in payload)
Esempio n. 18
0
 def test_get_request_with_text_response(self):
     request = self.factory.get(
         reverse('lizard_auth_server.jwt'), {
             'portal': self.portal.sso_key,
         },
     )
     self.user.user_profile.portals.add(self.portal)
     request.user = self.user
     response = JWTView.as_view()(request)
     expected_status_code = 200
     actual_status_code = response.status_code
     self.assertEqual(expected_status_code, actual_status_code)
     expected_content_type = 'text/plain'
     actual_content_type = response.get('Content-Type')
     self.assertEqual(expected_content_type, actual_content_type)
     token = response.content
     payload = jwt.decode(token, self.portal.sso_secret)
     self.assertTrue(payload['username'] == self.user.username)
     self.assertTrue('exp' in payload)
Esempio n. 19
0
 def test_get_request_with_text_response(self):
     request = self.factory.get(
         reverse("lizard_auth_server.jwt"),
         {
             "portal": self.portal.sso_key,
         },
     )
     self.user.user_profile.portals.add(self.portal)
     request.user = self.user
     response = JWTView.as_view()(request)
     expected_status_code = 200
     actual_status_code = response.status_code
     self.assertEqual(expected_status_code, actual_status_code)
     expected_content_type = "text/plain"
     actual_content_type = response.get("Content-Type")
     self.assertEqual(expected_content_type, actual_content_type)
     token = response.content
     payload = jwt.decode(token,
                          self.portal.sso_secret,
                          algorithms=["HS256"])
     self.assertTrue(payload["username"] == self.user.username)
     self.assertTrue("exp" in payload)
Esempio n. 20
0
 def test_absolute_url(self):
     self.assertTrue(JWTView.is_url(fake.url()))
Esempio n. 21
0
 def test_expired_token(self):
     self.user.user_profile.portals.add(self.portal)
     token = JWTView.get_token(self.user, self.portal, 0)
     jwt.decode(token, self.portal.sso_secret)
Esempio n. 22
0
 def test_expired_token(self):
     self.user.user_profile.portals.add(self.portal)
     token = JWTView.get_token(self.user, self.portal, 0)
     jwt.decode(token, self.portal.sso_secret, algorithms=["HS256"])
Esempio n. 23
0
 def test_valid_portal(self):
     self.assertTrue(JWTView.is_portal(self.portal.sso_key))
Esempio n. 24
0
 def test_token_for_user_without_access(self):
     JWTView.get_token(self.user, self.portal)
Esempio n. 25
0
 def test_invalid_portal(self):
     random_sso_key = GenKey("Portal", "sso_key")
     self.assertFalse(JWTView.is_portal(sso_key=random_sso_key))
Esempio n. 26
0
 def test_token_for_inactive_user(self):
     user = factories.UserF(is_active=False)
     user.user_profile.portals.add(self.portal)
     JWTView.get_token(user, self.portal)
Esempio n. 27
0
 def test_invalid_portal(self):
     random_sso_key = GenKey("Portal", "sso_key")
     self.assertFalse(JWTView.is_portal(sso_key=random_sso_key))
Esempio n. 28
0
 def test_invalid_portal(self):
     random_sso_key = GenKey('Portal', 'sso_key')
     self.assertFalse(JWTView.is_portal(sso_key=random_sso_key))
Esempio n. 29
0
 def test_token_for_anonymous_user(self):
     user = AnonymousUser()
     JWTView.get_token(user, self.portal)
Esempio n. 30
0
 def test_token_for_inactive_user(self):
     user = factories.UserF(is_active=False)
     user.user_profile.portals.add(self.portal)
     JWTView.get_token(user, self.portal)
Esempio n. 31
0
 def test_valid_portal(self):
     self.assertTrue(JWTView.is_portal(self.portal.sso_key))
Esempio n. 32
0
 def test_absolute_url(self):
     self.assertTrue(JWTView.is_url(fake.url()))
Esempio n. 33
0
 def test_token_for_anonymous_user(self):
     user = AnonymousUser()
     JWTView.get_token(user, self.portal)
Esempio n. 34
0
 def test_token_for_user_without_access(self):
     JWTView.get_token(self.user, self.portal)