forked from mtusi2026/mtusi2026lab2
Implement lab2 PostgreSQL authentication and Redis sessions
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Optional operator test for Redis session corruption on an isolated lab stack.
|
||||
No other users' keys are modified. Run only against own Docker Compose setup.
|
||||
"""
|
||||
import hashlib
|
||||
import subprocess
|
||||
from client import Client, check, run
|
||||
|
||||
|
||||
def main():
|
||||
c = Client()
|
||||
user = c.user('cachecorrupt')
|
||||
digest = hashlib.sha256(user['token'].encode('ascii')).hexdigest()
|
||||
key = 'session:' + digest
|
||||
cmd = ['docker','compose','--env-file','.env','exec','-T','redis','redis-cli']
|
||||
proc = subprocess.run(cmd + ['SET',key,'null','EX','30'], text=True, capture_output=True)
|
||||
check(proc.returncode == 0 and 'OK' in proc.stdout, 'could not inject synthetic corrupt Redis session')
|
||||
c.call('GET','/api/v1/users/me',401,actor=user)
|
||||
proc = subprocess.run(cmd + ['EXISTS', key], text=True, capture_output=True)
|
||||
check(proc.returncode == 0 and proc.stdout.strip()=='0', 'corrupt session key was not removed')
|
||||
print('PASS: malformed Redis session value fails closed with 401 and is removed')
|
||||
|
||||
if __name__=='__main__':
|
||||
run(main)
|
||||
Reference in New Issue
Block a user