# 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/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)
# 
# class RS256KeyTestMixin(object):
# 
#     """ Private rs256 test mixin. """
# 
#     @property
#     def algorithm(self):
#         return 'RS256'
# 
#     def get_new_private_key_in_pem_format(self):
#         return get_new_rsa_private_key_in_pem_format()


import os
import django
from django.test.testcases import SimpleTestCase
from django.test.utils import override_settings, modify_settings
    from django.urls import reverse
    from django.core.urlresolvers import reverse
from atlassian_jwt_auth.contrib.tests.utils import (
    get_static_retriever_class,
)
from atlassian_jwt_auth.tests import utils
from atlassian_jwt_auth.tests.utils import (
    create_token,
    RS256KeyTestMixin,
)

        test_settings = self.test_settings.copy()
        if retriever_key is not None:
            retriever = get_static_retriever_class({
                retriever_key: self._public_key_pem
            })
            test_settings['ASAP_KEY_RETRIEVER_CLASS'] = retriever

        with override_settings(**test_settings):
            response = self.client.get(reverse(view_name),
                                       HTTP_AUTHORIZATION=authorization)

        self.assertContains(response, response_content,
                            status_code=status_code)

    def test_request_with_valid_token_is_allowed(self):
        self.check_response('needed', 'one', 200)

    def test_request_with_duplicate_jti_is_rejected_as_per_setting(self):
        self.test_settings['ASAP_CHECK_JTI_UNIQUENESS'] = True
        token = create_token(
            issuer='client-app', audience='server-app',
            key_id='client-app/key01', private_key=self._private_key_pem
        )
        str_auth = 'Bearer ' + token.decode(encoding='iso-8859-1')
        self.check_response('needed', 'one', 200, authorization=str_auth)
        self.check_response('needed', 'duplicate jti', 401,
                            authorization=str_auth)

    def _assert_request_with_duplicate_jti_is_accepted(self):

# 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/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)
# 
# class RS256KeyTestMixin(object):
# 
#     """ Private rs256 test mixin. """
# 
#     @property
#     def algorithm(self):
#         return 'RS256'
# 
#     def get_new_private_key_in_pem_format(self):
#         return get_new_rsa_private_key_in_pem_format()


# Path: atlassian_jwt_auth/frameworks/django/tests/test_django.py
import os
import django
from django.test.testcases import SimpleTestCase
from django.test.utils import override_settings, modify_settings
    from django.urls import reverse
    from django.core.urlresolvers import reverse
from atlassian_jwt_auth.contrib.tests.utils import (
    get_static_retriever_class,
)
from atlassian_jwt_auth.tests import utils
from atlassian_jwt_auth.tests.utils import (
    create_token,
    RS256KeyTestMixin,
)


        test_settings = self.test_settings.copy()
        if retriever_key is not None:
            retriever = get_static_retriever_class({
                retriever_key: self._public_key_pem
            })
            test_settings['ASAP_KEY_RETRIEVER_CLASS'] = retriever

        with override_settings(**test_settings):
            response = self.client.get(reverse(view_name),
                                       HTTP_AUTHORIZATION=authorization)

        self.assertContains(response, response_content,
                            status_code=status_code)

    def test_request_with_valid_token_is_allowed(self):
        self.check_response('needed', 'one', 200)

    def test_request_with_duplicate_jti_is_rejected_as_per_setting(self):
        self.test_settings['ASAP_CHECK_JTI_UNIQUENESS'] = True
        token = create_token(
            issuer='client-app', audience='server-app',
            key_id='client-app/key01', private_key=self._private_key_pem
        )
        str_auth = 'Bearer ' + token.decode(encoding='iso-8859-1')
        self.check_response('needed', 'one', 200, authorization=str_auth)
        self.check_response('needed', 'duplicate jti', 401,
                            authorization=str_auth)

    def _assert_request_with_duplicate_jti_is_accepted(self):

        token = create_token(