Пример #1
0
    def test_identity_dict_creation(self):

        def random_method(self):
            return "test method result"

        User.random_method = random_method
        user = User()
        user.name = 'Test Name'
        user.email = '*****@*****.**'
        user.other_setting = 'Test Setting'
        user.setting_not_passed = 'Test Setting Not Passed'

        service_provider = ServiceProvider(entity_id='entity-id', _attribute_mapping=json.dumps({
                'name': 'fullName',
                'email': 'emailAddress',
                'other_setting': 'otherSetting',
                'random_method': 'randomMethodTest'
            }))
        _ = IDP.load().config

        expected_result = {
            'fullName': 'Test Name',
            'emailAddress': '*****@*****.**',
            'otherSetting': 'Test Setting',
            'randomMethodTest': 'test method result'
        }

        assert BaseProcessor('entity_id').create_identity(user, service_provider.attribute_mapping) == expected_result
Пример #2
0
 def test_property_digest_algorithm(self):
     instance = ServiceProvider(_digest_algorithm=None)
     assert instance.digest_algorithm == getattr(IDP.load().config,
                                                 "SAML_AUTHN_DIGEST_ALG",
                                                 xmldsig.DIGEST_SHA256)
     instance = ServiceProvider(_digest_algorithm='dummy_value')
     assert instance.digest_algorithm == 'dummy_value'
Пример #3
0
 def test_property_signing_algorithm(self):
     instance = ServiceProvider(_signing_algorithm=None)
     assert instance.signing_algorithm == getattr(IDP.load().config,
                                                  "SAML_AUTHN_SIGN_ALG",
                                                  xmldsig.SIG_RSA_SHA256)
     instance = ServiceProvider(_signing_algorithm='dummy_value')
     assert instance.signing_algorithm == 'dummy_value'
Пример #4
0
 def test_metadata_sp_autoload_idp(self, sp_model_mock):
     '''The IdP metadata should not require loading of SP metadata.'''
     sp_instance_mock = Mock()
     sp_instance_mock.metadata_path.return_value = '/tmp/djangosaml2idp/1.xml'
     sp_model_mock.objects.filter.return_value = [sp_instance_mock]
     IDP._server_instance = None
     md = IDP.metadata()
     sp_instance_mock.metadata_path.assert_not_called()
Пример #5
0
    def test_extract_user_id_default_to_username(self):
        user = User()
        user.username = '******'

        service_provider = ServiceProvider(entity_id='entity-id')
        idp = IDP.load().config

        assert BaseProcessor('entity-id').get_user_id(user, NAMEID_FORMAT_UNSPECIFIED, service_provider, idp) == 'test_username'
Пример #6
0
    def test_extract_user_id_configure_on_service_provider(self):
        user = User()
        user.USERNAME_FIELD = 'email'
        user.email = 'test_email'

        service_provider = ServiceProvider(entity_id='entity-id', _nameid_field='email')
        idp = IDP.load().config

        assert BaseProcessor('entity-id').get_user_id(user, NAMEID_FORMAT_UNSPECIFIED, service_provider, idp) == 'test_email'
Пример #7
0
    def test_extract_user_id_configure_by_settings(self, settings):
        """Should use `settings.SAML_IDP_DJANGO_USERNAME_FIELD` to determine the user id field"""

        settings.SAML_IDP_DJANGO_USERNAME_FIELD = 'first_name'

        user = User(first_name='test_first_name')
        service_provider = ServiceProvider(entity_id='entity-id')
        idp = IDP.load().config

        assert BaseProcessor('entity-id').get_user_id(user, NAMEID_FORMAT_UNSPECIFIED, service_provider, idp) == 'test_first_name'
Пример #8
0
    def test_extract_user_id_from_sp_config_if_method(self):

        def random_method(self):
            return "test method result"

        User.random_method = random_method

        user = User()

        service_provider = ServiceProvider(entity_id='entity-id', _nameid_field='random_method')
        idp = IDP.load().config

        assert BaseProcessor('entity-id').get_user_id(user, NAMEID_FORMAT_UNSPECIFIED, service_provider, idp) == 'test method result'
Пример #9
0
 def test_metadata_no_settings_defined(self, settings):
     IDP._server_instance = None
     settings.SAML_IDP_CONFIG = None
     with pytest.raises(ImproperlyConfigured):
         IDP.metadata()
Пример #10
0
 def test_metadata_no_sp_defined_valid(self):
     IDP._server_instance = None
     md = IDP.metadata()
     assert isinstance(md, str)
Пример #11
0
 def test_idp_load_default_settings_defined_and_valid(self):
     IDP._server_instance = None
     srv = IDP.load()
     assert isinstance(srv, Server)
Пример #12
0
 def test_property_encrypt_saml_responses(self):
     instance = ServiceProvider(_encrypt_saml_responses=None)
     assert instance.encrypt_saml_responses == getattr(
         IDP.load().config, "SAML_ENCRYPT_AUTHN_RESPONSE", False)
     instance = ServiceProvider(_encrypt_saml_responses=True)
     assert instance.encrypt_saml_responses == True
Пример #13
0
 def test_property_sign_assertion(self):
     instance = ServiceProvider(_sign_assertion=None)
     assert instance.sign_assertion == getattr(IDP.load().config,
                                               "sign_assertion", False)
     instance = ServiceProvider(_sign_assertion=True)
     assert instance.sign_assertion == True
Пример #14
0
 def test_property_sign_response(self):
     instance = ServiceProvider(_sign_response=None)
     assert instance.sign_response == getattr(IDP.load().config,
                                              "sign_response", False)
     instance = ServiceProvider(_sign_response=True)
     assert instance.sign_response == True