Skip to content

Commit 255ceae

Browse files
committed
test(policy): report forward graphql deny details
1 parent fdbe03a commit 255ceae

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

crates/openshell-sandbox/src/proxy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2799,7 +2799,7 @@ async fn handle_forward_proxy(
27992799
403,
28002800
"Forbidden",
28012801
"policy_denied",
2802-
&format!("{method} {host_lc}:{port}{path} denied by L7 policy"),
2802+
&format!("{method} {host_lc}:{port}{path} denied by L7 policy: {reason}"),
28032803
),
28042804
)
28052805
.await?;

e2e/rust/tests/forward_proxy_graphql_l7.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ import urllib.request
223223
224224
HOST = "host.openshell.internal"
225225
PORT = {port}
226+
DETAILS = {{}}
226227
227228
QUERY_VIEWER = "query Viewer {{ viewer {{ login }} }}"
228229
QUERY_REPOSITORY = "query Repo {{ repository(owner:\"o\", name:\"r\") {{ id }} }}"
@@ -317,7 +318,8 @@ def forward_chunked_status(query):
317318
).encode() + chunk
318319
sock.sendall(request)
319320
sock.shutdown(socket.SHUT_WR)
320-
response = read_until(sock, b"\r\n\r\n")
321+
response, body = read_response(sock)
322+
DETAILS["forward_chunked_query_allowed_detail"] = body.decode(errors="replace")
321323
return int(response.split()[1])
322324
323325
def read_until(sock, marker):
@@ -329,6 +331,21 @@ def read_until(sock, marker):
329331
data += chunk
330332
return data
331333
334+
def read_response(sock):
335+
response = read_until(sock, b"\r\n\r\n")
336+
headers, _, body = response.partition(b"\r\n\r\n")
337+
content_length = 0
338+
for line in headers.split(b"\r\n")[1:]:
339+
if line.lower().startswith(b"content-length:"):
340+
content_length = int(line.split(b":", 1)[1].strip())
341+
break
342+
while len(body) < content_length:
343+
chunk = sock.recv(4096)
344+
if not chunk:
345+
break
346+
body += chunk
347+
return response, body
348+
332349
def connect_status(query):
333350
proxy_host, proxy_port = connect_proxy_parts()
334351
target = f"{{HOST}}:{{PORT}}"
@@ -476,6 +493,7 @@ results = {{
476493
"connect_mutation_allowed": connect_status(MUTATION_CREATE),
477494
"connect_deny_rule_denied": connect_status(MUTATION_DELETE),
478495
}}
496+
results.update(DETAILS)
479497
print(json.dumps(results, sort_keys=True))
480498
"#,
481499
port = server.port,

0 commit comments

Comments
 (0)