def test_validate_config(self): # validate_config doesn't use the repo or related_repos args, so we'll just pass None for # ease config = get_basic_config(**{constants.CONFIG_SERVE_HTTP: True, constants.CONFIG_SERVE_HTTPS: True}) repo = self._get_default_repo() status, error_message = self.iso_distributor.validate_config(repo, config, None) self.assertTrue(status) self.assertEqual(error_message, None) # Try setting the HTTP one to a string, which should be OK as long as it's still True config = get_basic_config(**{constants.CONFIG_SERVE_HTTP: "True", constants.CONFIG_SERVE_HTTPS: True}) repo = self._get_default_repo() status, error_message = self.iso_distributor.validate_config(repo, config, None) self.assertTrue(status) self.assertEqual(error_message, None) # Now try setting the HTTPS one to an invalid string config = get_basic_config(**{constants.CONFIG_SERVE_HTTP: True, constants.CONFIG_SERVE_HTTPS: "Heyo!"}) repo = self._get_default_repo() status, error_message = self.iso_distributor.validate_config(repo, config, None) self.assertFalse(status) self.assertEqual(error_message, 'The configuration parameter <serve_https> may only be set to a ' 'boolean value, but is currently set to <Heyo!>.')
def test_post_repo_publish_ignores_configure_repository_protection_if_cert_missing( self, mock_protection): repo = self._get_default_repo() config = get_basic_config(**{constants.CONFIG_SERVE_HTTP: False, constants.CONFIG_SERVE_HTTPS: True}) self.iso_distributor.post_repo_publish(repo, config) self.assertFalse(mock_protection.called)
def test_get_hosting_locations_https_only_default(self): """ Test the _get_hosting_locations() for an http only repository function. """ repo = self._get_default_repo() config = get_basic_config() locations = self.iso_distributor.get_hosting_locations(repo, config) self.assertEquals(1, len(locations)) self.assertEquals(os.path.join(constants.ISO_HTTPS_DIR, repo.repo_id), locations[0])
def test_post_repo_publish_calls_configure_repository_protection_if_https_enabled(self, mock_protection): repo = self._get_default_repo() cert = "foo" config = get_basic_config(**{constants.CONFIG_SERVE_HTTP: False, constants.CONFIG_SERVE_HTTPS: True, constants.CONFIG_SSL_AUTH_CA_CERT: cert}) self.iso_distributor.post_repo_publish(repo, config) mock_protection.assert_called_once_with(repo, cert)
def test_get_hosting_locations_https_only_default(self): """ Test the _get_hosting_locations() for an http only repository function. """ repo = self._get_default_repo() config = get_basic_config() locations = self.iso_distributor.get_hosting_locations(repo, config) self.assertEquals(1, len(locations)) self.assertEquals(os.path.join(constants.ISO_HTTPS_DIR, repo.id), locations[0])
def test_get_hosting_locations_http_only(self): """ Test the _get_hosting_locations() for an http only repository function. """ repo = self._get_default_repo() config = get_basic_config(**{constants.CONFIG_SERVE_HTTP: True, constants.CONFIG_SERVE_HTTPS: False}) locations = self.iso_distributor.get_hosting_locations(repo, config) self.assertEquals(1, len(locations)) self.assertEquals(os.path.join(constants.ISO_HTTP_DIR, repo.id), locations[0])
def test_post_repo_publish_calls_configure_repository_protection_if_https_enabled( self, mock_protection): repo = self._get_default_repo() cert = "foo" config = get_basic_config(**{constants.CONFIG_SERVE_HTTP: False, constants.CONFIG_SERVE_HTTPS: True, constants.CONFIG_SSL_AUTH_CA_CERT: cert}) self.iso_distributor.post_repo_publish(repo, config) mock_protection.assert_called_once_with(repo, cert)
def test_get_hosting_locations_http_and_https(self): """ Test the _get_hosting_locations() for an http only repository function. """ repo = self._get_default_repo() config = get_basic_config(**{constants.CONFIG_SERVE_HTTP: True, constants.CONFIG_SERVE_HTTPS: True}) locations = self.iso_distributor.get_hosting_locations(repo, config) self.assertEquals(2, len(locations)) self.assertEquals(os.path.join(constants.ISO_HTTP_DIR, repo.id), locations[0]) self.assertEquals(os.path.join(constants.ISO_HTTPS_DIR, repo.id), locations[1])
def test_validate_config(self): # validate_config doesn't use the repo or related_repos args, so we'll just pass None for # ease config = get_basic_config(**{ constants.CONFIG_SERVE_HTTP: True, constants.CONFIG_SERVE_HTTPS: True }) repo = self._get_default_repo() status, error_message = self.iso_distributor.validate_config( repo, config, None) self.assertTrue(status) self.assertEqual(error_message, None) # Try setting the HTTP one to a string, which should be OK as long as it's still True config = get_basic_config( **{ constants.CONFIG_SERVE_HTTP: "True", constants.CONFIG_SERVE_HTTPS: True }) repo = self._get_default_repo() status, error_message = self.iso_distributor.validate_config( repo, config, None) self.assertTrue(status) self.assertEqual(error_message, None) # Now try setting the HTTPS one to an invalid string config = get_basic_config( **{ constants.CONFIG_SERVE_HTTP: True, constants.CONFIG_SERVE_HTTPS: "Heyo!" }) repo = self._get_default_repo() status, error_message = self.iso_distributor.validate_config( repo, config, None) self.assertFalse(status) self.assertEqual( error_message, 'The configuration parameter <serve_https> may only be set to a ' 'boolean value, but is currently set to <Heyo!>.')
def test_post_repo_publish_does_not_call_configure_repository_protection_if_https_disabled( self, mock_protection): repo = self._get_default_repo() config = get_basic_config(**{constants.CONFIG_SERVE_HTTPS: False}) self.iso_distributor.post_repo_publish(repo, config) self.assertFalse(mock_protection.called)