예제 #1
0
파일: test_auth.py 프로젝트: hugovk/twine
def test_get_username_runtime_error_suppressed(
        entered_username, keyring_no_backends_get_credential, recwarn, config):
    assert auth.Resolver(config,
                         auth.CredentialInput()).username == "entered user"
    assert len(recwarn) == 1
    warning = recwarn.pop(UserWarning)
    assert "fail!" in str(warning)
예제 #2
0
파일: test_auth.py 프로젝트: hugovk/twine
def test_get_username_and_password_keyring_overrides_prompt(
        monkeypatch, config, caplog):
    caplog.set_level(logging.INFO, "twine")

    class MockKeyring:
        @staticmethod
        def get_credential(system, user):
            return auth.CredentialInput(
                "real_user",
                "real_user@{system} sekure pa55word".format(**locals()))

        @staticmethod
        def get_password(system, user):
            cred = MockKeyring.get_credential(system, user)
            if user != cred.username:
                raise RuntimeError("unexpected username")
            return cred.password

    monkeypatch.setattr(auth, "keyring", MockKeyring)

    res = auth.Resolver(config, auth.CredentialInput())

    assert res.username == "real_user"
    assert res.password == "real_user@system sekure pa55word"

    assert caplog.messages == [
        "username set from keyring",
        "password set from keyring",
    ]
예제 #3
0
파일: test_auth.py 프로젝트: hugovk/twine
def test_get_password_runtime_error_suppressed(entered_password,
                                               keyring_no_backends, recwarn,
                                               config):
    assert auth.Resolver(config,
                         auth.CredentialInput("user")).password == "entered pw"
    assert len(recwarn) == 1
    warning = recwarn.pop(UserWarning)
    assert "fail!" in str(warning)
예제 #4
0
파일: test_auth.py 프로젝트: hugovk/twine
def test_get_username_return_none(entered_username, monkeypatch, config):
    """Prompt for username when it's not in keyring."""
    class FailKeyring:
        @staticmethod
        def get_credential(system, username):
            return None

    monkeypatch.setattr(auth, "keyring", FailKeyring())
    assert auth.Resolver(config,
                         auth.CredentialInput()).username == "entered user"
예제 #5
0
파일: test_auth.py 프로젝트: hugovk/twine
def test_get_password_keyring_overrides_prompt(monkeypatch, config):
    class MockKeyring:
        @staticmethod
        def get_password(system, user):
            return "{user}@{system} sekure pa55word".format(**locals())

    monkeypatch.setattr(auth, "keyring", MockKeyring)

    pw = auth.Resolver(config, auth.CredentialInput("user")).password
    assert pw == "user@system sekure pa55word"
예제 #6
0
파일: test_auth.py 프로젝트: hugovk/twine
def test_get_password_keyring_defers_to_prompt(monkeypatch, entered_password,
                                               config):
    class MockKeyring:
        @staticmethod
        def get_password(system, user):
            return

    monkeypatch.setattr(auth, "keyring", MockKeyring)

    pw = auth.Resolver(config, auth.CredentialInput("user")).password
    assert pw == "entered pw"
예제 #7
0
파일: test_auth.py 프로젝트: hugovk/twine
def test_logs_cli_values(caplog):
    caplog.set_level(logging.INFO, "twine")

    res = auth.Resolver(config, auth.CredentialInput("username", "password"))

    assert res.username == "username"
    assert res.password == "password"

    assert caplog.messages == [
        "username set by command options",
        "password set by command options",
    ]
예제 #8
0
파일: test_auth.py 프로젝트: hugovk/twine
def test_logs_config_values(config, caplog):
    caplog.set_level(logging.INFO, "twine")

    config.update(username="******", password="******")
    res = auth.Resolver(config, auth.CredentialInput())

    assert res.username == "username"
    assert res.password == "password"

    assert caplog.messages == [
        "username set from config file",
        "password set from config file",
    ]
