Passed
Push — master ( ce647f...f4ead8 )
by Dean
02:57
created

OpenSSL   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 47.62%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 5
c 5
b 0
f 0
dl 0
loc 40
ccs 10
cts 21
cp 0.4762
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_import() 0 20 3
A on_success() 0 13 2
1 1
from plugin.core.libraries.tests.core.base import BaseTest
2
3 1
import logging
4
5 1
log = logging.getLogger(__name__)
6
7
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