Skip to content

Commit

Permalink
Enable authentication against a disabled remote (#12913)
Browse files Browse the repository at this point in the history
* Make deactivate_conanx a function instead of an extra file

* Make remote authenticate stop checking for remote.disabled

* Revert change from different PR

* Add even more missing parts

* Adds test and makes api nicer
  • Loading branch information
AbrilRBS authored Jan 18, 2023
1 parent 5147e99 commit 9038cae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
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)
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

0 comments on commit 9038cae

Please sign in to comment.