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

Fix client cert password bug #678

Merged
merged 3 commits into from Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -28,3 +28,4 @@ Brian Rutledge <bhrutledge@gmail.com>
Peter Stensmyr <peter.stensmyr@gmail.com> (http://www.peterstensmyr.com)
Felipe Mulinari Rocha Campos <felipecampos@google.com>
Devesh Kumar Singh <deveshkusingh@gmail.com>
Yesha Maggi <yesha.maggic@gmail.com>
28 changes: 18 additions & 10 deletions tests/test_settings.py
Expand Up @@ -74,31 +74,39 @@ def test_identity_requires_sign():
settings.Settings(sign=False, identity="fakeid")


def test_password_not_required_if_client_cert(entered_password):
"""Don't set password when only client_cert is provided."""
test_client_cert = "/random/path"
settings_obj = settings.Settings(username="fakeuser", client_cert=test_client_cert)
assert not settings_obj.password
assert settings_obj.client_cert == test_client_cert


@pytest.mark.parametrize("client_cert", [None, ""])
def test_password_is_required_if_no_client_cert(client_cert, entered_password):
"""Set password when client_cert is not provided."""
settings_obj = settings.Settings(username="fakeuser", client_cert=client_cert)
assert settings_obj.password == "entered pw"


def test_client_cert_is_set_and_password_not_if_both_given(entered_password):
def test_client_cert_and_password_both_set_if_given():
"""Set password and client_cert when both are provided."""
client_cert = "/random/path"
settings_obj = settings.Settings(
username="fakeuser", password="anything", client_cert=client_cert
)
assert not settings_obj.password
assert settings_obj.password == "anything"
assert settings_obj.client_cert == client_cert


def test_password_required_if_no_client_cert_and_non_interactive():
"""Raise exception if no password or client_cert when non interactive."""
settings_obj = settings.Settings(username="fakeuser", non_interactive=True)
with pytest.raises(exceptions.NonInteractive):
settings_obj.password


def test_no_password_prompt_if_client_cert_and_non_interactive(entered_password):
"""Don't prompt for password when client_cert is provided and non interactive."""
client_cert = "/random/path"
settings_obj = settings.Settings(
username="fakeuser", client_cert=client_cert, non_interactive=True
)
assert not settings_obj.password


class TestArgumentParsing:
@staticmethod
def parse_args(args):
Expand Down
5 changes: 4 additions & 1 deletion twine/settings.py
Expand Up @@ -145,7 +145,10 @@ def username(self) -> Optional[str]:
@property
def password(self) -> Optional[str]:
if self.client_cert:
return None
try:
jaraco marked this conversation as resolved.
Show resolved Hide resolved
return cast(Optional[str], self.auth.password)
except exceptions.NonInteractive:
return None

# Workaround for https://github.com/python/mypy/issues/5858
return cast(Optional[str], self.auth.password)
Expand Down