Skip to content

Commit

Permalink
Merge pull request #2330 from alphagov/require-signin-after-accepting…
Browse files Browse the repository at this point in the history
…-invitation

Require user to sign in after accepting invitation
  • Loading branch information
mike29736 authored Aug 30, 2023
2 parents 3df4a3b + db825dc commit b6f5962
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
5 changes: 5 additions & 0 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@
# Default: false
config.validate_on_invite = true

# Auto-login after the user accepts the invite. If this is false,
# the user will need to manually log in after accepting the invite.
# Default: true
config.allow_insecure_sign_in_after_accept = false

# ==> Configuration for :confirmable
# A period that the user is allowed to access the website even without
# confirming their account. For instance, if set to 2.days, the user will be
Expand Down
2 changes: 0 additions & 2 deletions test/integration/email_change_test.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require "test_helper"
require "support/user_account_helpers"

class EmailChangeTest < ActionDispatch::IntegrationTest
include UserAccountHelpers
include ActiveJob::TestHelper

context "by an admin" do
Expand Down
22 changes: 19 additions & 3 deletions test/integration/inviting_users_test.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
require "test_helper"

class InvitingUsersTest < ActionDispatch::IntegrationTest
include EmailHelpers
include ActiveJob::TestHelper

should "send the user an invitation token" do
should "ask the invited user to set a password" do
user = User.invite!(name: "Jim", email: "jim@web.com")
visit accept_user_invitation_path(invitation_token: user.raw_invitation_token)

fill_in "New password", with: "this 1s 4 v3333ry s3cur3 p4ssw0rd.!Z"
fill_in "Confirm new password", with: "this 1s 4 v3333ry s3cur3 p4ssw0rd.!Z"
click_button "Save password"

assert_response_contains("You are now signed in")
assert_response_contains("Your password was set successfully.")
end

should "require the invited user to sign in after setting their password" do
user = User.invite!(name: "Neptuno Keighley", email: "neptuno.keighley@office.gov.uk")

accept_invitation(
invitation_token: user.raw_invitation_token,
password: "pretext annoying headpiece waviness header slinky",
)

assert_response_contains("Sign in to GOV.UK")

fill_in "Email", with: "neptuno.keighley@office.gov.uk"
fill_in "Password", with: "pretext annoying headpiece waviness header slinky"
click_button "Sign in"

assert_response_contains("Make your account more secure by setting up 2‑step verification.")
end

should "not send invitation token to Google Analytics" do
Expand Down
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def sign_out(_user)
require "support/managing_two_sv_helpers"
require "support/analytics_helpers"
require "support/html_table_helpers"
require "support/user_account_helpers"

class ActiveRecord::Base
mattr_accessor :shared_connection
Expand All @@ -94,6 +95,7 @@ class ActionDispatch::IntegrationTest
include EmailHelpers
include ConfirmationTokenHelpers
include AnalyticsHelpers
include UserAccountHelpers

def assert_response_contains(content)
assert page.has_content?(content), "Expected to find '#{content}' in:\n#{page.text}"
Expand Down

0 comments on commit b6f5962

Please sign in to comment.