feat: complete lab 7 grade 4 security controls and report
This commit is contained in:
@@ -13,7 +13,7 @@ import http.client
|
||||
TLS = Path(__file__).resolve().parents[1] / "secrets/tls"
|
||||
|
||||
|
||||
def query(service, port, path, params):
|
||||
def query(service, port, path, params, *, allow_missing=False):
|
||||
context = ssl.create_default_context(cafile=str(TLS / "lab7-ca.crt"))
|
||||
context.load_cert_chain(TLS / "grafana-reader.crt", TLS / "grafana-reader.key")
|
||||
container = subprocess.check_output(["docker", "compose", "ps", "-q", service], text=True).strip()
|
||||
@@ -26,6 +26,8 @@ def query(service, port, path, params):
|
||||
try:
|
||||
connection.request("GET", f"{path}?{urlencode(params)}")
|
||||
response = connection.getresponse()
|
||||
if allow_missing and response.status == 404:
|
||||
return None
|
||||
assert response.status == 200, (service, response.status)
|
||||
return json.load(response)
|
||||
finally:
|
||||
@@ -35,7 +37,7 @@ def query(service, port, path, params):
|
||||
def main():
|
||||
try:
|
||||
with urlopen("https://localhost:8443/api/v1/users/me", context=ssl.create_default_context(
|
||||
cafile=str(TLS / "lab7-ca.crt")), timeout=5):
|
||||
cafile=str(TLS / "lab7-ingress-ca.crt")), timeout=5):
|
||||
raise AssertionError("Anonymous request should be rejected")
|
||||
except HTTPError as error:
|
||||
assert error.code == 401
|
||||
|
||||
Reference in New Issue
Block a user