コード例 #1
0
def test_get_pypi_token(config: Config, with_simple_keyring: None,
                        dummy_keyring: DummyBackend):
    dummy_keyring.set_password("poetry-repository-foo", "__token__", "baz")
    manager = PasswordManager(config)

    assert manager.keyring.is_available()
    assert manager.get_pypi_token("foo") == "baz"
コード例 #2
0
def test_delete_http_password(config: Config, with_simple_keyring: None,
                              dummy_keyring: DummyBackend):
    dummy_keyring.set_password("poetry-repository-foo", "bar", "baz")
    config.auth_config_source.add_property("http-basic.foo",
                                           {"username": "******"})
    manager = PasswordManager(config)

    assert manager.keyring.is_available()
    manager.delete_http_password("foo")

    assert dummy_keyring.get_password("poetry-repository-foo", "bar") is None
    assert config.get("http-basic.foo") is None
コード例 #3
0
def test_get_http_auth(config: Config, with_simple_keyring: None,
                       dummy_keyring: DummyBackend):
    dummy_keyring.set_password("poetry-repository-foo", "bar", "baz")
    config.auth_config_source.add_property("http-basic.foo",
                                           {"username": "******"})
    manager = PasswordManager(config)

    assert manager.keyring.is_available()
    auth = manager.get_http_auth("foo")

    assert auth["username"] == "bar"
    assert auth["password"] == "baz"
コード例 #4
0
def test_authenticator_falls_back_to_keyring_netloc(
    config: Config,
    mock_remote: None,
    repo: dict[str, dict[str, str]],
    http: type[httpretty.httpretty],
    with_simple_keyring: None,
    dummy_keyring: DummyBackend,
):
    config.merge({
        "repositories": repo,
    })

    dummy_keyring.set_password("foo.bar", None, SimpleCredential(None, "bar"))

    authenticator = Authenticator(config, NullIO())
    authenticator.request("get", "https://foo.bar/files/foo-0.1.0.tar.gz")

    request = http.last_request()

    assert request.headers["Authorization"] == "Basic OmJhcg=="
コード例 #5
0
def test_set_http_password(config: Config, with_simple_keyring: None,
                           dummy_keyring: DummyBackend):
    manager = PasswordManager(config)

    assert manager.keyring.is_available()
    manager.set_http_password("foo", "bar", "baz")

    assert dummy_keyring.get_password("poetry-repository-foo", "bar") == "baz"

    auth = config.get("http-basic.foo")
    assert auth["username"] == "bar"
    assert "password" not in auth
コード例 #6
0
def test_authenticator_falls_back_to_keyring_url_matched_by_path(
    config: Config,
    mock_remote: None,
    http: type[httpretty.httpretty],
    with_simple_keyring: None,
    dummy_keyring: DummyBackend,
):
    config.merge({
        "repositories": {
            "foo-alpha": {
                "url": "https://foo.bar/alpha/files/simple/"
            },
            "foo-beta": {
                "url": "https://foo.bar/beta/files/simple/"
            },
        }
    })

    dummy_keyring.set_password("https://foo.bar/alpha/files/simple/", None,
                               SimpleCredential(None, "bar"))
    dummy_keyring.set_password("https://foo.bar/beta/files/simple/", None,
                               SimpleCredential(None, "baz"))

    authenticator = Authenticator(config, NullIO())

    authenticator.request(
        "get", "https://foo.bar/alpha/files/simple/foo-0.1.0.tar.gz")
    request = http.last_request()

    basic_auth = base64.b64encode(b":bar").decode()
    assert request.headers["Authorization"] == f"Basic {basic_auth}"

    authenticator.request(
        "get", "https://foo.bar/beta/files/simple/foo-0.1.0.tar.gz")
    request = http.last_request()

    basic_auth = base64.b64encode(b":baz").decode()
    assert request.headers["Authorization"] == f"Basic {basic_auth}"