summaryrefslogtreecommitdiff
path: root/tests/test_server.py
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-09-23 21:11:01 -0400
committerJohn Turner <jturner.usa@gmail.com>2025-09-25 00:46:06 -0400
commit8779a06a5b4afbb3a57b858b51ba8a2dd5787c75 (patch)
treed0efab55a60a10c638df2e5b4194a060c9a85c38 /tests/test_server.py
parent2aa14b931f1a4fa7f465537b5310217b84615203 (diff)
downloadpypaste-8779a06a5b4afbb3a57b858b51ba8a2dd5787c75.tar.gz
change keys to 13*key_length bit random tokens and humanize the result
Instead of picking random words via a random choice function, we generate a 13 * key_length bit random int as the key. We humanize the key by splitting it up into 13 bit segments and using the 13 bits as an index into the word list. This allows us to store the keys in binary form which is faster and uses less space.
Diffstat (limited to 'tests/test_server.py')
-rwxr-xr-xtests/test_server.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/tests/test_server.py b/tests/test_server.py
index 0ccfc5b..2b1ed2e 100755
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@ -7,6 +7,7 @@ import string
import random
import aiohttp
from pathlib import Path
+from asyncio import Queue
def truncate(file: Path) -> None:
@@ -20,10 +21,21 @@ def generate_name() -> str:
return "".join(random.choice(characters) for _ in range(10))
+async def tee_pipe(proc: asyncio.subprocess.Process, queue: Queue[str]) -> None:
+ assert proc.stdout is not None
+
+ while (line := await proc.stdout.readline()) is not None:
+ sys.stderr.write(line.decode())
+ await queue.put(line.decode())
+
+
async def main() -> int:
- with tempfile.TemporaryDirectory() as tmpdir:
+ with tempfile.TemporaryDirectory(delete=False) as tmpdir:
+ print(tmpdir, file=sys.stderr)
+
socket = Path(tmpdir) / (generate_name() + ".sock")
database = Path(tmpdir) / generate_name()
+ queue: Queue[str] = Queue()
truncate(database)
@@ -38,7 +50,7 @@ async def main() -> int:
"--content-length-max-bytes",
"200000",
"--key-length",
- "3",
+ "6",
"--database",
database,
"--storage-max-bytes",
@@ -48,12 +60,9 @@ async def main() -> int:
stderr=asyncio.subprocess.STDOUT,
)
- assert proc.stdout is not None
-
- line = await proc.stdout.readline()
+ asyncio.create_task(tee_pipe(proc, queue))
- if b"starting" not in line:
- print(line, file=sys.stderr)
+ if "starting" not in await queue.get():
return 1
connection = aiohttp.UnixConnector(path=str(socket))