Beispiel #1
0
    def test_create_success_lenient_verification(self):
        """
            Test creating a token with strict verification disabled.

            Expected Result: A token is created successfully. The create token can be decoded.
        """

        EasyJWT.strict_verification = False

        easyjwt = EasyJWT(self.key)
        easyjwt.expiration_date = self.expiration_date
        easyjwt.issuer = self.issuer
        easyjwt.JWT_ID = self.JWT_ID
        easyjwt.not_before_date = self.not_before_date
        easyjwt.subject = self.subject

        token = easyjwt.create()
        self.assertIsNotNone(token)

        self.assertIsNotNone(easyjwt.issued_at_date)

        claim_set = decode(token,
                           self.key,
                           algorithms=easyjwt._get_decode_algorithms())
        self.assertIsNotNone(claim_set)
Beispiel #2
0
    def test_create_success_without_issued_at_date(self):
        """
             Test creating a token without specifying an issued-at date.

             Expected Result: A token is created. The created token can be decoded.
        """

        easyjwt = EasyJWT(self.key)
        easyjwt.expiration_date = self.expiration_date
        easyjwt.issuer = self.issuer
        easyjwt.JWT_ID = self.JWT_ID
        easyjwt.not_before_date = self.not_before_date
        easyjwt.subject = self.subject

        token = easyjwt.create()
        self.assertIsNotNone(token)

        self.assertIsNotNone(easyjwt.issued_at_date)

        claim_set = decode(token,
                           self.key,
                           algorithms=easyjwt._get_decode_algorithms())
        self.assertIsNotNone(claim_set)
Beispiel #3
0
    def test_get_decode_algorithms(self):
        """
            Test getting the algorithms for decoding a token.

            Expected Result: A set of all previous encoding algorithms and the current one is returned.
        """

        # Temporarily save the current class variables to restore them later. Otherwise, changes could influence other
        # parts of the tests.
        current_alg_temp = EasyJWT.algorithm
        previous_algs_temp = EasyJWT.previous_algorithms

        # Set some test algorithms.
        EasyJWT.algorithm = Algorithm.HS256
        EasyJWT.previous_algorithms = [Algorithm.HS384, Algorithm.HS512]

        algorithms = [
            Algorithm.HS384.value, Algorithm.HS512.value, Algorithm.HS256.value
        ]
        self.assertListEqual(algorithms, EasyJWT._get_decode_algorithms())

        # Restore the class variables.
        EasyJWT.algorithm = current_alg_temp
        EasyJWT.previous_algorithms = previous_algs_temp