MCPcopy
hub / github.com/AstrBotDevs/AstrBot / test_nonce_generation

Function test_nonce_generation

tests/test_security_fixes.py:69–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67 }
68
69 async def test_nonce_generation():
70 async with OTTSProvider(config) as provider:
71 # Mock time sync to avoid actual API calls
72 provider.time_offset = 0
73 provider.last_sync_time = 9999999999
74
75 # Generate multiple signatures and extract nonces
76 signatures = []
77 for _ in range(10):
78 sig = await provider._generate_signature()
79 signatures.append(sig)
80
81 # Extract nonces (second field in signature format: timestamp-nonce-0-hash)
82 nonces = [sig.split("-")[1] for sig in signatures]
83
84 # All nonces should be 10 characters long
85 assert all(len(n) == 10 for n in nonces)
86
87 # All nonces should be alphanumeric (lowercase letters and digits)
88 for n in nonces:
89 assert all(c in "abcdefghijklmnopqrstuvwxyz0123456789" for c in n)
90
91 # All nonces should be different (cryptographic random ensures uniqueness)
92 assert len(set(nonces)) == 10
93
94 asyncio.run(test_nonce_generation())
95

Callers 1

Calls 4

OTTSProviderClass · 0.90
setFunction · 0.85
_generate_signatureMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected