From bc05a77222267eeb4fdc6229d2f34c883ba7c056 Mon Sep 17 00:00:00 2001 From: Louis Burda Date: Fri, 9 Jul 2021 02:21:28 +0200 Subject: moved local check start out of checker folder, merged havocids into fakeid and created extra type of id which is only lower alphanumeric --- checker/src/checker.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'checker/src') diff --git a/checker/src/checker.py b/checker/src/checker.py index 7387aa9..54820ee 100644 --- a/checker/src/checker.py +++ b/checker/src/checker.py @@ -173,22 +173,28 @@ def leetify(clean: str) -> str: return "".join([conv[c] if c in conv else c for c in out]) -def fakeid(havoc: bool = False, minlen: int = 20, maxlen: int = 60) -> bytes: - if havoc: +def fakeid(minlen: int = 25, maxlen: int = 50) -> bytes: + choice = rand.randint(0, 2) + if choice == 0: # most random without hurting parsing idlen = rand.randint(minlen, maxlen) - return bytes([rand.randint(32, 127) for i in range(idlen)]) - else: + return bytes([rand.randint(33, 127) for i in range(idlen)]) + elif choice == 1: # a cat walking across the keyboard + idlen = rand.randint(minlen, maxlen) + alph = b"0123456789abcdefghijklmopqrstuvwxyz" + return bytes([rand.choice(alph) for i in range(idlen)]) + else: # a hacker band name idstr = b"" while len(idstr) < minlen: word = rand.choice(wordlist) if idstr != b"": idstr += b"-" - idstr += leetify(word).encode() if randbool() else word.encode() + idstr += leetify(word).encode() + idstr += b"-" + leetify(rand.choice(wordlist)).encode() return idstr[:maxlen] -def fakeids(n: int, havoc: bool = False) -> list[bytes]: - return [fakeid(havoc=havoc) for i in range(n)] +def fakeids(n: int) -> list[bytes]: + return [fakeid() for i in range(n)] def approx_equal(f1: float, f2: float, precision: int = 2) -> bool: @@ -705,8 +711,7 @@ def check_stlinfo( async def test_good_upload( di: DependencyInjector, filetype: str, register: bool ) -> None: - solidname = fakeid(havoc=(filetype == "bin")) # ascii stl cant handle havoc - modelname, authstr = fakeids(2, havoc=True) + solidname, modelname, authstr = fakeids(3) stlfile = genfile(solidname, filetype) ref_info = parse_stlinfo(stlfile) @@ -1025,7 +1030,7 @@ async def havoc_fluff_upload(di: DependencyInjector) -> None: # Simple Upload session = await di.get(Session) if randbool(): - await do_auth(session, fakeid(), check=True, newuser=True); + await do_auth(session, fakeid(), check=True, newuser=True) modelid = await do_upload(session, modelname, stlfile, check=True) assert modelid is not None await check_in_search( -- cgit v1.2.3-71-gd317