コード例 #1
0
def test_load_root(root_config_file):
    """Load root config file and test for presence of root-level keys"""
    config = ConfigFileLoader.load_root_config(root_config_file)
    assert isinstance(config, dict)
    assert ('adobe_users' in config and 'directory_users' in config
            and 'logging' in config and 'limits' in config
            and 'invocation_defaults' in config)
コード例 #2
0
    def test_load_sub_config(self, mock_yaml, mock_open):
        '''
        same purpose as test_load_root_config, but tests against sub
        configuration path updates (which is currently only the private key
        path in the dashboard configuration file)
        :type mock_yaml: Mock
        :type mock_open: Mock
        '''
        mocked_open = mock_open('test')
        mocked_open_name = '%s.open' % __name__
        with patch(mocked_open_name, mocked_open, create=True):
            mock_yaml.return_value = {
                'enterprise': {
                    'priv_key_path': '../keys/test-key.key',
                    'test': 'value should not change'
                },
                'other': {
                    'test-2': 123
                }
            }

            yml = ConfigFileLoader.load_sub_config(
                'sub-config-test/user-sync-config-test.yml')

            # test path updating
            self.assert_eq(yml['enterprise']['priv_key_path'],
                           os.path.abspath('keys/test-key.key'),
                           'private key path is incorrect')

            # test control keys
            self.assert_eq(yml['enterprise']['test'],
                           'value should not change',
                           '/enterprise/test value should not change')
            self.assert_eq(yml['other']['test-2'], 123,
                           '/other/test-2 value should not change')
コード例 #3
0
def test_max_adobe_percentage(modify_root_config, caplog):
    root_config_file = modify_root_config(['limits', 'max_adobe_only_users'], "50%")
    config = ConfigFileLoader.load_root_config(root_config_file)
    assert ('limits' in config and 'max_adobe_only_users' in config['limits'] and
            config['limits']['max_adobe_only_users'] == "50%")

    args = app.process_args(['-c', root_config_file])
    options = ConfigLoader(args).get_rule_options()
    assert 'max_adobe_only_users' in options and options['max_adobe_only_users'] == '50%'

    modify_root_config(['limits', 'max_adobe_only_users'], "error%")
    with pytest.raises(AssertionException):
        ConfigLoader(args).get_rule_options()
コード例 #4
0
def test_additional_groups_config(modify_root_config, caplog):
    addl_groups = [
        {"source": r"ACL-(.+)", "target": r"ACL-Grp-(\1)"},
        {"source": r"(.+)-ACL", "target": r"ACL-Grp-(\1)"},
    ]
    root_config_file = modify_root_config(['directory_users', 'additional_groups'], addl_groups)
    config = ConfigFileLoader.load_root_config(root_config_file)
    assert ('additional_groups' in config['directory_users'] and
            len(config['directory_users']['additional_groups']) == 2)

    args = app.process_args(['-c', root_config_file])
    options = ConfigLoader(args).get_rule_options()
    assert addl_groups[0]['source'] in options['additional_groups'][0]['source'].pattern
    assert addl_groups[1]['source'] in options['additional_groups'][1]['source'].pattern
コード例 #5
0
    def test_load_root_config(self, mock_isfile, mock_yaml, mock_open):
        '''
        tests ConfigFileLoader.load_root_config by inputing a root configuration
        file path, and asserts that the resulting processed content has the
        file references properly updated
        :type mock_isfile: Mock
        :type mock_yaml: Mock
        :type mock_open: Mock
        '''
        mock_isfile.return_value = True
        mocked_open = mock_open('test')
        mocked_open_name = '%s.open' % __name__
        with patch(mocked_open_name, mocked_open, create=True):
            mock_yaml.return_value = {
                'logging': {
                    'file_log_directory': 'log-test-1'
                },
                'other': {
                    'test-string': 'test string value should not change',
                    'test-dict': {
                        'test-string-2': 'this should not change as well'
                    },
                    'test-list':
                    ['item-1', 'item-2', {
                        'test-string-3': 'xyz'
                    }]
                }
            }
            yml = ConfigFileLoader.load_root_config(
                'config-test/user-sync-config-test.yml')

            # test path updating
            self.assert_eq(yml['logging']['file_log_directory'],
                           os.path.abspath('config-test/log-test-1'),
                           'logging path is incorrect')

            # test control keys
            self.assert_eq(yml['other']['test-string'],
                           'test string value should not change',
                           '/other/test-string value should not change')
            self.assert_eq(
                yml['other']['test-dict']['test-string-2'],
                'this should not change as well',
                '/other/test-dict/test-string-2 value should not change')
            self.assert_eq(yml['other']['test-list'][0], 'item-1',
                           '/other/test-list/[0] value should not change')
            self.assert_eq(yml['other']['test-list'][2]['test-string-3'],
                           'xyz',
                           '/other/test-list/[2] value should not change')
