From e693f0a80b27cdcc40ab002b8796a4df1d28cdf0 Mon Sep 17 00:00:00 2001 From: Kushal Das Date: Tue, 31 Jul 2018 21:27:37 +0530 Subject: [PATCH 1/4] Adds --staging flag create-dev-data.py for tests We now have --staging flag to the create-dev-data.py script so that we can easily create an user in the staging or prodcution test and then use the functional tests to test the instance. (cherry picked from commit b08a0d7d634b2a9387742a72dba48be46fe15e90) --- securedrop/create-dev-data.py | 14 ++++++++++-- securedrop/tests/functional/README.md | 33 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 securedrop/tests/functional/README.md diff --git a/securedrop/create-dev-data.py b/securedrop/create-dev-data.py index 7af1ecbe4a..ab4e886710 100755 --- a/securedrop/create-dev-data.py +++ b/securedrop/create-dev-data.py @@ -3,6 +3,7 @@ import datetime import os +import argparse from flask import current_app from sqlalchemy.exc import IntegrityError @@ -15,7 +16,7 @@ from models import Journalist, Reply, Source, Submission -def main(): +def main(staging=False): app = journalist_app.create_app(config) with app.app_context(): # Add two test users @@ -26,6 +27,10 @@ def main(): test_password, test_otp_secret, is_admin=True) + + if staging: + return + add_test_user("dellsberg", test_password, test_otp_secret, @@ -104,4 +109,9 @@ def create_source_and_submissions(num_submissions=2, num_replies=2): if __name__ == "__main__": # pragma: no cover - main() + parser = argparse.ArgumentParser() + parser.add_argument("--staging", help="Adding user for staging tests.", + action="store_true") + args = parser.parse_args() + + main(args.staging) diff --git a/securedrop/tests/functional/README.md b/securedrop/tests/functional/README.md new file mode 100644 index 0000000000..1651ee6168 --- /dev/null +++ b/securedrop/tests/functional/README.md @@ -0,0 +1,33 @@ +### To test in prod vms + +- `sudo -u www-data bash` +- `cd /var/wwww/securedrop/` +- `./manage.py reset` # This will clean the DB for testing +- `./create-dev-data.py --staging` + +Update this information to the `tests/functional/instance_information.json file. + +The content of the file looks like below. + +``` +{ + "hidserv_token": "asfjsdfag", + "journalist_location": "http://thejournalistfqb.onion", + "source_location": "http://thesourceadsfa.onion", + "sleep_time": 10, + "user": { + "name": "journalist", + "password": "WEjwn8ZyczDhQSK24YKM8C9a", + "secret": "JHCOGO7VCER3EJ4L" + } +} +``` + +### Run the tests + +``` +cd securedrop +./bin/dev-shell ./bin/run-test -v tests/functional/ +``` +You may wish to append a pipe to less (i.e. `| less`), as a failure may generate +many pages of output, making it difficult to scroll back. From 689f4bdb096507d2b1f46d2532159879f8dd6eb8 Mon Sep 17 00:00:00 2001 From: John Hensley Date: Fri, 22 Mar 2019 18:06:31 -0400 Subject: [PATCH 2/4] Fix typo in functional test README --- securedrop/tests/functional/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/securedrop/tests/functional/README.md b/securedrop/tests/functional/README.md index 1651ee6168..11e75ae453 100644 --- a/securedrop/tests/functional/README.md +++ b/securedrop/tests/functional/README.md @@ -1,7 +1,7 @@ ### To test in prod vms - `sudo -u www-data bash` -- `cd /var/wwww/securedrop/` +- `cd /var/www/securedrop/` - `./manage.py reset` # This will clean the DB for testing - `./create-dev-data.py --staging` From 102afb57bcf4798cd466001b9aaeec1bf1a58577 Mon Sep 17 00:00:00 2001 From: Michael Sheinberg Date: Fri, 17 Aug 2018 11:40:31 -0400 Subject: [PATCH 3/4] Add functionality to prepare boxes for functional testing Typically these actions were done manually but lets get our good old friend ansible to run them for us (at least under the upgrade env). --- molecule/upgrade/side_effect.yml | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/molecule/upgrade/side_effect.yml b/molecule/upgrade/side_effect.yml index 8316bde38a..5e6a0c78d8 100644 --- a/molecule/upgrade/side_effect.yml +++ b/molecule/upgrade/side_effect.yml @@ -1,5 +1,4 @@ --- - - name: Perform apt upgrades hosts: securedrop become: yes @@ -8,3 +7,29 @@ apt: update_cache: yes upgrade: yes + +- name: Lay out app testing deps + hosts: securedrop_application_server + max_fail_percentage: 0 + any_errors_fatal: yes + roles: + - role: app-test + tags: app-test + + tasks: + - name: Reset database + command: ./manage.py reset + args: + chdir: /var/www/securedrop + + - name: Slap in latest create-dev-data script + copy: + src: ../../securedrop/create-dev-data.py + dest: /var/www/securedrop/create-dev-data.py + mode: 0555 + + - name: Insert journalist test user + command: /var/www/securedrop/create-dev-data.py --staging + args: + chdir: /var/www/securedrop + become: yes From cb663eddd0471fc62fa0bd1eff50884e0b5d4428 Mon Sep 17 00:00:00 2001 From: John Hensley Date: Mon, 25 Mar 2019 10:43:04 -0400 Subject: [PATCH 4/4] Add missing backquote --- securedrop/tests/functional/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/securedrop/tests/functional/README.md b/securedrop/tests/functional/README.md index 11e75ae453..b3a9aebc93 100644 --- a/securedrop/tests/functional/README.md +++ b/securedrop/tests/functional/README.md @@ -5,7 +5,7 @@ - `./manage.py reset` # This will clean the DB for testing - `./create-dev-data.py --staging` -Update this information to the `tests/functional/instance_information.json file. +Update this information to the `tests/functional/instance_information.json` file. The content of the file looks like below.