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

Misc test cleanup #1445

Merged
merged 9 commits into from
Nov 4, 2016
Merged

Misc test cleanup #1445

merged 9 commits into from
Nov 4, 2016

Conversation

psivesely
Copy link
Contributor

  • Updates some syntax.
  • Imports config after setting SECUREDROP_ENV.
  • Gets the test suite working again by fetching an old version of Firefox from the Ubuntu archives that's still compatible with the last Selenium 2 release. We want to avoid switching to Selenium 3 before the Aaron Swartz day Hackathon this weekend.
  • Replaces a hardcoded path with a config attr.
  • Removes a couple test methods and a lot of TOTP values that were doing nothing because the verification is mocked.

Noah Vesely added 5 commits November 3, 2016 20:29
Flask Testing maintains some `assert_foo` methods that redirect to the assertFoo
syntax used by the `unittest.TestCase` class on which it's own `TestCase` class
is based (I presume at one point they decided to standardize, but didn't want to
break older code like ours). For consistency, I believe the camelcase syntax is
preferable.
* Replaces TOTP token values with 'mocked' to make it clear it we're mocking
  TOTP verification.
* Removes functions that test TOTP verification.
Selenium 3 makes breaking API changes that require Mozilla's geckodriver.  We're
going to hold off on supporting this for now. I've pinned Selenium at the latest
2.X release (2.53.6), and written Ansible code to download and install Ubuntu
46.0.1, which is the latest Firefox version that version of Selenium supports.
Since normally we run unit tests from manage.py this bug was never caught--in
interactive cases where you might not be using manage.py, the config attributes
were getting set mostly as in prod (if you don't set SECUREDROP_ENV you actually
get a result that not's exactly any of the configuration settings).
@redshiftzero
Copy link
Contributor

Hey @fowlslegs thanks for taking on the functional tests! I tried to provision a development VM using this branch but ran into some dependency issues installing Firefox 46:

TASK [app-test : Install Firefox 46.0.1 for compatibility with Selenium 2.53.6.] ***
fatal: [development]: FAILED! => {"changed": true, "cmd": ["dpkg", "-i", "/home/vagrant/firefox_46.0.1+build1-0ubuntu0.14.04.3_amd64.deb"], "delta": "0:00:04.272178", "end": "2016-11-04 17:57:32.565899", "failed": true, "rc": 1, "start": "2016-11-04 17:57:28.293721", "stderr": "dpkg: dependency problems prevent configuration of firefox:\n firefox depends on libasound2 (>= 1.0.16); however:\n  Package libasound2 is not installed.\n firefox depends on libcairo-gobject2 (>= 1.10.0); however:\n  Package libcairo-gobject2 is not installed.\n firefox depends on libgtk-3-0 (>= 3.4); however:\n  Package libgtk-3-0 is not installed.\n firefox depends on libstartup-notification0 (>= 0.8); however:\n  Package libstartup-notification0 is not installed.\n\ndpkg: error processing package firefox (--install):\n dependency problems - leaving unconfigured\nErrors were encountered while processing:\n firefox", "stdout": "Selecting previously unselected package firefox.\n(Reading database ... 39240 files and directories currently installed.)\nPreparing to unpack .../firefox_46.0.1+build1-0ubuntu0.14.04.3_amd64.deb ...\nUnpacking firefox (46.0.1+build1-0ubuntu0.14.04.3) ...\nProcessing triggers for mime-support (3.54ubuntu1.1) ...\nProcessing triggers for man-db (2.6.7.1-1ubuntu1) ...", "stdout_lines": ["Selecting previously unselected package firefox.", "(Reading database ... 39240 files and directories currently installed.)", "Preparing to unpack .../firefox_46.0.1+build1-0ubuntu0.14.04.3_amd64.deb ...", "Unpacking firefox (46.0.1+build1-0ubuntu0.14.04.3) ...", "Processing triggers for mime-support (3.54ubuntu1.1) ...", "Processing triggers for man-db (2.6.7.1-1ubuntu1) ..."], "warnings": []}

# /root. Since this command doesn't need to be run as root and is part of a
# crutch anyway, I've just hardcoded /home/vagrant.
dest: /home/vagrant/
url: https://launchpad.net/~ubuntu-mozilla-security/+archive/ubuntu/ppa/+build/9727836/+files/firefox_46.0.1+build1-0ubuntu0.14.04.3_amd64.deb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get a checksum on this task to validate the download.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is signed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is signed.

The associated Release file in the origin repo is signed, but these tasks perform no signature verification. Confirm the SHA256 checksum manually and hardcode it in the get_url task.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, there is an option

       --no-debsig
              Do not try to verify package signatures.

in the dpkg man page, but I am remembering now that dpkg doesn't actually verify signatures, and I don't know what that flag is about.

- apt

- name: Install Firefox 46.0.1 for compatibility with Selenium 2.53.6.
command: dpkg -i /home/vagrant/firefox_46.0.1+build1-0ubuntu0.14.04.3_amd64.deb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The apt module supports a deb parameter, so you don't need to invoke dpkg via command.

@conorsch
Copy link
Contributor

conorsch commented Nov 4, 2016

As @redshiftzero reported, Firefox installation fails due to lack of dependencies. Folded error output:

TASK: [app-test | Install Firefox 46.0.1 for compatibility with Selenium 
2.53.6.] ***
failed: [development] => {"changed": true, "cmd": ["dpkg", "-i", 
"/home/vagrant/firefox_46.0.1+build1-0ubuntu0.14.04.3_amd64.deb"], "delta": 
"0:00:05.810106", "end": "2016-11-04 18:21:13.372646", "rc": 1, "start": 
"2016-11-04 18:21:07.562540", "warnings": []}
stderr: dpkg: dependency problems prevent configuration of firefox:
 firefox depends on libasound2 (>= 1.0.16); however:
  Package libasound2 is not installed.
 firefox depends on libcairo-gobject2 (>= 1.10.0); however:
  Package libcairo-gobject2 is not installed.
 firefox depends on libgtk-3-0 (>= 3.4); however:
  Package libgtk-3-0 is not installed.
 firefox depends on libstartup-notification0 (>= 0.8); however:
  Package libstartup-notification0 is not installed.

dpkg: error processing package firefox (--install):
 dependency problems - leaving unconfigured
Errors were encountered while processing:
 firefox
stdout: Selecting previously unselected package firefox.
(Reading database ... 41302 files and directories currently installed.)
Preparing to unpack .../firefox_46.0.1+build1-0ubuntu0.14.04.3_amd64.deb ...
Unpacking firefox (46.0.1+build1-0ubuntu0.14.04.3) ...
Processing triggers for mime-support (3.54ubuntu1.1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...

FATAL: all hosts have already failed -- aborting

@psivesely
Copy link
Contributor Author

psivesely commented Nov 4, 2016

Okay, two ways to solve:

  1. Set failed_when: false to the dpkg (soon to be apt module) task. And then run sudo apt-get install -f in the next task.
  2. Install those 4 dependencies first.

I think 2 is probably cleaner for Ansible, even though I would use 1 for convenience on my own laptop.

@conorsch
Copy link
Contributor

conorsch commented Nov 4, 2016

I think 2 is probably cleaner for Ansible

Agreed. Approach 1 would be clean with use of Ansible 2's block syntax, but alas, we are on Ansible v1 (cc #1146).

@psivesely
Copy link
Contributor Author

Ready for re-review. Working locally for me.

Copy link
Contributor

@redshiftzero redshiftzero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me @fowlslegs! Thanks for these changes. Functional tests are working again 👍 Just remove the one line I noted in functional/functional_test.py and we can get this merged.

@@ -11,6 +11,8 @@
import sys


# Set environment variable so config.py uses a test environment
os.environ['SECUREDROP_ENV'] = 'test'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why you're moving this here, but remove the old setting of the environmental variable on line 29

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

otp = self.new_user['orm_obj'].totp.at(
datetime.datetime.now() + datetime.timedelta(seconds=interval))
self._check_login_with_otp(otp)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test would always pass because it's mocked, and it looks like the underlying functionality - the valid_window option of verify which we now use for this check - is tested in pytop, so good to remove 👍

@@ -5,6 +5,8 @@

import gnupg

# Set environment variable so config.py uses a test environment
os.environ['SECUREDROP_ENV'] = 'test'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point, we might find another way to do this. We have this set in a few different places (also migrating this code above these module-level imports makes this file no longer PEP8 compliant - bad if we want to go in the direction of #886). Perhaps we could migrate some of the environmental variable setting necessary for our test running elsewhere (e.g. in manage.py or in the test runner (tox or pytest-env)). For now let's just leave as is and then come back after the hackathon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all environment variables need to be removed. Instead, the relevant arguments should be passed directly, such as to object constructors. See, e.g., the TestDatabase mixin class I recently added to help solve this problem in FPSD. The SecureDrop story will be a little more complicated, and I haven't figured it all out yet, but I plan to make a PR for this. Should maybe open an issue.

@redshiftzero redshiftzero merged commit a3916c7 into develop Nov 4, 2016
conorsch pushed a commit that referenced this pull request Nov 5, 2016
Changes in #1445 forced installation of a specific version of Firefox,
which caused tests to fail since not all packages were updated.
Carefully modified the tests to permit either "0" or "1" packages not
upgraded.
conorsch pushed a commit that referenced this pull request Nov 5, 2016
Recent changes in #1445 bumped a few test pip requirements. This commit
updates the Serverspec tests to match. The Serverspec tests aren't DRY
in this regard; there are two points of update right now, with a few
libs duplicated between `development` and `app-staging`. Not going to
mess with that now, because I just separated them out a few days ago.
conorsch pushed a commit that referenced this pull request Nov 6, 2016
Changes in #1445 forced installation of a specific version of Firefox,
which caused tests to fail since not all packages were updated.
Carefully modified the tests to permit either "0" or "1" packages not
upgraded.
conorsch pushed a commit that referenced this pull request Nov 6, 2016
Recent changes in #1445 bumped a few test pip requirements. This commit
updates the Serverspec tests to match. The Serverspec tests aren't DRY
in this regard; there are two points of update right now, with a few
libs duplicated between `development` and `app-staging`. Not going to
mess with that now, because I just separated them out a few days ago.
conorsch pushed a commit that referenced this pull request Nov 8, 2016
Changes in #1445 forced installation of a specific version of Firefox,
which caused tests to fail since not all packages were updated.
Carefully modified the tests to permit either "0" or "1" packages not
upgraded.
conorsch pushed a commit that referenced this pull request Nov 8, 2016
Recent changes in #1445 bumped a few test pip requirements. This commit
updates the Serverspec tests to match. The Serverspec tests aren't DRY
in this regard; there are two points of update right now, with a few
libs duplicated between `development` and `app-staging`. Not going to
mess with that now, because I just separated them out a few days ago.
conorsch pushed a commit that referenced this pull request Nov 8, 2016
Changes in #1445 forced installation of a specific version of Firefox,
which caused tests to fail since not all packages were updated.
Carefully modified the tests to permit either "0" or "1" packages not
upgraded.
conorsch pushed a commit that referenced this pull request Nov 8, 2016
Recent changes in #1445 bumped a few test pip requirements. This commit
updates the Serverspec tests to match. The Serverspec tests aren't DRY
in this regard; there are two points of update right now, with a few
libs duplicated between `development` and `app-staging`. Not going to
mess with that now, because I just separated them out a few days ago.
@redshiftzero redshiftzero deleted the misc-test-cleanup branch November 9, 2016 01:07
@redshiftzero redshiftzero mentioned this pull request Feb 7, 2017
14 tasks
conorsch pushed a commit that referenced this pull request Mar 30, 2017
Changes in #1445 forced installation of a specific version of Firefox,
which caused tests to fail since not all packages were updated.
Carefully modified the tests to permit either "0" or "1" packages not
upgraded.
conorsch pushed a commit that referenced this pull request Apr 5, 2017
Changes in #1445 forced installation of a specific version of Firefox,
which caused tests to fail since not all packages were updated.
Carefully modified the tests to permit either "0" or "1" packages not
upgraded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants