Skip to content
Myr

Merge pull request #3492 from pallets/cryptography

Before adoption: this commit came in with the history the project adopted, so no landing records it.

CLI checks for cryptography library

authored by David Lord · committed by GitHub · parents 982663d, bcde664 · Browse files · 3 files+11 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+11 added−7 removed

  • tests:+4 added−4 removed
  • other:+7 added−3 removed

3 files+11 added−7 removed

modified:src/flask/cli.py+5 added-3 removed
711 unmodified lines
712 value = click.STRING(value, param, ctx).lower()713714 if value == "adhoc":715 try:716 import OpenSSL # noqa: F401716 import cryptography # noqa: F401717 except ImportError:718 raise click.BadParameter(719 "Using ad-hoc certificates requires pyOpenSSL.", ctx, param719 "Using ad-hoc certificates requires the cryptography library.",720 ctx,721 param,722 )723724 return value725
18 unmodified lines
744745 if sys.version_info < (2, 7, 9):746 is_context = cert and not isinstance(cert, (text_type, bytes))747 else:746 is_context = isinstance(cert, ssl.SSLContext)748 is_context = ssl and isinstance(cert, ssl.SSLContext)749750 if value is not None:751 if is_adhoc:752 raise click.BadParameter(
222 unmodified lines
modified:tests/test_cli.py+4 added-4 removed
564 unmodified lines
565 assert ctx.params["cert"] == (__file__, __file__)566567568def test_run_cert_adhoc(monkeypatch):569 monkeypatch.setitem(sys.modules, "OpenSSL", None)569 monkeypatch.setitem(sys.modules, "cryptography", None)570571 # pyOpenSSL not installed571 # cryptography not installed572 with pytest.raises(click.BadParameter):573 run_command.make_context("run", ["--cert", "adhoc"])574575 # pyOpenSSL installed576 monkeypatch.setitem(sys.modules, "OpenSSL", types.ModuleType("OpenSSL"))575 # cryptography installed576 monkeypatch.setitem(sys.modules, "cryptography", types.ModuleType("cryptography"))577 ctx = run_command.make_context("run", ["--cert", "adhoc"])578 assert ctx.params["cert"] == "adhoc"579580 # no key with adhoc
87 unmodified lines
modified:CHANGES.rst+2 added
14 unmodified lines
15 the traceback immediately. :issue:`3431`16- :func:`send_file` raises a :exc:`ValueError` when passed an17 :mod:`io` object in text mode. Previously, it would respond with18 200 OK and an empty file. :issue:`3358`19- When using ad-hoc certificates, check for the cryptography library20 instead of PyOpenSSL. :pr:`3492`212223Version 1.1.224-------------
1012 unmodified lines