Skip to content

Instantly share code, notes, and snippets.

@cfm
Created September 27, 2022 00:56
Show Gist options
  • Save cfm/c1e4840788ba07ac207205325d28e529 to your computer and use it in GitHub Desktop.
Save cfm/c1e4840788ba07ac207205325d28e529 to your computer and use it in GitHub Desktop.
stress-test the SecureDrop submission flow with Locust for stress and profit
$ pip install faker locust  # Then go nuts:
$ locust --headless --users 10 --run-time 60s --host http://localhost:8080
import re
from faker import Faker
from locust import HttpUser, task
fake = Faker()
class SubmitFile(HttpUser):
@task
def submit_file(self):
self.client.get("/")
generate = self.client.get("/generate")
self.grab(generate, "csrf_token", "tab_id")
self.client.post("/create", {"csrf_token": self.csrf_token, "tab_id": self.tab_id})
lookup = self.client.get("/lookup")
self.grab(lookup, "csrf_token")
f = open(__file__, "rb")
self.client.post(
"/submit",
{
"csrf_token": self.csrf_token,
"msg": fake.text(),
"files": {"fh": f},
},
)
self.client.get("/logout")
def grab(self, response, *fields):
for k in fields:
needle = f'<input name="{k}" .* value="(?P<v>.+?)"'
v = re.search(re.compile(needle), response.text).groupdict()["v"]
setattr(self, k, v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment