Beispiel #1
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)
Beispiel #2
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)
Beispiel #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,
                                 algorithms=["HS256"])
     self.assertTrue(isinstance(actual_payload.pop("exp"), int))
     self.assertDictEqual(expected_payload, actual_payload)
Beispiel #4
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)
Beispiel #5
0
 def test_token_for_anonymous_user(self):
     user = AnonymousUser()
     JWTView.get_token(user, self.portal)
Beispiel #6
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)
Beispiel #7
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)
Beispiel #8
0
 def test_token_for_user_without_access(self):
     JWTView.get_token(self.user, self.portal)
Beispiel #9
0
 def test_token_for_anonymous_user(self):
     user = AnonymousUser()
     JWTView.get_token(user, self.portal)
Beispiel #10
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)
Beispiel #11
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"])
Beispiel #12
0
 def test_token_for_user_without_access(self):
     JWTView.get_token(self.user, self.portal)