Last active
April 29, 2020 22:29
-
-
Save zenmonkeykstop/c9ff2a4df509b0aade26602c47f3259e to your computer and use it in GitHub Desktop.
getkeytest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Script by @rmol to test SecureDrop API /sources response times | |
# | |
# 1) copy the file to your Admin workstation | |
# 2) fill in the address and admin account values for your instance | |
# 3) activate the securedrop admin venv with the command `source ~/Persistent/securedrop/admin/.venv3/bin/activate` | |
# 4) install the script dependencies with `torify pip install pyotp requests` | |
# 4) run the script with `python3 getkeytest.py` | |
# 5) note times for first and subsequent get_all_sources call | |
import time | |
import pyotp | |
import requests | |
def api_url(path): | |
return "http://localhost:8081/api/v1{}".format(path) | |
def get_all_sources(headers): | |
start = time.perf_counter() | |
get_all_sources_response = requests.get(api_url("/sources"), headers=headers) | |
elapsed = time.perf_counter() - start | |
sources = get_all_sources_response.json()["sources"] | |
print("get_all_sources with {:d} sources took {:.2f} seconds".format(len(sources), elapsed)) | |
if __name__ == "__main__": | |
token_data = { | |
"username": "journalist", | |
"passphrase": "correct horse battery staple profanity oil chewy", | |
"one_time_code": pyotp.TOTP("JHCOGO7VCER3EJ4L").now(), | |
} | |
token_response = requests.post(api_url("/token"), json=token_data).json() | |
headers = { | |
"Authorization": "Token {}".format(token_response["token"]) | |
} | |
get_all_sources(headers) | |
get_all_sources(headers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment