# Path: atlassian_jwt_auth/contrib/flask_app/decorators.py
# def requires_asap(f, issuers=None, subject_should_match_issuer=None):
#     """
#     Wrapper for Flask endpoints to make them require asap authentication to
#     access.
#     """
# 
#     return with_asap(func=f,
#                      required=True,
#                      issuers=issuers,
#                      subject_should_match_issuer=subject_should_match_issuer)
# 
# Path: atlassian_jwt_auth/contrib/tests/utils.py
# def get_static_retriever_class(keys):
# 
#     class StaticPublicKeyRetriever(object):
#         """ Retrieves a key from a static list of public keys
#         (for use in tests only) """
# 
#         def __init__(self, *args, **kwargs):
#             self.keys = keys
# 
#         def retrieve(self, key_identifier, **requests_kwargs):
#             return self.keys[key_identifier.key_id]
# 
#     return StaticPublicKeyRetriever
# 
# Path: atlassian_jwt_auth/frameworks/flask/decorators.py
# def with_asap(func=None, issuers=None, required=None,
#               subject_should_match_issuer=None):
#     """Decorator to allow endpoint-specific ASAP authentication.
# 
#     If authentication fails, a 401 or 403 response will be returned. Otherwise,
#     the decorated function will be executed.
# 
#     The ASAP claimset will be set on g.asap_claims for further
#     inspection later in the request lifecycle.
# 
#     :param list func: The view to decorate.
#     :param list issuers: A list of valid token issuers that can access this
#                          endpoint.
#     :param boolean required: Whether or not to require ASAP on this endpoint.
#     :param boolean subject_should_match_issuer: Indicate whether the subject
#                                                 must match the issuer for a
#                                                 token to be considered valid.
#     """
#     return _with_asap(
#         func, FlaskBackend(), issuers, required,
#         subject_should_match_issuer
#     )
# 
# Path: atlassian_jwt_auth/tests/utils.py
# def get_new_rsa_private_key_in_pem_format():
# def get_public_key_pem_for_private_key_pem(private_key_pem):
# def get_example_jwt_auth_signer(**kwargs):
# def create_token(issuer, audience, key_id, private_key, subject=None):
#     def get_new_private_key_in_pem_format(self):
#     def algorithm(self):
#     def get_new_private_key_in_pem_format(self):
#     def algorithm(self):
#     def get_new_private_key_in_pem_format(self):
# class BaseJWTAlgorithmTestMixin(object):
# class RS256KeyTestMixin(object):
# class ES256KeyTestMixin(object):
# 
# Path: atlassian_jwt_auth/tests/utils.py
# def create_token(issuer, audience, key_id, private_key, subject=None):
#     """" returns a token based upon the supplied parameters. """
#     signer = atlassian_jwt_auth.create_signer(
#         issuer, key_id, private_key, subject=subject)
#     return signer.generate_jwt(audience)


