|
| 1 | +defmodule Sentry.ScrubberTest do |
| 2 | + use ExUnit.Case, async: true |
| 3 | + |
| 4 | + alias Sentry.Scrubber |
| 5 | + |
| 6 | + describe "scrub_map/1" do |
| 7 | + test "redacts default sensitive keys" do |
| 8 | + assert Scrubber.scrub_map(%{"password" => "hunter2", "username" => "alice"}) == |
| 9 | + %{"password" => "*********", "username" => "alice"} |
| 10 | + |
| 11 | + assert Scrubber.scrub_map(%{"passwd" => "x", "secret" => "y", "ok" => "z"}) == |
| 12 | + %{"passwd" => "*********", "secret" => "*********", "ok" => "z"} |
| 13 | + end |
| 14 | + |
| 15 | + test "redacts credit card-like values" do |
| 16 | + assert Scrubber.scrub_map(%{"card" => "4111111111111111"}) == |
| 17 | + %{"card" => "*********"} |
| 18 | + end |
| 19 | + |
| 20 | + test "leaves non-sensitive data untouched" do |
| 21 | + data = %{"username" => "alice", "age" => 30, "active" => true} |
| 22 | + assert Scrubber.scrub_map(data) == data |
| 23 | + end |
| 24 | + |
| 25 | + test "recurses into nested maps" do |
| 26 | + assert Scrubber.scrub_map(%{"user" => %{"password" => "x", "name" => "alice"}}) == |
| 27 | + %{"user" => %{"password" => "*********", "name" => "alice"}} |
| 28 | + end |
| 29 | + |
| 30 | + test "recurses into lists of maps" do |
| 31 | + assert Scrubber.scrub_map(%{"users" => [%{"password" => "x"}, %{"password" => "y"}]}) == |
| 32 | + %{"users" => [%{"password" => "*********"}, %{"password" => "*********"}]} |
| 33 | + end |
| 34 | + |
| 35 | + test "recurses into structs by converting them to maps" do |
| 36 | + struct = %URI{scheme: "https", host: "example.com"} |
| 37 | + result = Scrubber.scrub_map(%{"uri" => struct}) |
| 38 | + assert result["uri"].host == "example.com" |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + describe "default_scrubbed_param_keys/0" do |
| 43 | + test "returns the default sensitive keys" do |
| 44 | + assert Scrubber.default_scrubbed_param_keys() == ["password", "passwd", "secret"] |
| 45 | + end |
| 46 | + end |
| 47 | + |
| 48 | + describe "scrubbed_value/0" do |
| 49 | + test "returns the placeholder value used for redacted data" do |
| 50 | + assert Scrubber.scrubbed_value() == "*********" |
| 51 | + end |
| 52 | + end |
| 53 | +end |
0 commit comments