L7-T9: Query matcher glob/any allows and denies as expected.
(
sandbox: Callable[..., Sandbox],
)
| 1206 | |
| 1207 | |
| 1208 | def test_l7_query_matchers_enforced( |
| 1209 | sandbox: Callable[..., Sandbox], |
| 1210 | ) -> None: |
| 1211 | """L7-T9: Query matcher glob/any allows and denies as expected.""" |
| 1212 | policy = _base_policy( |
| 1213 | network_policies={ |
| 1214 | "query_api": sandbox_pb2.NetworkPolicyRule( |
| 1215 | name="query_api", |
| 1216 | endpoints=[ |
| 1217 | sandbox_pb2.NetworkEndpoint( |
| 1218 | host=_SANDBOX_IP, |
| 1219 | port=_FORWARD_PROXY_PORT, |
| 1220 | protocol="rest", |
| 1221 | enforcement="enforce", |
| 1222 | allowed_ips=["10.200.0.0/24"], |
| 1223 | rules=[ |
| 1224 | sandbox_pb2.L7Rule( |
| 1225 | allow=sandbox_pb2.L7Allow( |
| 1226 | method="GET", |
| 1227 | path="/download", |
| 1228 | query={ |
| 1229 | "tag": sandbox_pb2.L7QueryMatcher(glob="foo-*"), |
| 1230 | }, |
| 1231 | ), |
| 1232 | ), |
| 1233 | sandbox_pb2.L7Rule( |
| 1234 | allow=sandbox_pb2.L7Allow( |
| 1235 | method="GET", |
| 1236 | path="/search", |
| 1237 | query={ |
| 1238 | "tag": sandbox_pb2.L7QueryMatcher( |
| 1239 | any=["foo-*", "bar-*"] |
| 1240 | ), |
| 1241 | }, |
| 1242 | ), |
| 1243 | ), |
| 1244 | ], |
| 1245 | ), |
| 1246 | ], |
| 1247 | binaries=[sandbox_pb2.NetworkBinary(path="/**")], |
| 1248 | ), |
| 1249 | }, |
| 1250 | ) |
| 1251 | spec = datamodel_pb2.SandboxSpec(policy=policy) |
| 1252 | with sandbox(spec=spec, delete_on_exit=True) as sb: |
| 1253 | allowed = sb.exec_python( |
| 1254 | _proxy_connect_then_http_with_server(), |
| 1255 | args=( |
| 1256 | _PROXY_HOST, |
| 1257 | _PROXY_PORT, |
| 1258 | _SANDBOX_IP, |
| 1259 | _FORWARD_PROXY_PORT, |
| 1260 | "GET", |
| 1261 | "/download?tag=foo-a&tag=foo-b", |
| 1262 | ), |
| 1263 | ) |
| 1264 | assert allowed.exit_code == 0, allowed.stderr |
| 1265 | allowed_resp = json.loads(allowed.stdout) |
nothing calls this directly
no test coverage detected