Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed wrong servers 200 ok #16126

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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