@@ -34,6 +34,22 @@ defmodule Sentry.PlugCaptureTest do
3434 plug PhoenixRouter
3535 end
3636
37+ defmodule Scrubber do
38+ def scrub_conn ( conn ) do
39+ conn
40+ end
41+ end
42+
43+ defmodule PhoenixEndpointWithScrubber do
44+ use Sentry.PlugCapture , scrubber: { Scrubber , :scrub_conn , [ ] }
45+ use Phoenix.Endpoint , otp_app: :sentry
46+ use Plug.Debugger , otp_app: :sentry
47+
48+ plug Plug.Parsers , parsers: [ :json ] , pass: [ "*/*" ] , json_decoder: Jason
49+ plug Sentry.PlugContext
50+ plug PhoenixRouter
51+ end
52+
3753 setup do
3854 bypass = Bypass . open ( )
3955 put_test_config ( dsn: "http://public:secret@localhost:#{ bypass . port } /1" )
@@ -239,6 +255,33 @@ defmodule Sentry.PlugCaptureTest do
239255 |> call_phoenix_endpoint ( )
240256 end
241257 end
258+
259+ test "modifies conn with custom scrubber" , % { bypass: bypass } do
260+ Application . put_env ( :sentry , PhoenixEndpointWithScrubber ,
261+ render_errors: [ view: Sentry.ErrorView , accepts: ~w( html) ]
262+ )
263+
264+ pid = start_supervised! ( PhoenixEndpointWithScrubber )
265+ Process . link ( pid )
266+
267+ Bypass . expect ( bypass , fn conn ->
268+ { :ok , body , conn } = Plug.Conn . read_body ( conn )
269+
270+ event = decode_event_from_envelope! ( body )
271+
272+ assert event [ "culprit" ] == "Sentry.PlugCaptureTest.PhoenixController.error/2"
273+
274+ assert List . first ( event [ "exception" ] ) [ "type" ] == "RuntimeError"
275+ assert List . first ( event [ "exception" ] ) [ "value" ] == "PhoenixError"
276+
277+ Plug.Conn . resp ( conn , 200 , ~s< {"id": "340"}> )
278+ end )
279+
280+ assert_raise RuntimeError , "PhoenixError" , fn ->
281+ conn ( :get , "/error_route" )
282+ |> Plug . run ( [ { PhoenixEndpointWithScrubber , [ ] } ] )
283+ end
284+ end
242285 end
243286
244287 defp call_plug_app ( conn ) , do: Plug . run ( conn , [ { Sentry.ExamplePlugApplication , [ ] } ] )
0 commit comments