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

loaddata: Allow increasing the size of submitted files #7016

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 11 additions & 3 deletions securedrop/loaddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def submit_message(source: Source, journalist_who_saw: Optional[Journalist]) ->
db.session.add(seen_message)


def submit_file(source: Source, journalist_who_saw: Optional[Journalist]) -> None:
def submit_file(source: Source, size: int, journalist_who_saw: Optional[Journalist]) -> None:
"""
Adds a single file submitted by a source.
"""
Expand All @@ -202,7 +202,7 @@ def submit_file(source: Source, journalist_who_saw: Optional[Journalist]) -> Non
source.interaction_count,
source.journalist_filename,
"memo.txt",
io.BytesIO(b"This is an example of a plain text file upload."),
io.BytesIO(b"A" * size),
Copy link
Contributor

Choose a reason for hiding this comment

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

We compress then encrypt, so this will compress down to pretty much nothing before further processing, making it less useful for timing encryption or file transfers. Consider adding some randomness?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, good point. Also there's a lot of overhead from SecureTemporaryFile. Maybe just a simple benchmarking script that just benchmarks exactly what we want (GPG vs redwood) would be better. Let me try to come up with something...

)
submission = Submission(source, fpath, Storage.get_default())
db.session.add(submission)
Expand Down Expand Up @@ -350,7 +350,9 @@ def add_sources(args: argparse.Namespace, journalists: Tuple[Journalist, ...]) -
seen_message_count -= 1

for _ in range(args.files_per_source):
submit_file(source, secrets.choice(journalists) if seen_file_count > 0 else None)
submit_file(
source, args.file_size, secrets.choice(journalists) if seen_file_count > 0 else None
)
seen_file_count -= 1

if i <= starred_sources_count:
Expand Down Expand Up @@ -436,6 +438,12 @@ def parse_arguments() -> argparse.Namespace:
default=2,
help=("Number of submitted files to create for each source"),
)
parser.add_argument(
"--file-size",
type=non_negative_int,
default=25,
help="Size of the generated file to be submitted, in bytes.",
)
parser.add_argument(
"--replies-per-source",
type=non_negative_int,
Expand Down
Loading