Skip to content

Commit

Permalink
fixed wrong servers 200 ok (#16126)
Browse files Browse the repository at this point in the history
* fixed wrong servers 200 ok

* Update conans/client/rest/rest_client_common.py

Co-authored-by: Rubén Rincón Blanco <git@rinconblanco.es>

* wip

---------

Co-authored-by: Rubén Rincón Blanco <git@rinconblanco.es>
  • Loading branch information
memsharded and AbrilRBS authored Apr 23, 2024
1 parent 19e8ac5 commit e6bfadb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion conans/client/rest/rest_client_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
16 changes: 16 additions & 0 deletions conans/test/integration/command/upload/upload_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
"""
Expand Down

0 comments on commit e6bfadb

Please sign in to comment.