-
Notifications
You must be signed in to change notification settings - Fork 697
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
Use the existing GPG fixture in the functional tests (CryptoUtil 2/3) #6184
Use the existing GPG fixture in the functional tests (CryptoUtil 2/3) #6184
Conversation
a3d28e0
to
d7be83c
Compare
|
||
# WARNING: This variable must be set before any import of the securedrop code/app | ||
# or most tests will fail | ||
os.environ["SECUREDROP_ENV"] = "test" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Putting this here ensures that the SECUREDROP_ENV
will always be set before any application code is imported.
@@ -110,37 +107,39 @@ def insecure_scrypt() -> Generator[None, None, None]: | |||
yield | |||
|
|||
|
|||
def setup_gpg(gpg_dir: Path) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All I did here was move the logic in setup_gpg()
to setup_journalist_key_and_gpg_folder()
.
@@ -172,7 +171,10 @@ def config( | |||
|
|||
config.SUPPORTED_LOCALES = i18n.get_test_locales() | |||
|
|||
yield config | |||
# Set this newly-created config as the "global" config | |||
with mock.patch.object(sdconfig, "config", config): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Important change here: this ensures that the application code "sees" the same config as the one created in the fixture (when the code imports the config).
It's not perfect and more work is needed with the config fixture, but it's a step forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SECUREDROP_ENV
does not seem to be set here when make test
is run locally . It's used to set the database URI to the appropriate value for the environment, so without it the alembic tests in particular will fail. (Said failure isn't happening in CI for some reason).
One solution is to add os.environ["SECUREDROP_ENV"] = "test"
before filesystem setup, but I'm sure there are more elegant ones :)
config.SOURCE_APP_FLASK_CONFIG_CLS.USE_X_SENDFILE = False | ||
|
||
# Disable CSRF checks to make writing tests easier | ||
config.SOURCE_APP_FLASK_CONFIG_CLS.WTF_CSRF_ENABLED = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was copied from the config.py created by make test
. These settings are needed for the tests to pass.
@@ -202,7 +199,7 @@ def set_default_driver(self): | |||
logging.error("Error stopping Firefox driver: %s", e) | |||
|
|||
@pytest.fixture(autouse=True) | |||
def sd_servers(self): | |||
def sd_servers(self, setup_journalist_key_and_gpg_folder): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "main" change in this PR.
# Then check the directory was already deleted | ||
assert not os.path.exists(config.TEMP_DIR) | ||
try: | ||
shutil.rmtree(config.SECUREDROP_DATA_ROOT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am no longer deleting the SECUREDROP_DATA_ROOT
between each test because it will delete the GPG_KEY_DIR
too (as it's a subfolder of SECUREDROP_DATA_ROOT
).
d7be83c
to
fac74a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI looks good, but the test_alembic.py tests fail when make test
is run locally as the db URI is being set to the prod value instead of test's.
@@ -172,7 +171,10 @@ def config( | |||
|
|||
config.SUPPORTED_LOCALES = i18n.get_test_locales() | |||
|
|||
yield config | |||
# Set this newly-created config as the "global" config | |||
with mock.patch.object(sdconfig, "config", config): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SECUREDROP_ENV
does not seem to be set here when make test
is run locally . It's used to set the database URI to the appropriate value for the environment, so without it the alembic tests in particular will fail. (Said failure isn't happening in CI for some reason).
One solution is to add os.environ["SECUREDROP_ENV"] = "test"
before filesystem setup, but I'm sure there are more elegant ones :)
fd5c35b
to
11d7490
Compare
from db import db | ||
from models import ( | ||
if not os.environ.get("SECUREDROP_ENV"): | ||
os.environ['SECUREDROP_ENV'] = 'dev' # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zenmonkeykstop This fixes the alembic tests. Thanks for explaining what the problem was.
Fix alembic tests failing
11d7490
to
403629d
Compare
(rebased to pull in a dependency update and get tests passing) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good, tests passing locally as well now!
Status
Ready.
Description of Changes
This PR updates the functional tests to use the same fixture for GPG as the other tests. It also updates the config fixture.
config()
fixture, or the config from the config.py file generated bymake test
right before the tests run.