Commit 09c18da4 by Sébastien Eustace

Add support for empty passwords when publishing

parent ea420b83
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
- The `install` command will now install the current project in editable mode. - The `install` command will now install the current project in editable mode.
- The `develop` command is now deprecated in favor of `install`. - The `develop` command is now deprecated in favor of `install`.
- Improved the `check` command. - Improved the `check` command.
- Empty passwords are now supported when publishing.
### Fixed ### Fixed
......
...@@ -65,7 +65,7 @@ class Publisher: ...@@ -65,7 +65,7 @@ class Publisher:
url = config["repositories"][repository_name]["url"] url = config["repositories"][repository_name]["url"]
if not (username and password): if not (username and password):
auth = get_http_basic_auth(repository_name) auth = get_http_basic_auth(self._poetry.auth_config, repository_name)
if auth: if auth:
username = auth[0] username = auth[0]
password = auth[1] password = auth[1]
...@@ -74,7 +74,7 @@ class Publisher: ...@@ -74,7 +74,7 @@ class Publisher:
if not username: if not username:
username = self._io.ask("Username:") username = self._io.ask("Username:")
if not password: if password is None:
password = self._io.ask_hidden("Password:") password = self._io.ask_hidden("Password:")
# TODO: handle certificates # TODO: handle certificates
......
...@@ -37,6 +37,7 @@ class Poetry: ...@@ -37,6 +37,7 @@ class Poetry:
self._local_config = local_config self._local_config = local_config
self._locker = locker self._locker = locker
self._config = Config.create("config.toml") self._config = Config.create("config.toml")
self._auth_config = Config.create("auth.toml")
# Configure sources # Configure sources
self._pool = Pool() self._pool = Pool()
...@@ -66,6 +67,14 @@ class Poetry: ...@@ -66,6 +67,14 @@ class Poetry:
def pool(self): # type: () -> Pool def pool(self): # type: () -> Pool
return self._pool return self._pool
@property
def config(self): # type: () -> Config
return self._config
@property
def auth_config(self): # type: () -> Config
return self._auth_config
@classmethod @classmethod
def create(cls, cwd): # type: (Path) -> Poetry def create(cls, cwd): # type: (Path) -> Poetry
candidates = [Path(cwd)] candidates = [Path(cwd)]
......
...@@ -171,7 +171,9 @@ class LegacyRepository(PyPiRepository): ...@@ -171,7 +171,9 @@ class LegacyRepository(PyPiRepository):
url_parts = urlparse.urlparse(self._url) url_parts = urlparse.urlparse(self._url)
if not url_parts.username: if not url_parts.username:
self._session.auth = get_http_basic_auth(self.name) self._session.auth = get_http_basic_auth(
Config.create("auth.toml"), self.name
)
self._disable_cache = disable_cache self._disable_cache = disable_cache
......
...@@ -3,6 +3,7 @@ import shutil ...@@ -3,6 +3,7 @@ import shutil
import tempfile import tempfile
from contextlib import contextmanager from contextlib import contextmanager
from typing import Optional
from typing import Union from typing import Union
from poetry.config import Config from poetry.config import Config
...@@ -80,14 +81,11 @@ def parse_requires(requires): # type: (str) -> Union[list, None] ...@@ -80,14 +81,11 @@ def parse_requires(requires): # type: (str) -> Union[list, None]
return requires_dist return requires_dist
def get_http_basic_auth(repository_name): # type: (str) -> tuple def get_http_basic_auth(
config = Config.create("auth.toml") config, repository_name
): # type: (Config, str) -> Optional[tuple]
repo_auth = config.setting("http-basic.{}".format(repository_name)) repo_auth = config.setting("http-basic.{}".format(repository_name))
if repo_auth: if repo_auth:
return repo_auth["username"], repo_auth["password"] return repo_auth["username"], repo_auth.get("password")
return None
def constraint_to_marker(constraint): # type: (Any) -> Marker return None
if constraint.is_any():
return AnyMarker()
import pytest
import tempfile
from poetry.config import Config
from poetry.utils.toml_file import TomlFile
@pytest.fixture
def config(): # type: () -> Config
with tempfile.NamedTemporaryFile() as f:
f.close()
return Config(TomlFile(f.name))
...@@ -42,16 +42,6 @@ def test_page_absolute_links_path_are_correct(): ...@@ -42,16 +42,6 @@ def test_page_absolute_links_path_are_correct():
assert link.path.startswith("/packages/") assert link.path.startswith("/packages/")
def test_http_basic_auth_repo(mocker):
mock = mocker.patch("poetry.repositories.legacy_repository.get_http_basic_auth")
mock.return_value = ("user1", "p4ss")
repo = MockRepository()
mock.assert_called_once_with("legacy")
assert repo._session.auth == ("user1", "p4ss")
def test_sdist_format_support(): def test_sdist_format_support():
repo = MockRepository() repo = MockRepository()
page = repo._get("/relative") page = repo._get("/relative")
......
import os import os
import pytest import pytest
import sys import sys
import tempfile
from poetry.config import Config
from poetry.utils.toml_file import TomlFile
@pytest.fixture
def config():
with tempfile.NamedTemporaryFile() as f:
f.close()
return Config(TomlFile(f.name))
@pytest.mark.skipif( @pytest.mark.skipif(
......
from poetry.utils.helpers import get_http_basic_auth
from poetry.utils.helpers import parse_requires from poetry.utils.helpers import parse_requires
...@@ -48,3 +49,20 @@ zipfile36>=0.1.0.0,<0.2.0.0 ...@@ -48,3 +49,20 @@ zipfile36>=0.1.0.0,<0.2.0.0
'zipfile36>=0.1.0.0,<0.2.0.0; python_version >= "3.4.0.0" and python_version < "3.6.0.0"', 'zipfile36>=0.1.0.0,<0.2.0.0; python_version >= "3.4.0.0" and python_version < "3.6.0.0"',
] ]
assert result == expected assert result == expected
def test_get_http_basic_auth(config):
config.add_property("http-basic.foo.username", "foo")
config.add_property("http-basic.foo.password", "bar")
assert get_http_basic_auth(config, "foo") == ("foo", "bar")
def test_get_http_basic_auth_without_password(config):
config.add_property("http-basic.foo.username", "foo")
assert get_http_basic_auth(config, "foo") == ("foo", None)
def test_get_http_basic_auth_missing(config):
assert get_http_basic_auth(config, "foo") is None
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment