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

Add staging-specific creation of test data #4298

Merged
merged 4 commits into from
Mar 26, 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
27 changes: 26 additions & 1 deletion molecule/upgrade/side_effect.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

- name: Perform apt upgrades
hosts: securedrop
become: yes
Expand All @@ -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
14 changes: 12 additions & 2 deletions securedrop/create-dev-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import datetime
import os
import argparse

from flask import current_app
from sqlalchemy.exc import IntegrityError
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)
33 changes: 33 additions & 0 deletions securedrop/tests/functional/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
### To test in prod vms

- `sudo -u www-data bash`
- `cd /var/www/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.