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

Enable authentication against a disabled remote #12913

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
2 changes: 1 addition & 1 deletion conan/cli/commands/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def remote_login(conan_api, parser, subparser, *args):
'requested interactively (not exposed)')

args = parser.parse_args(*args)
remotes = conan_api.remotes.list(pattern=args.remote)
remotes = conan_api.remotes.list(pattern=args.remote, only_enabled=False)
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
if not remotes:
raise ConanException("There are no remotes matching the '{}' pattern".format(args.remote))

Expand Down
5 changes: 3 additions & 2 deletions conans/client/remote_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def remove_all_packages(self, ref, remote):
return self._call_remote(remote, "remove_all_packages", ref)

def authenticate(self, remote, name, password):
return self._call_remote(remote, 'authenticate', name, password)
return self._call_remote(remote, 'authenticate', name, password, enforce_disabled=False)

def get_recipe_revisions_references(self, ref, remote):
assert ref.revision is None, "get_recipe_revisions_references of a reference with revision"
Expand Down Expand Up @@ -199,7 +199,8 @@ def get_package_revision_reference(self, pref, remote) -> bool:

def _call_remote(self, remote, method, *args, **kwargs):
assert (isinstance(remote, Remote))
if remote.disabled:
enforce_disabled = kwargs.pop("enforce_disabled", True)
if remote.disabled and enforce_disabled:
raise ConanException("Remote '%s' is disabled" % remote.name)
try:
return self._auth_manager.call_rest_api_method(remote, method, *args, **kwargs)
Expand Down
9 changes: 9 additions & 0 deletions conans/test/integration/remote/auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ def test_no_client_username_checks(self):
self.assertTrue(os.path.exists(self.test_server.server_store.export(ref)))
self.assertIn('Please enter a password for "some_random.special!characters"', client.out)

def test_authorize_disabled_remote(self):
tc = TestClient(servers=self.servers)
# Sanity check, this should not fail
tc.run("remote login default pepe -p pepepass")
tc.run("remote logout default")
# This used to fail when the authentication was not possible for disabled remotes
tc.run("remote disable default")
tc.run("remote login default pepe -p pepepass")
self.assertIn("Changed user of remote 'default' from 'None' (anonymous) to 'pepe' (authenticated)", tc.out)

class AuthenticationTest(unittest.TestCase):

Expand Down