Skip to content

Commit

Permalink
Merge pull request #1770 from DFE-Digital/feedback-captcha
Browse files Browse the repository at this point in the history
Add invisible captcha protection to candidates feedback form
  • Loading branch information
leoapost authored Jun 15, 2021
2 parents ce5e774 + d087fb1 commit e3fee39
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ gem "get_into_teaching_api_client_faraday", github: "DFE-Digital/get-into-teachi
# Ignore cloudfront IPs when getting customer IP address
gem 'actionpack-cloudfront'

gem 'invisible_captcha'

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ GEM
httpclient (2.8.3)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
invisible_captcha (2.0.0)
rails (>= 5.0)
json (2.5.1)
json-jwt (1.13.0)
activesupport (>= 4.2)
Expand Down Expand Up @@ -596,6 +598,7 @@ DEPENDENCIES
geocoder
get_into_teaching_api_client_faraday!
govuk_elements_form_builder!
invisible_captcha
json (>= 2.3.0)
kaminari
listen (>= 3.0.5)
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/candidates/feedbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Candidates
class FeedbacksController < ApplicationController
invisible_captcha only: [:create], timestamp_threshold: 1.second

def show; end

def new
Expand Down
2 changes: 2 additions & 0 deletions app/views/feedbacks/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
</p>
<% end %>

<%= invisible_captcha %>

<%= f.submit 'Submit feedback' %>
<% end %>

Expand Down
5 changes: 5 additions & 0 deletions config/initializers/invisible_captcha.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
InvisibleCaptcha.setup do |config|
# Only enable in production so our automated integration
# tests don't fail.
config.timestamp_enabled = Rails.env.production?
end
17 changes: 17 additions & 0 deletions spec/features/feedback_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'rails_helper'

RSpec.feature "Feedback", type: :feature do
scenario "a bot submitting feedback (filling in the honeypot)" do
visit new_candidates_feedback_path

choose "Make a school experience request"
choose "Yes"
choose "Satisfied"
fill_in "If you are a human, ignore this field", with: "i-am-a-bot"

click_on "Submit feedback"

expect(page.status_code).to eq(200)
expect(page.body).to eq("")
end
end

0 comments on commit e3fee39

Please sign in to comment.