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

Various fixes to tests infrastructure #246

Merged
merged 3 commits into from
Aug 20, 2019
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
12 changes: 8 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sudo: required

dist: trusty
dist: xenial

language: python

Expand All @@ -23,13 +23,17 @@ matrix:
env: TOXENV=py36-extras
- python: 3.6
env: TOXENV=py36-noextras
- python: 3.6
- python: 3.7
env: TOXENV=py37-extras
- python: 3.7
env: TOXENV=py37-noextras
- python: 3.7
env: TOXENV=doc
- python: 3.6
- python: 3.7
env: TOXENV=lint
- python: 2.7
env: TOXENV=pep8py2
- python: 3.6
- python: 3.7
env: TOXENV=pep8py3

before_install:
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ cscope:
git ls-files | xargs pycscope

test: clean_socket clean_coverage
$(TOX) --skip-missing-interpreters -e py27-extra,py27-noextra
$(TOX) --skip-missing-interpreters -e py35-extra,py35-noextra
$(TOX) --skip-missing-interpreters -e py36-extra,py36-noextra
$(TOX) --skip-missing-interpreters -e py27-extras,py27-noextras
$(TOX) --skip-missing-interpreters -e py35-extras,py35-noextras
$(TOX) --skip-missing-interpreters -e py36-extras
$(TOX) --skip-missing-interpreters -e doc
$(TOX) -e coverage-report

Expand Down
2 changes: 1 addition & 1 deletion src/custodia/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def main():

try:
result = args.func(args)
except BaseException as e:
except BaseException as e: # pylint: disable=broad-except
simo5 marked this conversation as resolved.
Show resolved Hide resolved
errcode, msg = error_message(args, e)
main_parser.exit(errcode, msg)
else:
Expand Down
4 changes: 2 additions & 2 deletions src/custodia/ipa/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def finalize_init(self, config, cfgparser, context=None):
# monkey-patch ipalib.constants and all loaded ipa modules
ipalib.constants.USER_CACHE_PATH = rundir
for name, mod in six.iteritems(sys.modules):
if (name.startswith(('ipalib.', 'ipaclient.')) and
hasattr(mod, 'USER_CACHE_PATH')):
if (name.startswith(('ipalib.', 'ipaclient.'))
and hasattr(mod, 'USER_CACHE_PATH')):
simo5 marked this conversation as resolved.
Show resolved Hide resolved
mod.USER_CACHE_PATH = rundir

self._gssapi_config()
Expand Down
8 changes: 4 additions & 4 deletions src/custodia/store/encgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def __init__(self, config, section):
self.store = None
self.protected_header = None