예제 #9
0
    def __init__(
        self,
        *,
        sign: bool = False,
        sign_with: str = "gpg",
        identity: Optional[str] = None,
        username: Optional[str] = None,
        password: Optional[str] = None,
        non_interactive: bool = False,
        comment: Optional[str] = None,
        config_file: str = "~/.pypirc",
        skip_existing: bool = False,
        cacert: Optional[str] = None,
        client_cert: Optional[str] = None,
        repository_name: str = "pypi",
        repository_url: Optional[str] = None,
        verbose: bool = False,
        disable_progress_bar: bool = False,
        **ignored_kwargs
    ) -> None:
        """Initialize our settings instance.

        :param bool sign:
            Configure whether the package file should be signed.

            This defaults to ``False``.
        :param str sign_with:
            The name of the executable used to sign the package with.

            This defaults to ``gpg``.
        :param str identity:
            The GPG identity that should be used to sign the package file.
        :param str username:
            The username used to authenticate to the repository (package
            index).
        :param str password:
            The password used to authenticate to the repository (package
            index).
        :param bool non_interactive:
            Do not interactively prompt for username/password if the required
            credentials are missing.

            This defaults to ``False``.
        :param str comment:
            The comment to include with each distribution file.
        :param str config_file:
            The path to the configuration file to use.

            This defaults to ``~/.pypirc``.
        :param bool skip_existing:
            Specify whether twine should continue uploading files if one
            of them already exists. This primarily supports PyPI. Other
            package indexes may not be supported.

            This defaults to ``False``.
        :param str cacert:
            The path to the bundle of certificates used to verify the TLS
            connection to the package index.
        :param str client_cert:
            The path to the client certificate used to perform authentication
            to the index.

            This must be a single file that contains both the private key and
            the PEM-encoded certificate.
        :param str repository_name:
            The name of the repository (package index) to interact with. This
            should correspond to a section in the config file.
        :param str repository_url:
            The URL of the repository (package index) to interact with. This
            will override the settings inferred from ``repository_name``.
        :param bool verbose:
            Show verbose output.
        :param bool disable_progress_bar:
            Disable the progress bar.

            This defaults to ``False``
        """
        self.config_file = config_file
        self.comment = comment
        self.verbose = verbose
        self.disable_progress_bar = disable_progress_bar
        self.skip_existing = skip_existing
        self._handle_repository_options(
            repository_name=repository_name, repository_url=repository_url,
        )
        self._handle_package_signing(
            sign=sign, sign_with=sign_with, identity=identity,
        )
        # _handle_certificates relies on the parsed repository config
        self._handle_certificates(cacert, client_cert)
        self.auth = auth.Resolver.choose(not non_interactive)(
            self.repository_config, auth.CredentialInput(username, password),
        )
예제 #10
0
파일: test_auth.py 프로젝트: hugovk/twine
 def get_credential(system, user):
     return auth.CredentialInput(
         "real_user",
         "real_user@{system} sekure pa55word".format(**locals()))
예제 #11
0
파일: test_auth.py 프로젝트: hugovk/twine
def test_no_password_non_interactive_aborts(config):
    with pytest.raises(exceptions.NonInteractive):
        auth.Private(config, auth.CredentialInput("user")).password
예제 #12
0
파일: test_auth.py 프로젝트: hugovk/twine
def test_empty_password_bypasses_prompt(monkeypatch, entered_password, config):
    config.update(password="")
    pw = auth.Resolver(config, auth.CredentialInput("user")).password
    assert pw == ""
예제 #13
0
파일: test_auth.py 프로젝트: hugovk/twine
def test_no_password_defers_to_prompt(monkeypatch, entered_password, config):
    config.update(password=None)
    pw = auth.Resolver(config, auth.CredentialInput("user")).password
    assert pw == "entered pw"
예제 #14
0
파일: test_auth.py 프로젝트: hugovk/twine
def test_get_password_keyring_missing_non_interactive_aborts(
        entered_username, keyring_missing_get_credentials, config):
    with pytest.raises(exceptions.NonInteractive):
        auth.Private(config, auth.CredentialInput("user")).password
예제 #15
0
파일: test_auth.py 프로젝트: hugovk/twine
def test_get_username_keyring_missing_get_credentials_prompts(
        entered_username, keyring_missing_get_credentials, config):
    assert auth.Resolver(config,
                         auth.CredentialInput()).username == "entered user"