Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Merge pull request #13 from scrapinghub/fix-auth-with-username-only
Browse files Browse the repository at this point in the history
Fix push when only --username is specified.
  • Loading branch information
vshlapakov committed Aug 1, 2016
2 parents b7d1b2f + eb6ea11 commit 14d9c88
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions shub_image/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def _execute_push_login(client, image, username, password, email):
"""Login if there're provided credentials for the registry"""
components = image.split('/')
registry = components[0] if len(components) == 3 else None
if password is None:
# Missing password leads to auth request to registry authentication service
# without 'account' query parameter which breaks login procedure.
password = ' '
resp = client.login(username=username, password=password,
email=email, registry=registry, reauth=False)
if not (isinstance(resp, dict) and 'username' in resp or
Expand Down
20 changes: 20 additions & 0 deletions tests/test_push.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ def test_cli_with_login(self, mocked_method):
'registry/user/project:test',
insecure_registry=False, stream=True)

def test_cli_with_login_username_only(self, mocked_method):
mocked = mock.MagicMock()
mocked.login.return_value = {"Status": "Login Succeeded"}
mocked.push.return_value = [
'{"stream":"In process"}',
'{"status":"Successfully pushed"}']
mocked_method.return_value = mocked
with FakeProjectDirectory() as tmpdir:
add_sh_fake_config(tmpdir)
runner = CliRunner()
result = runner.invoke(
cli, ["dev", "--version", "test", "--username", "apikey"])
assert result.exit_code == 0
mocked.login.assert_called_with(
email=None, password=' ',
reauth=False, registry='registry', username='apikey')
mocked.push.assert_called_with(
'registry/user/project:test',
insecure_registry=False, stream=True)

def test_cli_login_fail(self, mocked_method):
mocked = mock.MagicMock()
mocked.login.return_value = {"Status": "Login Failed!"}
Expand Down

0 comments on commit 14d9c88

Please sign in to comment.