def test_validate_config_iso_prefix(self):
     repo = mock.Mock(spec=Repository)
     repo.id = "testrepo"
     distributor = ISODistributor()
     # test invalid iso prefix
     config = distributor_mocks.get_basic_config(http=True, https=False, iso_prefix="my_iso*_name_/")
     state, msg = distributor.validate_config(repo, config, [])
     self.assertFalse(state)
     # test valid iso prefix
     config = distributor_mocks.get_basic_config(http=True, https=False, iso_prefix="My_iso_name-01")
     state, msg = distributor.validate_config(repo, config, [])
     self.assertTrue(state)
    def test_validate_config(self):
        """
        Test the validate_config method in ISODistributor, which just hands the config off to a helper
        method in export_utils
        """
        # Setup
        validate_config = export_utils.validate_export_config
        export_utils.validate_export_config = mock.MagicMock()
        distributor = ISODistributor()

        # Test. All validate_config should do is hand the config argument to the export_utils validator
        distributor.validate_config(None, 'config', None)
        export_utils.validate_export_config.assert_called_once_with('config')

        # Clean up
        export_utils.validate_export_config = validate_config
    def test_validate_config(self):
        distributor = ISODistributor()
        repo = mock.Mock(spec=Repository)
        repo.id = "testrepo"
        http = "true"
        https = False
        config = distributor_mocks.get_basic_config(http=http, https=https)
        state, msg = distributor.validate_config(repo, config, [])
        self.assertFalse(state)

        http = True
        config = distributor_mocks.get_basic_config(http=http, https=https)
        state, msg = distributor.validate_config(repo, config, [])
        self.assertTrue(state)

        http = True
        https = "False"
        relative_url = "test_path"
        config = distributor_mocks.get_basic_config(http=http, https=https)
        state, msg = distributor.validate_config(repo, config, [])
        self.assertFalse(state)

        https = True
        config = distributor_mocks.get_basic_config(http=http, https=https)
        state, msg = distributor.validate_config(repo, config, [])
        self.assertTrue(state)

        http = True
        https = False
        relative_url = "test_path"
        skip_content_types = "fake"
        config = distributor_mocks.get_basic_config(http=http, https=https,
            skip=skip_content_types)
        state, msg = distributor.validate_config(repo, config, [])
        self.assertFalse(state)

        skip_content_types = []
        config = distributor_mocks.get_basic_config(http=http, https=https,
            skip=skip_content_types)
        state, msg = distributor.validate_config(repo, config, [])
        self.assertTrue(state)

        # test invalid iso prefix
        config = distributor_mocks.get_basic_config(http=True, https=False, iso_prefix="my_iso*_name_/")
        state, msg = distributor.validate_config(repo, config, [])
        self.assertFalse(state)
        # test valid iso prefix
        config = distributor_mocks.get_basic_config(http=True, https=False, iso_prefix="My_iso_name-01")
        state, msg = distributor.validate_config(repo, config, [])
        self.assertTrue(state)

        invalid_config="dummy"
        config = distributor_mocks.get_basic_config(invalid_config)
        state, msg = distributor.validate_config(repo, config, [])
        self.assertFalse(state)

        http_publish_dir = self.http_publish_dir
        config = distributor_mocks.get_basic_config(http=http, https=https,
            http_publish_dir=http_publish_dir)
        state, msg = distributor.validate_config(repo, config, [])
        self.assertTrue(state)

        http_publish_dir = "test"
        config = distributor_mocks.get_basic_config(http=http, https=https,
            http_publish_dir=http_publish_dir)
        state, msg = distributor.validate_config(repo, config, [])
        self.assertFalse(state)

        https_publish_dir = self.https_publish_dir
        config = distributor_mocks.get_basic_config(http=http, https=https,
            https_publish_dir=https_publish_dir)
        state, msg = distributor.validate_config(repo, config, [])
        self.assertTrue(state)

        https_publish_dir = "test"
        config = distributor_mocks.get_basic_config(http=http, https=https,
            https_publish_dir=https_publish_dir)
        state, msg = distributor.validate_config(repo, config, [])
        self.assertFalse(state)

        if not M2CRYPTO_HAS_CRL_SUPPORT:
            return
        http = True
        https = False
        relative_url = "test_path"
        auth_cert = "fake"
        config = distributor_mocks.get_basic_config(http=http, https=https,
            https_ca=auth_cert)
        state, msg = distributor.validate_config(repo, config, [])
        self.assertFalse(state)

        auth_cert = open(os.path.join(self.data_dir, "cert.crt")).read()
        config = distributor_mocks.get_basic_config(http=http, https=https,
            https_ca=auth_cert)
        state, msg = distributor.validate_config(repo, config, [])
        self.assertTrue(state)