forked from mtusi2026/mtusi2026lab7
ЛР 7: реализация мессенджера и сценарии проверки
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"""Verify repeatable login limiting over the HTTPS ingress."""
|
||||
|
||||
import argparse
|
||||
import base64
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT / "tests"))
|
||||
from client import Client, check
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--base-url", default="https://localhost:8443")
|
||||
parser.add_argument("--ca-file", default=ROOT / "certs/private/ca.crt")
|
||||
args = parser.parse_args()
|
||||
c = Client(args.base_url, str(args.ca_file))
|
||||
user = c.user("ratelimit")
|
||||
name = user["registration"]["username"]
|
||||
authorization = base64.b64encode((name + ":synthetic-wrong-password").encode()).decode()
|
||||
outcomes = []
|
||||
for _ in range(9):
|
||||
reply = c.call("POST", "/api/v1/auth/sessions", (401, 429),
|
||||
headers={"Authorization": "Basic " + authorization})
|
||||
outcomes.append(reply["status"])
|
||||
if reply["status"] == 429:
|
||||
check(int(reply["headers"]["Retry-After"]) > 0, "missing retry interval")
|
||||
check(outcomes[:7] == [401] * 7 and outcomes[7:] == [429, 429],
|
||||
f"unexpected shared login limit: {outcomes}")
|
||||
print("PASS: 401 for wrong passwords, then shared 429/Retry-After over HTTPS")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user