Пример #1
0
    def test_restore_claim_set_with_optional_claims(self):
        """
            Test restoring a claim set if optional claims are given.

            Expected Result: The values in the claim set are correctly mapped to their respective instance variables.
                             The date values are converted to `datetime` objects.
        """

        # Prepare a claim set. The dates must be included as a timestamp (seconds since the epoch).
        exp_timestamp = int(
            self.expiration_date.replace(tzinfo=timezone.utc).timestamp())
        iat_timestamp = int(
            self.issued_at_date.replace(tzinfo=timezone.utc).timestamp())
        nbf_timestamp = int(
            self.not_before_date.replace(tzinfo=timezone.utc).timestamp())
        claim_set = dict(
            _easyjwt_class='EasyJWT',
            aud=self.audience,
            exp=exp_timestamp,
            iat=iat_timestamp,
            iss=self.issuer,
            jti=self.JWT_ID,
            nbf=nbf_timestamp,
            sub=self.subject,
        )

        easyjwt = EasyJWT(self.key)
        easyjwt._restore_claim_set(claim_set)
        self.assertEqual(self.audience, easyjwt.audience)
        self.assertEqual(self.expiration_date, easyjwt.expiration_date)
        self.assertEqual(self.issued_at_date, easyjwt.issued_at_date)
        self.assertEqual(self.issuer, easyjwt.issuer)
        self.assertEqual(self.JWT_ID, easyjwt.JWT_ID)
        self.assertEqual(self.not_before_date, easyjwt.not_before_date)
        self.assertEqual(self.subject, easyjwt.subject)
Пример #2
0
    def test_restore_claim_set_without_optional_claims(self):
        """
            Test restoring a claim set if optional claims are not given.

            Expected Result: The values in the claim set are mapped to their respective instance variables. Optional
                             claims are empty, without causing an error.
        """

        claim_set = dict(_easyjwt_class='EasyJWT', )

        easyjwt = EasyJWT(self.key)
        easyjwt._restore_claim_set(claim_set)
        self.assertIsNone(easyjwt.audience)
        self.assertIsNone(easyjwt.expiration_date)
        self.assertIsNone(easyjwt.issued_at_date)
        self.assertIsNone(easyjwt.issuer)
        self.assertIsNone(easyjwt.JWT_ID)
        self.assertIsNone(easyjwt.not_before_date)
        self.assertIsNone(easyjwt.subject)