2018-11-04 19:23:11 +00:00
|
|
|
"""
|
|
|
|
This file is part of nucypher.
|
|
|
|
|
|
|
|
nucypher is free software: you can redistribute it and/or modify
|
2019-03-05 02:50:11 +00:00
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
2018-11-04 19:23:11 +00:00
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
nucypher is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-03-05 02:50:11 +00:00
|
|
|
GNU Affero General Public License for more details.
|
2018-11-04 19:23:11 +00:00
|
|
|
|
2019-03-05 02:50:11 +00:00
|
|
|
You should have received a copy of the GNU Affero General Public License
|
2018-11-04 19:23:11 +00:00
|
|
|
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
"""
|
2019-02-26 04:46:03 +00:00
|
|
|
import os
|
2018-11-03 21:48:11 +00:00
|
|
|
|
2018-11-09 15:25:20 +00:00
|
|
|
import pytest
|
2018-11-27 00:43:47 +00:00
|
|
|
from twisted.logger import globalLogPublisher
|
2018-11-09 15:25:20 +00:00
|
|
|
|
2019-02-26 04:46:03 +00:00
|
|
|
from nucypher.characters.control.emitters import WebEmitter
|
2019-02-12 00:18:26 +00:00
|
|
|
from nucypher.cli.config import NucypherClickConfig
|
2019-02-14 08:23:48 +00:00
|
|
|
from nucypher.utilities.logging import GlobalConsoleLogger, logToSentry
|
2018-11-09 15:25:20 +00:00
|
|
|
# Logger Configuration
|
2018-11-20 04:29:01 +00:00
|
|
|
#
|
2019-02-26 04:46:03 +00:00
|
|
|
from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD
|
|
|
|
|
2019-02-14 21:49:24 +00:00
|
|
|
globalLogPublisher.removeObserver(logToSentry)
|
2018-11-20 04:29:01 +00:00
|
|
|
|
|
|
|
# Disable click sentry and file logging
|
2018-11-05 23:13:45 +00:00
|
|
|
NucypherClickConfig.log_to_sentry = False
|
2019-03-05 21:50:14 +00:00
|
|
|
NucypherClickConfig.log_to_file = True
|
2018-08-05 20:09:05 +00:00
|
|
|
|
2019-02-22 05:38:54 +00:00
|
|
|
# Crash on server error by default
|
2019-02-26 04:48:31 +00:00
|
|
|
WebEmitter._crash_on_error_default = False
|
|
|
|
|
|
|
|
|
|
|
|
##########################################
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True, scope='session')
|
|
|
|
def __very_pretty_and_insecure_scrypt_do_not_use():
|
|
|
|
"""
|
|
|
|
# WARNING: DO NOT USE THIS CODE ANYWHERE #
|
|
|
|
|
|
|
|
Mocks Scrypt derivation function for the duration of
|
|
|
|
the test session in order to improve test performance.
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Capture Scrypt derivation method
|
|
|
|
from cryptography.hazmat.primitives.kdf.scrypt import Scrypt
|
|
|
|
original_derivation_function = Scrypt.derive
|
|
|
|
|
|
|
|
# One-Time Insecure Password
|
2019-03-04 22:10:12 +00:00
|
|
|
insecure_password = bytes(INSECURE_DEVELOPMENT_PASSWORD, encoding='utf8')
|
2019-02-26 04:48:31 +00:00
|
|
|
|
|
|
|
# Patch Method
|
|
|
|
def __insecure_derive(*args, **kwargs):
|
|
|
|
"""Temporarily replaces Scrypt.derive for mocking"""
|
|
|
|
return insecure_password
|
|
|
|
|
|
|
|
# Disable Scrypt KDF
|
|
|
|
Scrypt.derive = __insecure_derive
|
|
|
|
yield
|
|
|
|
|
|
|
|
# Re-Enable Scrypt KDF
|
|
|
|
Scrypt.derive = original_derivation_function
|
|
|
|
|
|
|
|
############################################
|
2019-02-22 05:38:54 +00:00
|
|
|
|
|
|
|
|
2018-11-20 04:29:01 +00:00
|
|
|
#
|
2018-11-09 15:25:20 +00:00
|
|
|
# Pytest configuration
|
2018-11-20 04:29:01 +00:00
|
|
|
#
|
|
|
|
|
2018-11-09 15:25:20 +00:00
|
|
|
pytest_plugins = [
|
2018-12-07 02:19:57 +00:00
|
|
|
'tests.fixtures', # Includes external fixtures module
|
2018-11-09 15:25:20 +00:00
|
|
|
]
|
2018-06-04 18:00:08 +00:00
|
|
|
|
|
|
|
|
2018-05-07 02:11:20 +00:00
|
|
|
def pytest_addoption(parser):
|
2018-09-13 20:07:14 +00:00
|
|
|
parser.addoption("--runslow",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
2018-09-20 19:51:41 +00:00
|
|
|
help="run tests even if they are marked as slow")
|
2018-05-07 02:11:20 +00:00
|
|
|
|
2018-06-04 18:00:08 +00:00
|
|
|
|
2018-05-07 02:11:20 +00:00
|
|
|
def pytest_collection_modifyitems(config, items):
|
2019-05-31 20:41:56 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Handle slow tests marker
|
|
|
|
#
|
|
|
|
|
2018-12-07 04:58:32 +00:00
|
|
|
if not config.getoption("--runslow"): # --runslow given in cli: do not skip slow tests
|
2018-11-17 19:27:53 +00:00
|
|
|
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
|
2019-05-31 20:41:56 +00:00
|
|
|
|
2018-11-17 19:27:53 +00:00
|
|
|
for item in items:
|
|
|
|
if "slow" in item.keywords:
|
|
|
|
item.add_marker(skip_slow)
|
2019-05-31 20:41:56 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Handle Log Level
|
|
|
|
#
|
|
|
|
|
2018-11-17 19:27:53 +00:00
|
|
|
log_level_name = config.getoption("--log-level", "info", skip=True)
|
2019-05-31 20:41:56 +00:00
|
|
|
|
2019-02-14 19:26:21 +00:00
|
|
|
GlobalConsoleLogger.set_log_level(log_level_name)
|