if (not os.path.isfile(self.master_key) and
self.autogen_master_key):
if (not os.path.isfile(self.master_key)
and self.autogen_master_key):
simo5 marked this conversation as resolved.
Show resolved Hide resolved
# XXX https://github.com/latchset/jwcrypto/issues/50
size = self.key_sizes.get(self.master_enctype, 512)
key = JWK(generate='oct', size=size)
Expand Down Expand Up @@ -79,8 +79,8 @@ def get(self, key):
if self.secret_protection == 'migrate':
self.set(key, value, replace=True)
else:
raise CSStoreError('Secret Pinning check failed!' +
'Missing custodia.key element')
raise CSStoreError('Secret Pinning check failed!'
+ 'Missing custodia.key element')
simo5 marked this conversation as resolved.
Show resolved Hide resolved
elif jwe.jose_header['custodia.key'] != key:
raise CSStoreError(
'Secret Pinning check failed! Expected {} got {}'.format(
Expand Down
2 changes: 1 addition & 1 deletion src/custodia/store/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def set(self, key, value, replace=False):
c.execute(setdata, (key, value))
except sqlite3.IntegrityError as err:
raise CSStoreExists(str(err))
except sqlite3.Error as err:
except sqlite3.Error:
simo5 marked this conversation as resolved.
Show resolved Hide resolved
self.logger.exception("Error storing key %s", key)
raise CSStoreError('Error occurred while trying to store key')

Expand Down
12 changes: 11 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ def pytest_addoption(parser):

def pytest_runtest_setup(item):
skip_servertest = item.config.getoption(SKIP_SERVERTEST)
if skip_servertest and item.get_marker("servertest") is not None:
skiptest = False
if skip_servertest:
# pytest < 4
if hasattr(item, 'get_marker'):
if item.get_marker("servertest"):
skiptest = True
# pytest >= 4
elif item.get_closest_marker("servertest"):
skiptest = True

if skiptest:
# args has --skip-servertests and test is marked as servertest
pytest.skip("Skip integration test")
6 changes: 2 additions & 4 deletions tests/functional/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,11 @@ def close_dev_null():
@pytest.fixture(scope="class")
def custodia_server(self, simple_configuration, request, dev_null):
# Don't write server messages to stdout unless we are in debug mode
# pylint: disable=no-member
if pytest.config.getoption('debug') or \
pytest.config.getoption('verbose'):
if (request.config.getoption('debug')
or request.config.getoption('verbose')):
stdout = stderr = None
else:
stdout = stderr = dev_null
# pylint: enable=no-member

self.process = subprocess.Popen(
[sys.executable, '-m', 'custodia.server', self.custodia_conf],
Expand Down
23 changes: 13 additions & 10 deletions tests/test_custodia.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,14 +506,16 @@ def create_client(cls, suffix, remote_user, clientcls=None):
client.set_client_cert(cls.client_cert, cls.client_key)
return client

def assert_ssl_error_msg(self, msg, exc):
# CERTIFICATE_VERIFY_FAILED, SSLV3_ALERT_HANDSHAKE_FAILURE
if msg in str(exc):
return
# 'certificate verify failed'
msg = msg.lower().replace('_', ' ')
if msg in str(exc):
return
def assert_ssl_error_msg(self, msgs, exc):
simo5 marked this conversation as resolved.
Show resolved Hide resolved
# CERTIFICATE_VERIFY_FAILED or
# SSLV3_ALERT_HANDSHAKE_FAILURE / Connection reset by peer
for msg in msgs:
if msg in str(exc):
return
# 'certificate verify failed'
msg = msg.lower().replace('_', ' ')
if msg in str(exc):
return
self.fail(str(exc))

def test_client_no_ca_trust(self):
Expand All @@ -522,7 +524,7 @@ def test_client_no_ca_trust(self):
# XXX workaround for requests bug with urllib3 v1.22
with self.assertRaises(RequestsConnSSLErrors) as e:
client.list_container('test')
self.assert_ssl_error_msg("CERTIFICATE_VERIFY_FAILED", e.exception)
self.assert_ssl_error_msg(["CERTIFICATE_VERIFY_FAILED"], e.exception)

def test_client_no_client_cert(self):
client = CustodiaSimpleClient(self.socket_url + '/forwarder')
Expand All @@ -531,7 +533,8 @@ def test_client_no_client_cert(self):
# XXX workaround for requests bug with urllib3 v1.22
with self.assertRaises(RequestsConnSSLErrors) as e:
client.list_container('test')
self.assert_ssl_error_msg("SSLV3_ALERT_HANDSHAKE_FAILURE",
self.assert_ssl_error_msg(["Connection reset by peer",
"SSLV3_ALERT_HANDSHAKE_FAILURE"],
e.exception)

def test_C_client_cert_auth(self):
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
minversion = 2.3.1
envlist = lint,py{27,35,36}-{extras,noextras},pep8py2,pep8py3,doc,coverage-report
envlist = lint,py{27,35,36,37}-{extras,noextras},pep8py2,pep8py3,doc,coverage-report
skip_missing_interpreters = true

[testenv]
Expand Down Expand Up @@ -90,5 +90,5 @@ addopts=-p no:logging
exclude = .tox,*.egg,dist,build,docs/source
show-source = true
max-line-length = 79
ignore = N802
ignore = N802,W503
simo5 marked this conversation as resolved.
Show resolved Hide resolved
application-import-names = custodia