|
223 | 223 |
|
224 | 224 | end |
225 | 225 |
|
| 226 | + context "with reCAPTCHA" do |
| 227 | + it "should not check a reCAPTCHA response unless recaptcha_secret is set" do |
| 228 | + checked = false |
| 229 | + out = nil |
| 230 | + |
| 231 | + stub_request(:any, /verify/).to_return { |request| |
| 232 | + checked = true |
| 233 | + { status: 200, body: '{"success":false}' } |
| 234 | + } |
| 235 | + |
| 236 | + expect { |
| 237 | + out= agent.receive_web_request({ 'secret' => 'foobar', 'some_key' => payload }, "post", "text/html") |
| 238 | + }.not_to change { checked } |
| 239 | + |
| 240 | + expect(out).to eq(["Event Created", 201]) |
| 241 | + end |
| 242 | + |
| 243 | + it "should reject a request if recaptcha_secret is set but g-recaptcha-response is not given" do |
| 244 | + agent.options['recaptcha_secret'] = 'supersupersecret' |
| 245 | + |
| 246 | + checked = false |
| 247 | + out = nil |
| 248 | + |
| 249 | + stub_request(:any, /verify/).to_return { |request| |
| 250 | + checked = true |
| 251 | + { status: 200, body: '{"success":false}' } |
| 252 | + } |
| 253 | + |
| 254 | + expect { |
| 255 | + out = agent.receive_web_request({ 'secret' => 'foobar', 'some_key' => payload }, "post", "text/html") |
| 256 | + }.not_to change { checked } |
| 257 | + |
| 258 | + expect(out).to eq(["Not Authorized", 401]) |
| 259 | + end |
| 260 | + |
| 261 | + it "should reject a request if recaptcha_secret is set and g-recaptcha-response given is not verified" do |
| 262 | + agent.options['recaptcha_secret'] = 'supersupersecret' |
| 263 | + |
| 264 | + checked = false |
| 265 | + out = nil |
| 266 | + |
| 267 | + stub_request(:any, /verify/).to_return { |request| |
| 268 | + checked = true |
| 269 | + { status: 200, body: '{"success":false}' } |
| 270 | + } |
| 271 | + |
| 272 | + expect { |
| 273 | + out = agent.receive_web_request({ 'secret' => 'foobar', 'some_key' => payload, 'g-recaptcha-response' => 'somevalue' }, "post", "text/html") |
| 274 | + }.to change { checked } |
| 275 | + |
| 276 | + expect(out).to eq(["Not Authorized", 401]) |
| 277 | + end |
| 278 | + |
| 279 | + it "should accept a request if recaptcha_secret is set and g-recaptcha-response given is verified" do |
| 280 | + agent.options['payload_path'] = '.' |
| 281 | + agent.options['recaptcha_secret'] = 'supersupersecret' |
| 282 | + |
| 283 | + checked = false |
| 284 | + out = nil |
| 285 | + |
| 286 | + stub_request(:any, /verify/).to_return { |request| |
| 287 | + checked = true |
| 288 | + { status: 200, body: '{"success":true}' } |
| 289 | + } |
| 290 | + |
| 291 | + expect { |
| 292 | + out = agent.receive_web_request(payload.merge({ 'secret' => 'foobar', 'g-recaptcha-response' => 'somevalue' }), "post", "text/html") |
| 293 | + }.to change { checked } |
| 294 | + |
| 295 | + expect(out).to eq(["Event Created", 201]) |
| 296 | + expect(Event.last.payload).to eq(payload) |
| 297 | + end |
| 298 | + end |
| 299 | + |
226 | 300 | end |
227 | 301 |
|
228 | 302 | end |
|
0 commit comments