import unittest
from flask import Flask
from atlassian_jwt_auth.contrib.flask_app import requires_asap
from atlassian_jwt_auth.contrib.tests.utils import get_static_retriever_class
from atlassian_jwt_auth.frameworks.flask import with_asap
from atlassian_jwt_auth.tests import utils
from atlassian_jwt_auth.tests.utils import (
    create_token,
)

    def _assert_request_with_duplicate_jti_is_accepted(self):
        token = create_token(
            'client-app', 'server-app',
            'client-app/key01', self._private_key_pem
        )
        self.assertEqual(self.send_request(token).status_code, 200)
        self.assertEqual(self.send_request(token).status_code, 200)

    def test_request_with_duplicate_jti_is_accepted(self):
        self._assert_request_with_duplicate_jti_is_accepted()

    def test_request_with_duplicate_jti_is_accepted_as_per_setting(self):
        self.app.config['ASAP_CHECK_JTI_UNIQUENESS'] = False
        self._assert_request_with_duplicate_jti_is_accepted()

    def test_request_with_invalid_audience_is_rejected(self):
        token = create_token(
            'client-app', 'invalid-audience',
            'client-app/key01', self._private_key_pem
        )
        self.assertEqual(self.send_request(token).status_code, 401)

    def test_request_with_invalid_token_is_rejected(self):
        response = self.send_request(b'notavalidtoken')
        self.assertEqual(response.status_code, 401)

    def test_request_with_invalid_issuer_is_rejected(self):
        # Try with a different audience with a valid signature
        self.app.config['ASAP_KEY_RETRIEVER_CLASS'] = (

# Path: atlassian_jwt_auth/contrib/flask_app/decorators.py
# def requires_asap(f, issuers=None, subject_should_match_issuer=None):
#     """
#     Wrapper for Flask endpoints to make them require asap authentication to
#     access.
#     """
# 
#     return with_asap(func=f,
#                      required=True,
#                      issuers=issuers,
#                      subject_should_match_issuer=subject_should_match_issuer)
# 
# Path: atlassian_jwt_auth/contrib/tests/utils.py
# def get_static_retriever_class(keys):
# 
#     class StaticPublicKeyRetriever(object):
#         """ Retrieves a key from a static list of public keys
#         (for use in tests only) """
# 
#         def __init__(self, *args, **kwargs):
#             self.keys = keys
# 
#         def retrieve(self, key_identifier, **requests_kwargs):
#             return self.keys[key_identifier.key_id]
# 
#     return StaticPublicKeyRetriever
# 
# Path: atlassian_jwt_auth/frameworks/flask/decorators.py
# def with_asap(func=None, issuers=None, required=None,
#               subject_should_match_issuer=None):
#     """Decorator to allow endpoint-specific ASAP authentication.
# 
#     If authentication fails, a 401 or 403 response will be returned. Otherwise,
#     the decorated function will be executed.
# 
#     The ASAP claimset will be set on g.asap_claims for further
#     inspection later in the request lifecycle.
# 
#     :param list func: The view to decorate.
#     :param list issuers: A list of valid token issuers that can access this
#                          endpoint.
#     :param boolean required: Whether or not to require ASAP on this endpoint.
#     :param boolean subject_should_match_issuer: Indicate whether the subject
#                                                 must match the issuer for a
#                                                 token to be considered valid.
#     """
#     return _with_asap(
#         func, FlaskBackend(), issuers, required,
#         subject_should_match_issuer
#     )
# 
# Path: atlassian_jwt_auth/tests/utils.py
# def get_new_rsa_private_key_in_pem_format():
# def get_public_key_pem_for_private_key_pem(private_key_pem):
# def get_example_jwt_auth_signer(**kwargs):
# def create_token(issuer, audience, key_id, private_key, subject=None):
#     def get_new_private_key_in_pem_format(self):
#     def algorithm(self):
#     def get_new_private_key_in_pem_format(self):
#     def algorithm(self):
#     def get_new_private_key_in_pem_format(self):
# class BaseJWTAlgorithmTestMixin(object):
# class RS256KeyTestMixin(object):
# class ES256KeyTestMixin(object):
# 
# Path: atlassian_jwt_auth/tests/utils.py
# def create_token(issuer, audience, key_id, private_key, subject=None):
#     """" returns a token based upon the supplied parameters. """
#     signer = atlassian_jwt_auth.create_signer(
#         issuer, key_id, private_key, subject=subject)
#     return signer.generate_jwt(audience)


# Path: atlassian_jwt_auth/frameworks/flask/tests/test_flask.py
import unittest
from flask import Flask
from atlassian_jwt_auth.contrib.flask_app import requires_asap
from atlassian_jwt_auth.contrib.tests.utils import get_static_retriever_class
from atlassian_jwt_auth.frameworks.flask import with_asap
from atlassian_jwt_auth.tests import utils
from atlassian_jwt_auth.tests.utils import (
    create_token,
)


    def _assert_request_with_duplicate_jti_is_accepted(self):
        token = create_token(
            'client-app', 'server-app',
            'client-app/key01', self._private_key_pem
        )
        self.assertEqual(self.send_request(token).status_code, 200)
        self.assertEqual(self.send_request(token).status_code, 200)

    def test_request_with_duplicate_jti_is_accepted(self):
        self._assert_request_with_duplicate_jti_is_accepted()

    def test_request_with_duplicate_jti_is_accepted_as_per_setting(self):
        self.app.config['ASAP_CHECK_JTI_UNIQUENESS'] = False
        self._assert_request_with_duplicate_jti_is_accepted()

    def test_request_with_invalid_audience_is_rejected(self):
        token = create_token(
            'client-app', 'invalid-audience',
            'client-app/key01', self._private_key_pem
        )
        self.assertEqual(self.send_request(token).status_code, 401)

    def test_request_with_invalid_token_is_rejected(self):
        response = self.send_request(b'notavalidtoken')
        self.assertEqual(response.status_code, 401)

    def test_request_with_invalid_issuer_is_rejected(self):
        # Try with a different audience with a valid signature
        self.app.config['ASAP_KEY_RETRIEVER_CLASS'] = (

            get_static_retriever_class({