diff --git a/.python-version b/.python-version deleted file mode 100644 index d5c0c99..0000000 --- a/.python-version +++ /dev/null @@ -1 +0,0 @@ -3.5.1 diff --git a/.travis.yml b/.travis.yml index 4132f59..25af184 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ sudo: false language: python -python: - - 2.7 - - 3.4 - - 3.5 + +env: + - PYTHON_VERSION=2.7.11 + - PYTHON_VERSION=3.4.4 + - PYTHON_VERSION=3.5.1 addons: apt: @@ -17,25 +18,17 @@ addons: cache: pip: true directories: - - env + - $HOME/env + - $HOME/.pyenv install: - - pip install coveralls - -before_script: - - openssl version -a - - python -c 'import ssl; print(ssl.OPENSSL_VERSION)' - - python -c 'import ssl; print(ssl.HAS_NPN)' - - python -c 'import ssl; print(ssl.HAS_ALPN)' - - make depends - - python -c 'from OpenSSL import SSL; print(SSL.SSLeay_version(SSL.SSLEAY_VERSION))' + - ./.travis/install.sh script: - - make test - - make flake8 + - ./.travis/run.sh after_success: - - coveralls + - ./.travis/after.sh notifications: email: diff --git a/.travis/after.sh b/.travis/after.sh new file mode 100755 index 0000000..a69d9e1 --- /dev/null +++ b/.travis/after.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +PYENV_ROOT="$HOME/.pyenv" +PATH="$PYENV_ROOT/bin:$PATH" +eval "$(pyenv init -)" +pyenv local $PYTHON_VERSION +pyenv global $PYTHON_VERSION + +ENV=$HOME/env +source $ENV/bin/activate + +coveralls diff --git a/.travis/install.sh b/.travis/install.sh new file mode 100755 index 0000000..86a44f4 --- /dev/null +++ b/.travis/install.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -ex + +PYENV_ROOT="$HOME/.pyenv" +git clone https://github.com/yyuu/pyenv.git $PYENV_ROOT +PATH="$PYENV_ROOT/bin:$PATH" +eval "$(pyenv init -)" +pyenv install $PYTHON_VERSION -s +pyenv local $PYTHON_VERSION +pyenv global $PYTHON_VERSION +pyenv rehash +which python +python --version +pip install --upgrade pip virtualenv + +ENV=$HOME/env +virtualenv $ENV +source $ENV/bin/activate +echo $VIRTUAL_ENV +python --version + +pip install coveralls + +openssl version -a +python -c 'import ssl; print(ssl.OPENSSL_VERSION)' +python -c 'import ssl; print(ssl.HAS_NPN)' +python -c 'import ssl; print(ssl.HAS_ALPN)' +make depends +python -c 'from OpenSSL import SSL; print(SSL.SSLeay_version(SSL.SSLEAY_VERSION))' diff --git a/.travis/run.sh b/.travis/run.sh new file mode 100755 index 0000000..6170f29 --- /dev/null +++ b/.travis/run.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +PYENV_ROOT="$HOME/.pyenv" +PATH="$PYENV_ROOT/bin:$PATH" +eval "$(pyenv init -)" + +ENV=$HOME/env +source $ENV/bin/activate + +make test +make flake8 diff --git a/apns/ssl_context/stdlib.py b/apns/ssl_context/stdlib.py index 6189ed1..6fdafd9 100644 --- a/apns/ssl_context/stdlib.py +++ b/apns/ssl_context/stdlib.py @@ -9,9 +9,9 @@ from hyper.tls import H2_NPN_PROTOCOLS -assert ssl.OPENSSL_VERSION_INFO[:3] >= (1, 0, 1), 'TLSv1.2 is required and ' \ - 'is not supported by the version of OpenSSL that Python was compiled ' \ - 'against' +assert hasattr(ssl, 'HAS_ALPN'), 'Your version of Python does not support ' \ + 'ALPN, or was compiled against a version of OpenSSL that does not ' \ + 'support it.' assert hasattr(ssl, 'PROTOCOL_TLSv1_2'), 'TLSv1.2 is required and is not ' \ 'supported by your version of Python' diff --git a/tests/test_stdlib_ssl_context.py b/tests/test_stdlib_ssl_context.py index df4f877..1c4f192 100644 --- a/tests/test_stdlib_ssl_context.py +++ b/tests/test_stdlib_ssl_context.py @@ -4,7 +4,7 @@ import ssl import pytest -from mock import patch, Mock +from mock import patch from apns import make_ssl_context @@ -15,17 +15,22 @@ def test_require_tls1_2(self): make_ssl_context('cert.pem', 'key.pem', protocol=ssl.PROTOCOL_TLSv1_1) - @patch('apns.ssl_context.stdlib.ssl') - def test_make_context_sets_apln_npn_protocols(self, mock_ssl): - mock_ssl.PROTOCOL_TLSv1_2 = 1 - ctx_mock = Mock() - mock_ssl.SSLContext.return_value = ctx_mock - ctx = make_ssl_context('cert.pem', 'key.pem') + @patch('apns.ssl_context.stdlib.ssl.SSLContext') + def test_make_context_sets_apln_npn_protocols(self, mock_ctx): + ctx = make_ssl_context('cert.pem', 'key.pem', password='test') + + args, _ = mock_ctx.call_args + assert ssl.PROTOCOL_TLSv1_2 == args[0] + + args, kwargs = ctx.load_cert_chain.call_args + assert 'cert.pem' == args[0] + assert 'key.pem' == kwargs['keyfile'] + assert 'test' == kwargs['password'] - assert ctx is ctx_mock args, _ = ctx.set_alpn_protocols.call_args alpn_protos = args[0] assert 'h2' in alpn_protos + args, _ = ctx.set_npn_protocols.call_args npn_protos = args[0] assert 'h2' in npn_protos