# 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,
)


@modify_settings(MIDDLEWARE={
    'prepend': 'atlassian_jwt_auth.frameworks.django.asap_middleware',
})
class TestAsapMiddleware(DjangoAsapMixin, RS256KeyTestMixin, SimpleTestCase):

    def check_response(self,
                       view_name,
                       response_content='',
                       status_code=200,
                       issuer='client-app',
                       audience='server-app',
                       key_id='client-app/key01',
                       subject=None,
                       private_key=None,
                       token=None,
                       authorization=None,
                       retriever_key=None):
        if authorization is None:
            if token is None:
                if private_key is None:
                    private_key = self._private_key_pem
                token = create_token(issuer=issuer, audience=audience,
                                     key_id=key_id, private_key=private_key,
                                     subject=subject)
            authorization = b'Bearer ' + token

        test_settings = self.test_settings.copy()
        if retriever_key is not None:

# 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,
)



@modify_settings(MIDDLEWARE={
    'prepend': 'atlassian_jwt_auth.frameworks.django.asap_middleware',
})
class TestAsapMiddleware(DjangoAsapMixin, RS256KeyTestMixin, SimpleTestCase):

    def check_response(self,
                       view_name,
                       response_content='',
                       status_code=200,
                       issuer='client-app',
                       audience='server-app',
                       key_id='client-app/key01',
                       subject=None,
                       private_key=None,
                       token=None,
                       authorization=None,
                       retriever_key=None):
        if authorization is None:
            if token is None:
                if private_key is None:
                    private_key = self._private_key_pem
                token = create_token(issuer=issuer, audience=audience,
                                     key_id=key_id, private_key=private_key,
                                     subject=subject)
            authorization = b'Bearer ' + token

        test_settings = self.test_settings.copy()
        if retriever_key is not None:

            retriever = get_static_retriever_class({