Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Bunting committed Jul 10, 2024
1 parent 7f3015d commit e330595
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/redaction/test_redact_by_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
keys=[
("responseBody.string", "ALLOW"),
("responseBody.other_string", "REDACT"),
("responseBody[].data[].string", "ALLOW"),
]
),
"config": get_config(redact_by_default=True),
Expand Down Expand Up @@ -47,3 +48,42 @@ def test_redact_by_default(self, httpserver, supergood_client):
assert filtered[0]["keyPath"] == "responseBody.other_string"
assert filtered[0]["type"] == "string"
assert filtered[0]["length"] == 3

# Test that allowed keys with array indexers are not redacted
def test_allowed_keys_of_arrays(self, httpserver, supergood_client):
httpserver.expect_request("/200").respond_with_json(
[
{
"data": [
{"string": "abc", "other_string": "sensitive"},
{"string": "abc", "other_string": "sensitive"},
]
}
]
)
requests.get(httpserver.url_for("/200"))
supergood_client.flush_cache()
args = Api.post_events.call_args[0][0]
response_body = args[0]["response"]["body"]
metadata = args[0]["metadata"]
assert len(response_body) == 1
assert len(response_body[0]["data"]) == 2
assert response_body[0]["data"][0]["string"] == "abc"
assert response_body[0]["data"][1]["string"] == "abc"

assert response_body[0]["data"][0]["other_string"] == None
assert response_body[0]["data"][1]["other_string"] == None

assert len(metadata["sensitiveKeys"]) > 0
# # There are a bunch of request/response headers. Filter for just responseBody
filtered = list(
filter(
lambda x: x["keyPath"].startswith("responseBody"),
metadata["sensitiveKeys"],
)
)
assert len(filtered) == 2
assert filtered[0]["keyPath"] == "responseBody[0].data[0].other_string"
assert filtered[1]["keyPath"] == "responseBody[0].data[1].other_string"
assert filtered[0]["type"] == "string" and filtered[1]["type"] == "string"
assert filtered[0]["length"] == 9 and filtered[1]["length"] == 9

0 comments on commit e330595

Please sign in to comment.