コード例 #1
0
    def test_validate_config(self, *mock_methods):
        config_kwargs = {
            "http": True,
            "https": True,
            "relative_url": None,
            "auth_ca": "CA",
            "auth_cert": "CERT",
            "checksum_type": "sha256",
            "http_publish_dir": "/http/path/",
            "https_publish_dir": "https/path/",
            "protected": True,
            "skip": {"drpms": 1},
            "skip_pkg_tags": True,
            "generate_sqlite": False,
        }

        repo = Repository("test")
        config = self._generate_call_config(**config_kwargs)
        conduit = RepoConfigConduit(TYPE_ID_DISTRIBUTOR_YUM)

        valid, reasons = configuration.validate_config(repo, config, conduit)

        for mock_method in mock_methods:
            self.assertEqual(mock_method.call_count, 1)

        self.assertTrue(valid)
        self.assertEqual(reasons, None)
コード例 #2
0
    def test_validate_config(self, *mock_methods):
        config_kwargs = {'http': True,
                         'https': True,
                         'relative_url': None,
                         'auth_ca': 'CA',
                         'auth_cert': 'CERT',
                         'checksum_type': 'sha256',
                         'http_publish_dir': '/http/path/',
                         'https_publish_dir': 'https/path/',
                         'protected': True,
                         'skip': {'drpms': 1},
                         'skip_pkg_tags': True,
                         'generate_sqlite': False}

        repo = Repository('test')
        config = self._generate_call_config(**config_kwargs)
        conduit = RepoConfigConduit(TYPE_ID_DISTRIBUTOR_YUM)

        valid, reasons = configuration.validate_config(repo, config, conduit)

        for mock_method in mock_methods:
            self.assertEqual(mock_method.call_count, 1)

        self.assertTrue(valid)
        self.assertEqual(reasons, None)
コード例 #3
0
    def test_validate_config(self, *mock_methods):
        config_kwargs = {
            'http': True,
            'https': True,
            'relative_url': None,
            'auth_ca': 'CA',
            'auth_cert': 'CERT',
            'checksum_type': 'sha256',
            'http_publish_dir': '/http/path/',
            'https_publish_dir': 'https/path/',
            'protected': True,
            'skip': {
                'drpms': 1
            },
            'skip_pkg_tags': True,
            'generate_sqlite': False
        }

        repo = Repository('test')
        config = self._generate_call_config(**config_kwargs)
        conduit = RepoConfigConduit(TYPE_ID_DISTRIBUTOR_YUM)

        valid, reasons = configuration.validate_config(repo, config, conduit)

        for mock_method in mock_methods:
            self.assertEqual(mock_method.call_count, 1)

        self.assertTrue(valid)
        self.assertEqual(reasons, None)
コード例 #4
0
    def test_gpg_key(self, mock_process_auth):
        config_dict = {"http": True, "https": True, "relative_url": "a/b/c", "gpgkey": "/tmp/my.gpg"}
        config = self._generate_call_config(**config_dict)

        valid, reason = configuration.validate_config(Repository("myrepo"), config, mock.MagicMock())

        self.assertTrue(valid is True)
        self.assertTrue(reason is None)
コード例 #5
0
    def test_validate_config_unsupported_keys(self, mock_check):
        repo = Repository('test')
        config = self._generate_call_config(http=True, https=False, relative_url=None, foo='bar')
        conduit = RepoConfigConduit(TYPE_ID_DISTRIBUTOR_YUM)

        valid, reasons = configuration.validate_config(repo, config, conduit)

        self.assertFalse(valid)

        expected_reason = 'Configuration key [foo] is not supported'
        self.assertEqual(reasons, expected_reason)

        self.assertEqual(mock_check.call_count, 1)
コード例 #6
0
    def test_validate_config_missing_required(self, mock_check):
        repo = Repository('test')
        config = self._generate_call_config(http=True, https=False)
        conduit = RepoConfigConduit(TYPE_ID_DISTRIBUTOR_YUM)

        valid, reasons = configuration.validate_config(repo, config, conduit)

        self.assertFalse(valid)

        expected_reason = 'Configuration key [relative_url] is required, but was not provided'
        self.assertEqual(reasons, expected_reason)

        mock_check.assert_called_once_with(repo, config.flatten(), conduit, [expected_reason])
