diff options
author | Pradyun Gedam <pradyunsg@gmail.com> | 2023-01-29 01:36:20 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-29 01:36:20 +0000 |
commit | efedf09c4967dcbe3105e3746aaca7bfb55d605f (patch) | |
tree | 5a67befba67db4028b7a6071148595d7bb04c3f4 | |
parent | 60a45984404460192067f3990e0258deeeafa636 (diff) | |
parent | 17e20c746e6b855f6bb4a28bbbfff66706762240 (diff) | |
download | pip-efedf09c4967dcbe3105e3746aaca7bfb55d605f.tar.gz |
Merge pull request #11759 from pradyunsg/fix-keyring-auth
Closes https://github.com/pypa/pip/issues/11658
-rw-r--r-- | src/pip/_internal/network/auth.py | 4 | ||||
-rw-r--r-- | tests/unit/test_network_auth.py | 5 |
2 files changed, 5 insertions, 4 deletions
diff --git a/src/pip/_internal/network/auth.py b/src/pip/_internal/network/auth.py index 68b5a5f45..c16213268 100644 --- a/src/pip/_internal/network/auth.py +++ b/src/pip/_internal/network/auth.py @@ -128,7 +128,7 @@ class KeyRingCliProvider(KeyRingBaseProvider): ) if res.returncode: return None - return res.stdout.decode("utf-8").strip("\n") + return res.stdout.decode("utf-8").strip(os.linesep) def _set_password(self, service_name: str, username: str, password: str) -> None: """Mirror the implementation of keyring.set_password using cli""" @@ -136,7 +136,7 @@ class KeyRingCliProvider(KeyRingBaseProvider): return None cmd = [self.keyring, "set", service_name, username] - input_ = password.encode("utf-8") + b"\n" + input_ = (password + os.linesep).encode("utf-8") env = os.environ.copy() env["PYTHONIOENCODING"] = "utf-8" res = subprocess.run(cmd, input=input_, env=env) diff --git a/tests/unit/test_network_auth.py b/tests/unit/test_network_auth.py index 625a20a48..5e9e325a1 100644 --- a/tests/unit/test_network_auth.py +++ b/tests/unit/test_network_auth.py @@ -1,4 +1,5 @@ import functools +import os import sys from typing import Any, Dict, Iterable, List, Optional, Tuple @@ -360,7 +361,7 @@ class KeyringSubprocessResult(KeyringModuleV1): self.returncode = 1 else: # Passwords are returned encoded with a newline appended - self.stdout = password.encode("utf-8") + b"\n" + self.stdout = (password + os.linesep).encode("utf-8") if cmd[1] == "set": assert stdin is None @@ -369,7 +370,7 @@ class KeyringSubprocessResult(KeyringModuleV1): assert input is not None # Input from stdin is encoded - self.set_password(cmd[2], cmd[3], input.decode("utf-8").strip("\n")) + self.set_password(cmd[2], cmd[3], input.decode("utf-8").strip(os.linesep)) return self |