Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an informative __main__.py #620

Merged
merged 9 commits into from
May 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Deprecations:
Changes:
^^^^^^^^

*none*
- Added ``OpenSSL.debug`` that allows to get an overview of used library versions (including linked OpenSSL) and other useful runtime information using ``python -m OpenSSL.debug``.
`#620 <https://github.com/pyca/pyopenssl/pull/620>`_


----
Expand Down
3 changes: 2 additions & 1 deletion INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ Currently that means:
- 1.0.2
- 1.1.0


If you need support for older releases, the following pinned versions will work:

- **OpenSSL 0.9.8**: ``'pyOpenSSL<17.0' 'cryptography<1.4'``
- **OpenSSL 1.0.0**: ``'pyOpenSSL<17.1' 'cryptography<1.7'``

You can always find out the versions of pyOpenSSL, cryptography, and the linked OpenSSL by running ``python -m OpenSSL.debug``.


Documentation
-------------
Expand Down
42 changes: 42 additions & 0 deletions src/OpenSSL/debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from __future__ import print_function

import ssl
import sys

import OpenSSL.SSL
import cffi
import cryptography

from . import version


_env_info = u"""\
pyOpenSSL: {pyopenssl}
cryptography: {cryptography}
cffi: {cffi}
cryptography's compiled against OpenSSL: {crypto_openssl_compile}
cryptography's linked OpenSSL: {crypto_openssl_link}
Pythons's OpenSSL: {python_openssl}
Python executable: {python}
Python version: {python_version}
Platform: {platform}
sys.path: {sys_path}""".format(
pyopenssl=version.__version__,
crypto_openssl_compile=OpenSSL._util.ffi.string(
OpenSSL._util.lib.OPENSSL_VERSION_TEXT,
).decode("ascii"),
crypto_openssl_link=OpenSSL.SSL.SSLeay_version(
OpenSSL.SSL.SSLEAY_VERSION
).decode("ascii"),
python_openssl=getattr(ssl, "OPENSSL_VERSION", "n/a"),
cryptography=cryptography.__version__,
cffi=cffi.__version__,
python=sys.executable,
python_version=sys.version,
platform=sys.platform,
sys_path=sys.path,
)


if __name__ == "__main__":
print(_env_info)
10 changes: 10 additions & 0 deletions tests/test_debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from OpenSSL.debug import _env_info
from OpenSSL import version


def test_debug_info():
"""
Debug info contains correct data.
"""
# Just check a sample we control.
assert version.__version__ in _env_info
6 changes: 3 additions & 3 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from OpenSSL._util import exception_from_error_queue, lib

import pytest

from OpenSSL._util import exception_from_error_queue, lib


class TestErrors(object):
"""
Tests for handling of certain OpenSSL error cases.
"""
def test_exception_from_error_queue_nonexistent_reason(self):
"""
:py:func:`exception_from_error_queue` raises ``ValueError`` when it
:func:`exception_from_error_queue` raises ``ValueError`` when it
encounters an OpenSSL error code which does not have a reason string.
"""
lib.ERR_put_error(lib.ERR_LIB_EVP, 0, 1112, b"", 10)
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ setenv =
PIP_NO_BINARY=cryptography
commands =
openssl version
coverage run --parallel -m OpenSSL.debug
coverage run --parallel -m pytest -v {posargs}

[testenv:py27-twistedMaster]
Expand Down