# 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,
)
    def test_request_decorated_issuer_is_allowed(self):
        self.check_response('restricted_issuer', 'three',
                            issuer='whitelist',
                            key_id='whitelist/key01',
                            retriever_key='whitelist/key01')

    # TODO: modify JWTAuthSigner to allow non-issuer subjects and update the
    # decorated subject test cases
    def test_request_non_decorated_subject_is_rejected(self):
        self.check_response('restricted_subject', 'Forbidden', 403,
                            issuer='whitelist',
                            key_id='whitelist/key01',
                            retriever_key='whitelist/key01')

    def test_request_using_settings_only_is_allowed(self):
        self.check_response('unneeded', 'two')

    def test_request_subject_does_not_need_to_match_issuer_from_settings(self):
        self.test_settings['ASAP_SUBJECT_SHOULD_MATCH_ISSUER'] = False
        self.check_response('needed', 'one', 200, subject='different_than_is')

    def test_request_subject_and_issue_not_matching(self):
        self.check_response(
            'needed',
            'Subject and Issuer do not match',
            401,
            subject='different_than_is',
        )



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

    def test_request_decorated_issuer_is_allowed(self):
        self.check_response('restricted_issuer', 'three',
                            issuer='whitelist',
                            key_id='whitelist/key01',
                            retriever_key='whitelist/key01')

    # TODO: modify JWTAuthSigner to allow non-issuer subjects and update the
    # decorated subject test cases
    def test_request_non_decorated_subject_is_rejected(self):
        self.check_response('restricted_subject', 'Forbidden', 403,
                            issuer='whitelist',
                            key_id='whitelist/key01',
                            retriever_key='whitelist/key01')

    def test_request_using_settings_only_is_allowed(self):
        self.check_response('unneeded', 'two')

    def test_request_subject_does_not_need_to_match_issuer_from_settings(self):
        self.test_settings['ASAP_SUBJECT_SHOULD_MATCH_ISSUER'] = False
        self.check_response('needed', 'one', 200, subject='different_than_is')

    def test_request_subject_and_issue_not_matching(self):
        self.check_response(
            'needed',
            'Subject and Issuer do not match',
            401,
            subject='different_than_is',
        )



class TestAsapDecorator(DjangoAsapMixin, RS256KeyTestMixin, SimpleTestCase):