@@ -97,14 +97,47 @@ def app
97
97
end
98
98
99
99
describe "#callback_phase" do
100
- subject { fresh_strategy }
101
- it "calls fail with the client error received" do
102
- instance = subject . new ( "abc" , "def" )
100
+ subject ( :instance ) { fresh_strategy . new ( "abc" , "def" ) }
101
+
102
+ let ( :params ) { { "error_reason" => "user_denied" , "error" => "access_denied" , "state" => state } }
103
+ let ( :state ) { "secret" }
104
+
105
+ before do
103
106
allow ( instance ) . to receive ( :request ) do
104
- double ( "Request" , :params => { "error_reason" => "user_denied" , "error" => "access_denied" } )
107
+ double ( "Request" , :params => params )
108
+ end
109
+
110
+ allow ( instance ) . to receive ( :session ) do
111
+ double ( "Session" , :delete => state )
105
112
end
113
+ end
114
+
115
+ it "calls fail with the error received" do
116
+ expect ( instance ) . to receive ( :fail! ) . with ( "user_denied" , anything )
117
+
118
+ instance . callback_phase
119
+ end
120
+
121
+ it "calls fail with the error received if state is missing and CSRF verification is disabled" do
122
+ params [ "state" ] = nil
123
+ instance . options . provider_ignores_state = true
106
124
107
125
expect ( instance ) . to receive ( :fail! ) . with ( "user_denied" , anything )
126
+
127
+ instance . callback_phase
128
+ end
129
+
130
+ it "calls fail with a CSRF error if the state is missing" do
131
+ params [ "state" ] = nil
132
+
133
+ expect ( instance ) . to receive ( :fail! ) . with ( :csrf_detected , anything )
134
+ instance . callback_phase
135
+ end
136
+
137
+ it "calls fail with a CSRF error if the state is invalid" do
138
+ params [ "state" ] = "invalid"
139
+
140
+ expect ( instance ) . to receive ( :fail! ) . with ( :csrf_detected , anything )
108
141
instance . callback_phase
109
142
end
110
143
end
0 commit comments