Skip to content

Commit 6c0da5f

Browse files
committed
add failing test
1 parent 1c3472a commit 6c0da5f

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

test/plug_test.exs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,26 @@ defmodule Sentry.PlugTest do
105105
"is_admin" => false, "passwd" => "*********", "credit_card" => "*********", "cc" => "*********",
106106
"another_cc" => "*********", "user" => %{"password" => "*********"}}
107107
end
108+
109+
test "handles data scrubbing with file upload" do
110+
bypass = Bypass.open
111+
Bypass.expect bypass, fn conn ->
112+
{:ok, body, conn} = Plug.Conn.read_body(conn)
113+
json = Poison.decode!(body)
114+
assert is_map(json["request"]["data"]["image"])
115+
assert json["request"]["data"]["password"] == "*********"
116+
Plug.Conn.resp(conn, 200, ~s<{"id": "340"}>)
117+
end
118+
119+
modify_env(:sentry, dsn: "http://public:secret@localhost:#{bypass.port}/1")
120+
upload = %Plug.Upload{path: "test/fixtures/my_image.png", filename: "my_image.png"}
121+
122+
assert_raise(RuntimeError, "Error", fn ->
123+
conn(:post, "/error_route", %{"image" => upload, "password" => "my_password"})
124+
|> put_req_cookie("cookie_key", "cookie_value")
125+
|> put_req_header("accept-language", "en-US")
126+
|> put_req_header("authorization", "ignorme")
127+
|> Sentry.ExampleApp.call([])
128+
end)
129+
end
108130
end

test/support/test_plug.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ defmodule Sentry.ExampleApp do
1414
raise RuntimeError, "Error"
1515
end
1616

17+
post "/error_route" do
18+
_ = conn
19+
raise RuntimeError, "Error"
20+
end
21+
1722
match "/error_route" do
1823
_ = conn
1924
raise RuntimeError, "Error"

0 commit comments

Comments
 (0)