Skip to content

Commit 7157722

Browse files
fix: Safely catch legacy flags on interactive login for other cmds (#828)
* safely catch legacy flags on interactive login for other cmds * skip the test --------- Co-authored-by: Matt Kramer <mkramer@anaconda.com>
1 parent dbb448b commit 7157722

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

binstar_client/commands/login.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def interactive_get_token(args, fail_if_already_exists=True):
102102

103103
api_client.check_server()
104104

105-
has_legacy_flags = getattr(args, "login_username") or getattr(args, "login_password")
105+
has_legacy_flags = getattr(args, "login_username", None) or getattr(args, "login_password", None)
106106

107107
if not (LEGACY_INTERACTIVE_LOGIN or has_legacy_flags):
108108
# If the user already has a token, prompt them if they want to login again.

tests/test_login.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
"""Tests for authentication commands."""
44

5+
import json
56
import unittest.mock
67

8+
from binstar_client import errors
9+
710
from tests.fixture import CLITestCase, main
811
from tests.urlmock import urlpatch
12+
from tests.utils.utils import data_dir
913

1014

1115
class Test(CLITestCase):
@@ -111,3 +115,33 @@ def test_legacy_login_user_pass_flags(self, urls, store_token, _do_auth_flow):
111115

112116
self.assertTrue(store_token.called)
113117
self.assertEqual(store_token.call_args[0][0], 'a-token')
118+
119+
@unittest.mock.patch('binstar_client.commands.login.bool_input')
120+
@unittest.mock.patch('binstar_client.commands.login._do_auth_flow')
121+
@urlpatch
122+
@unittest.skip("Cannot accurately test this scenario")
123+
def test_login_required_args(self, urls, _do_auth_flow, bool_input):
124+
org_data = {
125+
"company": "foo",
126+
"created_at": "2015-11-19 18:22:23.061000+00:00",
127+
"description": "",
128+
"location": "here",
129+
"login": "org-name",
130+
"name": "Me",
131+
"url": "",
132+
"user_type": "org",
133+
}
134+
135+
urls.register(method='HEAD', path='/', status=200)
136+
urls.register(method='GET', path='/user/org-name', content=json.dumps(org_data))
137+
urls.register(method="GET", path="/dist/org-name/foo/0.1/osx-64/foo-0.1-0.tar.bz2", status=401, content={})
138+
139+
# We just need make sure we get past the legacy_flag determination
140+
# We don't need to finish login or upload
141+
bool_input.return_value = False
142+
143+
with self.assertRaises(SystemExit):
144+
main(['--show-traceback', 'upload', "-u", "org-name", data_dir('foo-0.1-0.tar.bz2')])
145+
146+
self.assertIn("\"org-name\" as upload username", self.stream.getvalue())
147+
self.assertIn("The action you are performing requires authentication", self.stream.getvalue())

0 commit comments

Comments
 (0)