From e6bfadbb27619c2ec3a59faf4117e54dcd6ed36e Mon Sep 17 00:00:00 2001 From: James Date: Tue, 23 Apr 2024 09:38:58 +0200 Subject: [PATCH] fixed wrong servers 200 ok (#16126) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fixed wrong servers 200 ok * Update conans/client/rest/rest_client_common.py Co-authored-by: Rubén Rincón Blanco * wip --------- Co-authored-by: Rubén Rincón Blanco --- conans/client/rest/rest_client_common.py | 5 ++++- .../integration/command/upload/upload_test.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/conans/client/rest/rest_client_common.py b/conans/client/rest/rest_client_common.py index b0956c2ce3f..9a3f76243b2 100644 --- a/conans/client/rest/rest_client_common.py +++ b/conans/client/rest/rest_client_common.py @@ -142,11 +142,14 @@ def server_capabilities(self, user=None, password=None): auth = self.auth ret = self.requester.get(url, auth=auth, headers=self.custom_headers, verify=self.verify_ssl) - server_capabilities = ret.headers.get('X-Conan-Server-Capabilities', "") + server_capabilities = ret.headers.get('X-Conan-Server-Capabilities') if not server_capabilities and not ret.ok: # Old Artifactory might return 401/403 without capabilities, we don't want # to cache them #5687, so raise the exception and force authentication raise get_exception_from_error(ret.status_code)(response_to_str(ret)) + if server_capabilities is None: + # Some servers returning 200-ok, even if not valid repo + raise ConanException(f"Remote {self.remote_url} doesn't seem like a valid Conan remote") return [cap.strip() for cap in server_capabilities.split(",") if cap] diff --git a/conans/test/integration/command/upload/upload_test.py b/conans/test/integration/command/upload/upload_test.py index 7a17a61aa37..eda0c069573 100644 --- a/conans/test/integration/command/upload/upload_test.py +++ b/conans/test/integration/command/upload/upload_test.py @@ -8,6 +8,7 @@ import pytest import requests from mock import patch +from requests import Response from conans.errors import ConanException from conans.model.package_ref import PkgReference @@ -485,6 +486,21 @@ def get(self, url, **kwargs): client.run("upload hello0/1.2.1@user/testing -r default") assert "Uploading recipe 'hello0/1.2.1@user/testing" in client.out + def test_server_returns_200_ok(self): + # https://github.com/conan-io/conan/issues/16104 + # If server returns 200 ok, without headers, it raises an error + class MyHttpRequester(TestRequester): + def get(self, _, **kwargs): + resp = Response() + resp.status_code = 200 + return resp + + client = TestClient(requester_class=MyHttpRequester, servers={"default": TestServer()}) + client.save({"conanfile.py": GenConanfile("hello0", "1.2.1")}) + client.run("create . ") + client.run("upload * -c -r default", assert_error=True) + assert "doesn't seem like a valid Conan remote" in client.out + def test_upload_only_without_user_channel(): """