diff --git a/components/renku_data_services/repositories/utils.py b/components/renku_data_services/repositories/utils.py index 69d42ac5a..c2c9dcd14 100644 --- a/components/renku_data_services/repositories/utils.py +++ b/components/renku_data_services/repositories/utils.py @@ -7,7 +7,10 @@ async def probe_repository(repository_url: str) -> bool: """Probe a repository to check if it is publicly available.""" async with httpx.AsyncClient(timeout=5) as client: url = f"{repository_url}/info/refs?service=git-upload-pack" - res = await client.get(url=url, follow_redirects=True) - if res.status_code != 200: + try: + res = await client.get(url=url, follow_redirects=True) + if res.status_code != 200: + return False + return bool(res.headers.get("Content-Type") == "application/x-git-upload-pack-advertisement") + except httpx.HTTPError: return False - return bool(res.headers.get("Content-Type") == "application/x-git-upload-pack-advertisement") diff --git a/test/bases/renku_data_services/data_api/test_repositories.py b/test/bases/renku_data_services/data_api/test_repositories.py index de4b61f1a..507984a81 100644 --- a/test/bases/renku_data_services/data_api/test_repositories.py +++ b/test/bases/renku_data_services/data_api/test_repositories.py @@ -139,3 +139,19 @@ async def test_get_one_repository_not_found( assert result.get("connection_id") == connection["id"] assert result.get("provider_id") == "provider_1" assert result.get("repository_metadata") is None + + +@pytest.mark.asyncio +@pytest.mark.parametrize( + "repository_url,status_code", + [ + ("https://github.com/SwissDataScienceCenter/renku.git", 200), + ("https://example.org/does-not-exist.git", 404), + ("http://foobar", 404), + ], +) +async def test_get_one_repository_probe(sanic_client: SanicASGITestClient, repository_url, status_code): + repository_url_param = quote_plus(repository_url) + _, response = await sanic_client.get(f"/api/data/repositories/{repository_url_param}/probe") + + assert response.status_code == status_code, response.text