コード例 #6
0
    def test_load_root_default_config(self, mock_yaml, mock_open):
        '''
        tests ConfigFileLoader.load_root_config by inputing a root configuration
        file path, and asserts that the resulting processed content has the
        file references properly updated
        :type mock_yaml: Mock
        :type mock_open: Mock
        '''
        mocked_open = mock_open('test')
        mocked_open_name = '%s.open' % __name__
        with patch(mocked_open_name, mocked_open, create=True):
            mock_yaml.return_value = {
                'dashboard': {
                    'other-1': 'test-123'
                },
                'logging': {
                    'file_log_directory': 'logs-test'
                },
            }

            yml = ConfigFileLoader.load_root_config(
                'config-test-2/user-sync-config-test.yml')

            # assert default values are preserved
            self.assert_eq(
                yml['dashboard']['owning'],
                os.path.abspath(
                    'config-test-2/%s' %
                    user_sync.config.DEFAULT_DASHBOARD_OWNING_CONFIG_FILENAME),
                'default owning dashboard configuration path is incorrect')
            self.assert_eq(
                yml['dashboard']['accessor_config_filename_format'],
                os.path.abspath(
                    'config-test-2/%s' % user_sync.config.
                    DEFAULT_DASHBOARD_ACCESSOR_CONFIG_FILENAME_FORMAT),
                'default accessor dashboard configuration file format is incorrect'
            )

            # assert file paths are still updated properly
            self.assert_eq(
                yml['logging']['file_log_directory'],
                os.path.abspath('config-test-2/logs-test'),
                'default owning dashboard configuration path is incorrect')
コード例 #7
0
    def test_load_root_default_config(self, mock_isfile, mock_yaml, mock_open):
        '''
        tests ConfigFileLoader.load_root_config by inputing a root configuration
        file path, and asserts that the resulting processed content has the
        file references properly updated
        :type mock_isfile: Mock
        :type mock_yaml: Mock
        :type mock_open: Mock
        '''
        mock_isfile.return_value = True
        mocked_open = mock_open('test')
        mocked_open_name = '%s.open' % __name__
        with patch(mocked_open_name, mocked_open, create=True):
            mock_yaml.return_value = {
                'adobe_users': {
                    'connectors': {
                        'umapi': 'test-123'
                    }
                },
                'logging': {
                    'log_to_file': True
                },
            }
            yml = ConfigFileLoader.load_root_config(
                'config-test-2/user-sync-config-test.yml')

            # assert default values are preserved
            self.assert_eq(yml['logging']['file_log_directory'],
                           os.path.abspath('config-test-2/logs'),
                           'default log path is missing or incorrect')

            # assert file paths are still updated properly
            self.assert_eq(
                yml['adobe_users']['connectors']['umapi'],
                os.path.abspath('config-test-2/test-123'),
                'default primary umapi configuration path is incorrect')
コード例 #8
0
    def test_load_root_config(self, mock_yaml, mock_open):
        '''
        tests ConfigFileLoader.load_root_config by inputing a root configuration
        file path, and asserts that the resulting processed content has the
        file references properly updated
        :type mock_yaml: Mock
        :type mock_open: Mock
        '''
        mocked_open = mock_open('test')
        mocked_open_name = '%s.open' % __name__
        with patch(mocked_open_name, mocked_open, create=True):
            mock_yaml.return_value = {
                'dashboard': {
                    'owning': 'dashboard/dashboard-owning-config-test.yml',
                    'accessors': {
                        'test-org-1': {
                            'enterprise': {
                                'priv_key_path':
                                '../keys/test-org-1/private-key-test.key'
                            }
                        },
                        'test-org-2': 'accessors/xyz/accessor-config-test.yml'
                    },
                    'accessor_config_filename_format':
                    'accessors-test/dashboard-accessor-{organization_name}-config.yml',
                    'test': 'value should not change'
                },
                'logging': {
                    'file_log_directory': 'logs'
                },
                'other': {
                    'test-string': 'test string value should not change',
                    'test-dict': {
                        'test-string-2': 'this should not change as well'
                    },
                    'test-list':
                    ['item-1', 'item-2', {
                        'test-string-3': 'xyz'
                    }]
                }
            }

            yml = ConfigFileLoader.load_root_config(
                'config-test/user-sync-config-test.yml')

            # test path updating
            self.assert_eq(
                yml['dashboard']['owning'],
                os.path.abspath(
                    'config-test/dashboard/dashboard-owning-config-test.yml'),
                'owning dashboard configuration path is incorrect')
            self.assert_eq(
                yml['dashboard']['accessor_config_filename_format'],
                os.path.abspath(
                    'config-test/accessors-test/dashboard-accessor-{organization_name}-config.yml'
                ), 'accessor dashboard config file format is incorrect')
            self.assert_eq(
                yml['dashboard']['accessors']['test-org-1']['enterprise']
                ['priv_key_path'],
                os.path.abspath('keys/test-org-1/private-key-test.key'),
                'accessor test_org_1 dashboard config private key path is incorrect'
            )
            self.assert_eq(
                yml['dashboard']['accessors']['test-org-2'],
                os.path.abspath(
                    'config-test/accessors/xyz/accessor-config-test.yml'),
                'accessor test_org_2 dashboard config file path is incorrect')
            self.assert_eq(yml['logging']['file_log_directory'],
                           os.path.abspath('config-test/logs'),
                           'logging path is incorrect')

            # test control keys
            self.assert_eq(yml['dashboard']['test'], 'value should not change',
                           '/dashboard/test value should not change')
            self.assert_eq(yml['other']['test-string'],
                           'test string value should not change',
                           '/other/test-string value should not change')
            self.assert_eq(
                yml['other']['test-dict']['test-string-2'],
                'this should not change as well',
                '/other/test-dict/test-string-2 value should not change')
            self.assert_eq(yml['other']['test-list'][0], 'item-1',
                           '/other/test-list/[0] value should not change')
            self.assert_eq(yml['other']['test-list'][2]['test-string-3'],
                           'xyz',
                           '/other/test-list/[2] value should not change')