forked from mtusi2026/mtusi2026lab7
Лабораторная 7: безопасность, mTLS и OpenBao, оценка 3
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
"""Public ingress: real login rate limit, body limit and hostname check."""
|
||||
import ssl
|
||||
import json
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
ctx=ssl.create_default_context(cafile='secrets/ca.crt')
|
||||
for i in range(25):
|
||||
req=urllib.request.Request('https://localhost:8443/api/v1/auth/sessions',data=b'',method='POST')
|
||||
try: urllib.request.urlopen(req,context=ctx,timeout=5)
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code==429:
|
||||
assert int(e.headers['Retry-After'])>0
|
||||
assert json.load(e)['error']['request_id']==e.headers['X-Request-Id']
|
||||
print('PASS login rate limit: 429 with Retry-After');break
|
||||
assert e.code==401
|
||||
else: raise AssertionError('429 not received')
|
||||
req=urllib.request.Request('https://localhost:8443/api/v1/users',data=b'x'*65537,headers={'Content-Type':'application/json'},method='POST')
|
||||
try: urllib.request.urlopen(req,context=ctx,timeout=5)
|
||||
except urllib.error.HTTPError as e: assert e.code==413
|
||||
else: raise AssertionError('body limit absent')
|
||||
print('PASS JSON request size limit: 413')
|
||||
Reference in New Issue
Block a user