Skip to content

Commit 2bffa04

Browse files
committed
test(sandbox): fix binary mismatch in HEAD/POST test and add deny-rule regression
l7_head_denied_when_only_post_allowed used /bin/sh in the fixture but l7_input() sends /usr/bin/curl, so requests were denied by binary policy before the method rule could be evaluated. A regression allowing HEAD to match POST would have passed undetected. Fixes the fixture binary and adds l7_head_blocked_by_deny_rule_targeting_get to cover the deny_rules path of method_matches(), per review feedback. Signed-off-by: mesutoezdil <mesudozdil@gmail.com>
1 parent 398979a commit 2bffa04

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

  • crates/openshell-sandbox/src

crates/openshell-sandbox/src/opa.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4817,7 +4817,7 @@ network_policies:
48174817
fn l7_head_denied_when_only_post_allowed() {
48184818
let engine = OpaEngine::from_strings(
48194819
TEST_POLICY,
4820-
"network_policies:\n p:\n name: p\n endpoints:\n - host: h.test\n port: 80\n protocol: rest\n enforcement: enforce\n rules:\n - allow: {method: POST, path: \"/\"}\n binaries:\n - {path: /bin/sh}\n",
4820+
"network_policies:\n p:\n name: p\n endpoints:\n - host: h.test\n port: 80\n protocol: rest\n enforcement: enforce\n rules:\n - allow: {method: POST, path: \"/\"}\n binaries:\n - {path: /usr/bin/curl}\n",
48214821
)
48224822
.unwrap();
48234823
let input = l7_input("h.test", 80, "HEAD", "/");
@@ -4830,4 +4830,16 @@ network_policies:
48304830
let input = l7_input("api.example.com", 8080, "OPTIONS", "/repos/myorg/foo");
48314831
assert!(!eval_l7(&engine, &input));
48324832
}
4833+
4834+
#[test]
4835+
fn l7_head_blocked_by_deny_rule_targeting_get() {
4836+
// deny_rules use method_matches() too; a deny on GET must also block HEAD.
4837+
let engine = OpaEngine::from_strings(
4838+
TEST_POLICY,
4839+
"network_policies:\n p:\n name: p\n endpoints:\n - host: h.test\n port: 80\n protocol: rest\n enforcement: enforce\n access: full\n deny_rules:\n - method: GET\n path: \"/protected\"\n binaries:\n - {path: /usr/bin/curl}\n",
4840+
)
4841+
.unwrap();
4842+
let input = l7_input("h.test", 80, "HEAD", "/protected");
4843+
assert!(!eval_l7(&engine, &input));
4844+
}
48334845
}

0 commit comments

Comments
 (0)