def test_download_with_content_guard(self): """Test that downloads with content guards work correctly.""" # Using requests for these tests because the client follows redirects and I need to # inspect the URL that gets redirected to # setup content guard cfg = config.get_config() configuration = cfg.get_bindings_config() core_client = CoreApiClient(configuration) guard_client = ContentguardsContentRedirectApi(core_client) guard = guard_client.create({"name": "test-content-guard"}) self.addCleanup(guard_client.delete, guard.pulp_href) self.distributions_api.partial_update( self.distribution.pulp_href, {"content_guard": guard.pulp_href}) download_url = self._get_download_url("testing", "k8s_demo_collection") response = requests.get(download_url, auth=tuple(cfg.pulp_auth), allow_redirects=False) # verify that the download url redirects to the content app assert response.is_redirect content_app_url = response.headers["Location"] # verify that token is present assert "?validate_token" in content_app_url collection = requests.get(content_app_url) assert collection.status_code == 200 assert collection.headers["content-type"] == "application/x-tar" # make an unauthenticated call to the content app and verify that it gets # rejected collection = requests.get(content_app_url.split("?")[0]) assert collection.status_code == 403