| Total Complexity | 3 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Coverage | 60% |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 1 | 1 | from plugin.core.libraries.tests.core.base import BaseTest |
|
| 4 | 1 | class OpenSSL(BaseTest): |
|
| 5 | 1 | name = 'openssl' |
|
| 6 | 1 | optional = True |
|
| 7 | |||
| 8 | 1 | @staticmethod |
|
| 9 | def test_import(): |
||
| 10 | import OpenSSL.SSL |
||
| 11 | |||
| 12 | # Try construct SSL context |
||
| 13 | ctx = OpenSSL.SSL.Context(OpenSSL.SSL.SSLv23_METHOD) |
||
| 14 | |||
| 15 | # Ensure library has SNI support |
||
| 16 | cnx = OpenSSL.SSL.Connection(ctx) |
||
| 17 | |||
| 18 | if not hasattr(cnx, 'set_tlsext_host_name'): |
||
| 19 | raise Exception('Missing SNI extension') |
||
| 20 | |||
| 21 | return { |
||
| 22 | 'versions': { |
||
| 23 | 'pyopenssl': getattr(OpenSSL, '__version__', None) |
||
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 27 | 1 | @classmethod |
|
| 28 | def on_success(cls, metadata): |
||
| 29 | # Inject pyopenssl into requests |
||
| 30 | 1 | from requests.packages.urllib3.contrib.pyopenssl import inject_into_urllib3 |
|
| 31 | 1 | inject_into_urllib3() |
|
| 32 | |||
| 33 | # Enable secure error reporting |
||
| 34 | 1 | from plugin.core.logger.handlers.error_reporter import RAVEN |
|
| 35 | RAVEN.set_protocol('threaded+requests+https') |
||
| 36 |