コード例 #7
0
    def test_validate_config_unsupported_keys(self, mock_check):
        repo = Repository('test')
        config = self._generate_call_config(http=True, https=False, relative_url=None, foo='bar')
        conduit = RepoConfigConduit(TYPE_ID_DISTRIBUTOR_YUM)

        valid, reasons = configuration.validate_config(repo, config, conduit)

        self.assertFalse(valid)

        expected_reason = 'Configuration key [foo] is not supported'
        self.assertEqual(reasons, expected_reason)

        self.assertEqual(mock_check.call_count, 1)
コード例 #8
0
    def test_validate_config_missing_required(self, mock_check):
        repo = Repository('test')
        config = self._generate_call_config(http=True, https=False)
        conduit = RepoConfigConduit(TYPE_ID_DISTRIBUTOR_YUM)

        valid, reasons = configuration.validate_config(repo, config, conduit)

        self.assertFalse(valid)

        expected_reason = 'Configuration key [relative_url] is required, but was not provided'
        self.assertEqual(reasons, expected_reason)

        mock_check.assert_called_once_with(repo, config.flatten(), conduit, [expected_reason])
コード例 #9
0
    def test_validate_config_https_http_false(self, mock_check):
        repo = Repository('test')
        config = self._generate_call_config(http=False, https=False, relative_url=None)
        conduit = RepoConfigConduit(TYPE_ID_DISTRIBUTOR_YUM)

        valid, reasons = configuration.validate_config(repo, config, conduit)

        self.assertFalse(valid)

        expected_reason = ('Settings serve via http and https are both set to false.'
                           ' At least one option should be set to true.')
        self.assertEqual(reasons, expected_reason)

        self.assertEqual(mock_check.call_count, 1)
コード例 #10
0
    def test_gpg_key(self, mock_process_auth):
        config_dict = {
            'http': True,
            'https': True,
            'relative_url': 'a/b/c',
            'gpgkey': '/tmp/my.gpg',
        }
        config = self._generate_call_config(**config_dict)

        valid, reason = configuration.validate_config(Repository('myrepo'),
                                                      config, mock.MagicMock())

        self.assertTrue(valid is True)
        self.assertTrue(reason is None)
コード例 #11
0
    def test_gpg_key(self, mock_process_auth):
        config_dict = {
            'http': True,
            'https': True,
            'relative_url': 'a/b/c',
            'gpgkey': '/tmp/my.gpg',
        }
        config = self._generate_call_config(**config_dict)

        valid, reason = configuration.validate_config(Repository('myrepo'),
                                                      config, mock.MagicMock())

        self.assertTrue(valid is True)
        self.assertTrue(reason is None)
コード例 #12
0
    def test_validate_config_https_http_false(self, mock_check):
        repo = Repository('test')
        config = self._generate_call_config(http=False, https=False, relative_url=None)
        conduit = RepoConfigConduit(TYPE_ID_DISTRIBUTOR_YUM)

        valid, reasons = configuration.validate_config(repo, config, conduit)

        self.assertFalse(valid)

        expected_reason = ('Settings serve via http and https are both set to false.'
                           ' At least one option should be set to true.')
        self.assertEqual(reasons, expected_reason)

        self.assertEqual(mock_check.call_count, 1)
コード例 #13
0
    def test_validate_config__repocfg_gpg_cmd(self):
        repo = Repository('test')
        config = self._generate_call_config(http=False,
                                            https=True,
                                            relative_url="a/b")
        config.repo_plugin_config["gpg_cmd"] = "this should fail"
        conduit = RepoConfigConduit(TYPE_ID_DISTRIBUTOR_YUM)

        valid, reasons = configuration.validate_config(repo, config, conduit)

        self.assertFalse(valid)

        expected_reason = ('Configuration key [gpg_cmd] is not allowed '
                           'in repository plugin configuration')
        self.assertEqual(reasons, expected_reason)
コード例 #14
0
    def test_validate_config_https_http_null(self, mock_check):
        repo = Repository("test")
        config = self._generate_call_config(relative_url=None)
        conduit = RepoConfigConduit(TYPE_ID_DISTRIBUTOR_YUM)

        valid, reasons = configuration.validate_config(repo, config, conduit)

        self.assertFalse(valid)

        expected_reason = (
            "Configuration key [http] is required, but was not provided\n"
            "Configuration key [https] is required, but was not provided\n"
            "Settings serve via http and https are both set to false."
            " At least one option should be set to true."
        )
        self.assertEqual(reasons, expected_reason)

        self.assertEqual(mock_check.call_count, 1)