-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11082 from uranusjr/truststore
- Loading branch information
Showing
5 changed files
with
180 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Add support to use `truststore <https://pypi.org/project/truststore/>`_ as an alternative SSL certificate verification backend. The backend can be enabled on Python 3.10 and later by installing ``truststore`` into the environment, and adding the ``--use-feature=truststore`` flag to various pip commands. | ||
|
||
``truststore`` differs from the current default verification backend (provided by ``certifi``) in it uses the operating system’s trust store, which can be better controlled and augmented to better support non-standard certificates. Depending on feedback, pip may switch to this as the default certificate verification backend in the future. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import sys | ||
from typing import Any, Callable | ||
|
||
import pytest | ||
|
||
from tests.lib import PipTestEnvironment, TestPipResult | ||
|
||
PipRunner = Callable[..., TestPipResult] | ||
|
||
|
||
@pytest.fixture() | ||
def pip(script: PipTestEnvironment) -> PipRunner: | ||
def pip(*args: str, **kwargs: Any) -> TestPipResult: | ||
return script.pip(*args, "--use-feature=truststore", **kwargs) | ||
|
||
return pip | ||
|
||
|
||
@pytest.mark.skipif(sys.version_info >= (3, 10), reason="3.10 can run truststore") | ||
def test_truststore_error_on_old_python(pip: PipRunner) -> None: | ||
result = pip( | ||
"install", | ||
"--no-index", | ||
"does-not-matter", | ||
expect_error=True, | ||
) | ||
assert "The truststore feature is only available for Python 3.10+" in result.stderr | ||
|
||
|
||
@pytest.mark.skipif(sys.version_info < (3, 10), reason="3.10+ required for truststore") | ||
def test_truststore_error_without_preinstalled(pip: PipRunner) -> None: | ||
result = pip( | ||
"install", | ||
"--no-index", | ||
"does-not-matter", | ||
expect_error=True, | ||
) | ||
assert ( | ||
"To use the truststore feature, 'truststore' must be installed into " | ||
"pip's current environment." | ||
) in result.stderr | ||
|
||
|
||
@pytest.mark.skipif(sys.version_info < (3, 10), reason="3.10+ required for truststore") | ||
@pytest.mark.network | ||
@pytest.mark.parametrize( | ||
"package", | ||
[ | ||
"INITools", | ||
"https://github.com/pypa/pip-test-package/archive/refs/heads/master.zip", | ||
], | ||
ids=["PyPI", "GitHub"], | ||
) | ||
def test_trustore_can_install( | ||
script: PipTestEnvironment, | ||
pip: PipRunner, | ||
package: str, | ||
) -> None: | ||
script.pip("install", "truststore") | ||
result = pip("install", package) | ||
assert "Successfully installed" in result.stdout |