Skip to content

Commit

Permalink
fix credentials necessary for install (#4872)
Browse files Browse the repository at this point in the history
* fix credentials necessary for install

* removed check_credentials check

* fix test

* added a new test

* checking credentials in uploader
  • Loading branch information
memsharded authored and lasote committed Apr 1, 2019
1 parent dc58c56 commit e5ff8f6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions conans/client/cmd/uploader.py
Expand Up @@ -335,6 +335,7 @@ def _compress_package_files(self, pref, integrity_check):

def _recipe_files_to_upload(self, ref, policy, the_files, remote, remote_manifest):
# Get the remote snapshot
self._remote_manager.check_credentials(remote)
remote_snapshot = self._remote_manager.get_recipe_snapshot(ref, remote)

if remote_snapshot and policy != UPLOAD_POLICY_FORCE:
Expand All @@ -353,6 +354,7 @@ def _recipe_files_to_upload(self, ref, policy, the_files, remote, remote_manifes
return files_to_upload, deleted

def _package_files_to_upload(self, pref, policy, the_files, remote):
self._remote_manager.check_credentials(remote)
remote_snapshot = self._remote_manager.get_package_snapshot(pref, remote)

if remote_snapshot:
Expand Down
3 changes: 3 additions & 0 deletions conans/client/remote_manager.py
Expand Up @@ -32,6 +32,9 @@ def __init__(self, cache, auth_manager, output, hook_manager):
self._auth_manager = auth_manager
self._hook_manager = hook_manager

def check_credentials(self, remote):
self._call_remote(remote, "check_credentials")

def get_recipe_snapshot(self, ref, remote):
assert ref.revision, "get_recipe_snapshot requires revision"
return self._call_remote(remote, "get_recipe_snapshot", ref)
Expand Down
3 changes: 3 additions & 0 deletions conans/client/rest/auth_manager.py
Expand Up @@ -124,6 +124,9 @@ def set_custom_headers(self, username):
custom_headers['X-Client-Id'] = str(username or "")

# ######### CONAN API METHODS ##########
@input_credentials_if_unauthorized
def check_credentials(self):
self._rest_client.check_credentials()

@input_credentials_if_unauthorized
def upload_recipe(self, ref, files_to_upload, deleted, retry, retry_wait):
Expand Down
8 changes: 4 additions & 4 deletions conans/client/rest/rest_client_common.py
Expand Up @@ -162,15 +162,15 @@ def upload_recipe(self, ref, files_to_upload, deleted, retry, retry_wait):
self._remove_conanfile_files(ref, deleted)

def get_recipe_snapshot(self, ref):
self.check_credentials()

# this method is used only for UPLOADING, then it requires the credentials
# Check of credentials is done in the uploader
url = self.router.recipe_snapshot(ref)
snap = self._get_snapshot(url)
return snap

def get_package_snapshot(self, pref):
self.check_credentials()

# this method is also used to check the integrity of the package upstream
# while installing, so check_credentials is done in uploader.
url = self.router.package_snapshot(pref)
snap = self._get_snapshot(url)
return snap
Expand Down
13 changes: 13 additions & 0 deletions conans/test/functional/command/install_test.py
Expand Up @@ -9,6 +9,7 @@
from conans.test.utils.cpp_test_files import cpp_hello_conan_files
from conans.test.utils.tools import TestClient, TestServer
from conans.util.files import load, mkdir, rmdir
from conans.test.utils.conanfile import TestConanFile


class InstallTest(unittest.TestCase):
Expand Down Expand Up @@ -566,3 +567,15 @@ class TestConan(ConanFile):
client.run("install -o boost:shared=True --build missing --build boost .")
output_5 = "%s" % client.out
self.assertEqual(output_4, output_5)

def install_anonymous_test(self):
# https://github.com/conan-io/conan/issues/4871
servers = {"default": TestServer()}
client = TestClient(servers=servers, users={"default": [("lasote", "mypass")]})
client.save({"conanfile.py": str(TestConanFile("Pkg", "0.1"))})
client.run("create . lasote/testing")
client.run("upload * --confirm --all")

client2 = TestClient(servers=servers, users={})
client2.run("install Pkg/0.1@lasote/testing")
self.assertIn("Pkg/0.1@lasote/testing: Package installed", client2.out)

0 comments on commit e5ff8f6

Please sign in to comment.