feat: реализовать ЛР7 — TLS, mTLS, OpenBao и hardening
Skeleton contracts / contracts (pull_request) Blocked by required conditions
Skeleton contracts / contracts (pull_request) Blocked by required conditions
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
"""Black-box security controls: rate limit shared at Redis, token logout, spoofed identity, ACL.
|
||||
No secret or bearer is logged; uses the provided public HTTP client.
|
||||
"""
|
||||
import base64
|
||||
from client import Client, arguments, check, run
|
||||
|
||||
|
||||
def main():
|
||||
args=arguments('Lab7 live auth/ACL/429 checks; use verified HTTPS + CA')
|
||||
c=Client(args.base_url,args.ca_file)
|
||||
alice,bob,eve,chat=c.bootstrap()
|
||||
token=alice['token']
|
||||
response=c.call('GET','/api/v1/users/me',actor=alice,schema='User')
|
||||
check(response['json']['id']==alice['id'],'Bearer identity mismatch')
|
||||
response=c.call('GET','/api/v1/chats/'+chat['id'],404,actor=eve,
|
||||
headers={'X-User-Id':alice['id']})
|
||||
check(response['status']==404,'X-User-Id spoof changed access')
|
||||
check(c.call('DELETE','/api/v1/auth/sessions/current',204,actor=alice)['status']==204,
|
||||
'logout failed')
|
||||
check(c.call('GET','/api/v1/users/me',401,actor=alice)['status']==401,
|
||||
'revoked session still valid')
|
||||
# Use a different registered account; count is stored centrally by username hash.
|
||||
username=bob['registration']['username']
|
||||
statuses=[]
|
||||
for _ in range(10):
|
||||
basic=base64.b64encode((username+':incorrect-password').encode()).decode()
|
||||
r=c.call('POST','/api/v1/auth/sessions',expected=(401,429),
|
||||
headers={'Authorization':'Basic '+basic})
|
||||
statuses.append(r['status'])
|
||||
if r['status']==429:
|
||||
check(r['headers'].get('Retry-After')=='60','429 lacks Retry-After')
|
||||
break
|
||||
check(429 in statuses,'shared login limiter did not issue 429')
|
||||
check(c.call('GET','/api/v1/users/me',401,
|
||||
headers={'Authorization':'Bearer completely_invalid'})['status']==401,
|
||||
'invalid token accepted')
|
||||
print('PASS: trusted HTTPS+Bearer, X-User-Id spoof denied, logout revoked, shared 429, Retry-After')
|
||||
|
||||
if __name__=='__main__':run(main)
|
||||
Reference in New Issue
Block a user