@@ -2,38 +2,27 @@ defmodule Sentry.PlugTest do
22 use ExUnit.Case
33 use Plug.Test
44 import Sentry.TestEnvironmentHelper
5+ alias Sentry.TestPlugApplications
56
67 test "non-existent route exceptions are ignored" do
7- exception = % FunctionClauseError { arity: 4 , function: :do_match , module: Sentry.ExampleApp }
8+ exception = % FunctionClauseError {
9+ arity: 4 ,
10+ function: :do_match ,
11+ module: TestPlugApplications.Example
12+ }
813
914 assert ^ exception =
1015 assert_raise (
1116 FunctionClauseError ,
12- "no function clause matching in Sentry.ExampleApp .do_match/4" ,
17+ "no function clause matching in Sentry.TestPlugApplications.Example .do_match/4" ,
1318 fn ->
1419 conn ( :get , "/not_found" )
15- |> Sentry.ExampleApp . call ( [ ] )
20+ |> TestPlugApplications.Example . call ( [ ] )
1621 end
1722 )
1823 end
1924
2025 test "overriding handle_errors/2" do
21- Code . compile_string ( """
22- defmodule OverrideApp do
23- use Plug.Router
24- use Plug.ErrorHandler
25- use Sentry.Plug
26- plug :match
27- plug :dispatch
28- forward("/", to: Sentry.ExampleApp)
29-
30- defp handle_errors(conn, %{kind: _kind, reason: _reason, stack: _stack} = error) do
31- super(conn, error)
32- send_resp(conn, conn.status, "Something went terribly wrong")
33- end
34- end
35- """ )
36-
3726 bypass = Bypass . open ( )
3827
3928 Bypass . expect ( bypass , fn conn ->
@@ -45,24 +34,13 @@ defmodule Sentry.PlugTest do
4534 conn = conn ( :post , "/error_route" , % { } )
4635
4736 assert_raise ( Plug.Conn.WrapperError , "** (RuntimeError) Error" , fn ->
48- OverrideApp . call ( conn , [ ] )
37+ TestPlugApplications.Override . call ( conn , [ ] )
4938 end )
5039
5140 assert { 500 , _headers , "Something went terribly wrong" } = sent_resp ( conn )
5241 end
5342
5443 test "default data scrubbing" do
55- Code . compile_string ( """
56- defmodule DefaultConfigApp do
57- use Plug.Router
58- use Plug.ErrorHandler
59- use Sentry.Plug
60- plug :match
61- plug :dispatch
62- forward("/", to: Sentry.ExampleApp)
63- end
64- """ )
65-
6644 bypass = Bypass . open ( )
6745
6846 Bypass . expect ( bypass , fn conn ->
@@ -91,22 +69,11 @@ defmodule Sentry.PlugTest do
9169 |> put_req_header ( "authorization" , "secrets" )
9270 |> put_req_header ( "authentication" , "secrets" )
9371 |> put_req_header ( "content-type" , "application/json" )
94- |> DefaultConfigApp . call ( [ ] )
72+ |> TestPlugApplications.DefaultConfig . call ( [ ] )
9573 end )
9674 end
9775
9876 test "handles data scrubbing with file upload" do
99- Code . compile_string ( """
100- defmodule ScrubbingWithFileApp do
101- use Plug.Router
102- use Plug.ErrorHandler
103- use Sentry.Plug
104- plug :match
105- plug :dispatch
106- forward("/", to: Sentry.ExampleApp)
107- end
108- """ )
109-
11077 bypass = Bypass . open ( )
11178
11279 Bypass . expect ( bypass , fn conn ->
@@ -125,24 +92,11 @@ defmodule Sentry.PlugTest do
12592 |> put_req_cookie ( "cookie_key" , "cookie_value" )
12693 |> put_req_header ( "accept-language" , "en-US" )
12794 |> put_req_header ( "authorization" , "ignorme" )
128- |> ScrubbingWithFileApp . call ( [ ] )
95+ |> TestPlugApplications.ScrubbingWithFile . call ( [ ] )
12996 end )
13097 end
13198
13299 test "custom cookie scrubbing" do
133- Code . compile_string ( """
134- defmodule CustomCookieScrubberApp do
135- use Plug.Router
136- use Plug.ErrorHandler
137- use Sentry.Plug, cookie_scrubber: fn(conn) ->
138- Map.take(conn.req_cookies, ["regular"])
139- end
140- plug :match
141- plug :dispatch
142- forward("/", to: Sentry.ExampleApp)
143- end
144- """ )
145-
146100 bypass = Bypass . open ( )
147101
148102 Bypass . expect ( bypass , fn conn ->
@@ -158,22 +112,11 @@ defmodule Sentry.PlugTest do
158112 conn ( :get , "/error_route" )
159113 |> update_req_cookie ( "secret" , "secretvalue" )
160114 |> update_req_cookie ( "regular" , "value" )
161- |> CustomCookieScrubberApp . call ( [ ] )
115+ |> TestPlugApplications.CustomCookieScrubber . call ( [ ] )
162116 end )
163117 end
164118
165119 test "collects feedback" do
166- Code . compile_string ( """
167- defmodule CollectFeedbackApp do
168- use Plug.Router
169- use Plug.ErrorHandler
170- use Sentry.Plug, collect_feedback: [enabled: true, options: %{title: "abc-123"}]
171- plug :match
172- plug :dispatch
173- forward("/", to: Sentry.ExampleApp)
174- end
175- """ )
176-
177120 bypass = Bypass . open ( )
178121
179122 Bypass . expect ( bypass , fn conn ->
@@ -188,7 +131,7 @@ defmodule Sentry.PlugTest do
188131 |> Plug.Conn . put_req_header ( "accept" , "text/html" )
189132
190133 assert_raise ( Plug.Conn.WrapperError , "** (RuntimeError) Error" , fn ->
191- CollectFeedbackApp . call ( conn , [ ] )
134+ TestPlugApplications.CollectFeedback . call ( conn , [ ] )
192135 end )
193136
194137 assert_received { :plug_conn , :sent }
0 commit comments