forked from orbit-oss/flask
cli checks for cryptography library
This commit is contained in:
parent
982663d063
commit
bcde664f9a
3 changed files with 11 additions and 7 deletions
|
|
@ -16,6 +16,8 @@ Unreleased
|
||||||
- :func:`send_file` raises a :exc:`ValueError` when passed an
|
- :func:`send_file` raises a :exc:`ValueError` when passed an
|
||||||
:mod:`io` object in text mode. Previously, it would respond with
|
:mod:`io` object in text mode. Previously, it would respond with
|
||||||
200 OK and an empty file. :issue:`3358`
|
200 OK and an empty file. :issue:`3358`
|
||||||
|
- When using ad-hoc certificates, check for the cryptography library
|
||||||
|
instead of PyOpenSSL. :pr:`3492`
|
||||||
|
|
||||||
|
|
||||||
Version 1.1.2
|
Version 1.1.2
|
||||||
|
|
|
||||||
|
|
@ -713,10 +713,12 @@ class CertParamType(click.ParamType):
|
||||||
|
|
||||||
if value == "adhoc":
|
if value == "adhoc":
|
||||||
try:
|
try:
|
||||||
import OpenSSL # noqa: F401
|
import cryptography # noqa: F401
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise click.BadParameter(
|
raise click.BadParameter(
|
||||||
"Using ad-hoc certificates requires pyOpenSSL.", ctx, param
|
"Using ad-hoc certificates requires the cryptography library.",
|
||||||
|
ctx,
|
||||||
|
param,
|
||||||
)
|
)
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
@ -743,7 +745,7 @@ def _validate_key(ctx, param, value):
|
||||||
if sys.version_info < (2, 7, 9):
|
if sys.version_info < (2, 7, 9):
|
||||||
is_context = cert and not isinstance(cert, (text_type, bytes))
|
is_context = cert and not isinstance(cert, (text_type, bytes))
|
||||||
else:
|
else:
|
||||||
is_context = isinstance(cert, ssl.SSLContext)
|
is_context = ssl and isinstance(cert, ssl.SSLContext)
|
||||||
|
|
||||||
if value is not None:
|
if value is not None:
|
||||||
if is_adhoc:
|
if is_adhoc:
|
||||||
|
|
|
||||||
|
|
@ -566,14 +566,14 @@ def test_run_cert_path():
|
||||||
|
|
||||||
|
|
||||||
def test_run_cert_adhoc(monkeypatch):
|
def test_run_cert_adhoc(monkeypatch):
|
||||||
monkeypatch.setitem(sys.modules, "OpenSSL", None)
|
monkeypatch.setitem(sys.modules, "cryptography", None)
|
||||||
|
|
||||||
# pyOpenSSL not installed
|
# cryptography not installed
|
||||||
with pytest.raises(click.BadParameter):
|
with pytest.raises(click.BadParameter):
|
||||||
run_command.make_context("run", ["--cert", "adhoc"])
|
run_command.make_context("run", ["--cert", "adhoc"])
|
||||||
|
|
||||||
# pyOpenSSL installed
|
# cryptography installed
|
||||||
monkeypatch.setitem(sys.modules, "OpenSSL", types.ModuleType("OpenSSL"))
|
monkeypatch.setitem(sys.modules, "cryptography", types.ModuleType("cryptography"))
|
||||||
ctx = run_command.make_context("run", ["--cert", "adhoc"])
|
ctx = run_command.make_context("run", ["--cert", "adhoc"])
|
||||||
assert ctx.params["cert"] == "adhoc"
|
assert ctx.params["cert"] == "adhoc"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue