Total Complexity | 5 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Coverage | 47.62% |
Changes | 5 | ||
Bugs | 0 | Features | 0 |
1 | 1 | from plugin.core.libraries.tests.core.base import BaseTest |
|
8 | 1 | class OpenSSL(BaseTest): |
|
9 | 1 | name = 'openssl' |
|
10 | 1 | optional = True |
|
11 | |||
12 | 1 | @staticmethod |
|
13 | def test_import(): |
||
14 | import OpenSSL.SSL |
||
15 | |||
16 | # Try construct SSL context |
||
17 | ctx = OpenSSL.SSL.Context(OpenSSL.SSL.SSLv23_METHOD) |
||
18 | |||
19 | # Ensure library has SNI support |
||
20 | cnx = OpenSSL.SSL.Connection(ctx) |
||
21 | |||
22 | if not hasattr(cnx, 'set_tlsext_host_name'): |
||
23 | raise Exception('Missing SNI extension') |
||
24 | |||
25 | # Ensure binding can be imported |
||
26 | from cryptography.hazmat.bindings.openssl.binding import Binding |
||
27 | assert Binding |
||
28 | |||
29 | return { |
||
30 | 'versions': { |
||
31 | 'pyopenssl': getattr(OpenSSL, '__version__', None) |
||
32 | } |
||
33 | } |
||
34 | |||
35 | 1 | @classmethod |
|
36 | def on_success(cls, metadata): |
||
37 | # Inject pyOpenSSL into requests |
||
38 | 1 | try: |
|
39 | 1 | from requests.packages.urllib3.contrib.pyopenssl import inject_into_urllib3 |
|
40 | 1 | inject_into_urllib3() |
|
41 | except Exception, ex: |
||
42 | log.warn('Unable to inject pyOpenSSL into urllib3 - %s', ex, exc_info=True) |
||
43 | return |
||
44 | |||
45 | # Enable secure error reporting |
||
46 | 1 | from plugin.core.logger.handlers.error_reporter import RAVEN |
|
47 | RAVEN.set_protocol('threaded+requests+https') |
||
48 |