forked from alphagov/signon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request alphagov#2105 from alphagov/organisation-2sv-logic
Require 2SV for users from organisations where 2SV is mandatory
- Loading branch information
Showing
11 changed files
with
317 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<% content_for :title, "Create new user" %> | ||
|
||
<h1>2-step verification settings for new user</h1> | ||
|
||
<%= form_for @user, :html => {:class => 'well'} do |f| %> | ||
<%= f.hidden_field :skip_update_user_permissions, value: "true" %> | ||
<p class="checkbox"> | ||
<%= f.label :require_2sv do %> | ||
<%= f.check_box :require_2sv %> Mandate 2-step verification for this user <%= "(this will remove their exemption)" if @user.exempt_from_2sv? %> | ||
<% end %> | ||
<br/> | ||
User will be prompted to set up 2-step verification again the next time they sign in. | ||
</p> | ||
|
||
<%= f.submit "Update user", :class => 'btn btn-success' %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,20 @@ | |
organisation: gds, | ||
) | ||
|
||
test_organisation = Organisation.create!( | ||
name: "Test Organisation", | ||
test_organisation_without_2sv = Organisation.create!( | ||
name: "Test Organisation without mandatory 2SV", | ||
content_id: SecureRandom.uuid, | ||
organisation_type: :ministerial_department, | ||
slug: "test-organisation", | ||
require_2sv: false, | ||
) | ||
|
||
test_organisation_with_2sv = Organisation.create!( | ||
name: "Test Organisation with mandatory 2SV", | ||
content_id: SecureRandom.uuid, | ||
organisation_type: :ministerial_department, | ||
slug: "test-organisation-with-2sv", | ||
require_2sv: true, | ||
) | ||
|
||
User.create!( | ||
|
@@ -29,7 +38,7 @@ | |
password: "6fe552ca-d406-4c54-b7a6-041ed1ade6cd", | ||
role: :normal, | ||
confirmed_at: Time.zone.now, | ||
organisation: test_organisation, | ||
organisation: test_organisation_without_2sv, | ||
) | ||
|
||
# The following user has 2SV enabled by default. Scan the QR code with your authenticator app to generate a code to login. | ||
|
@@ -65,7 +74,18 @@ | |
password: "6fe552ca-d406-4c54-b7a6-041ed1ade6cd", | ||
role: :normal, | ||
confirmed_at: Time.zone.now, | ||
organisation: test_organisation, | ||
organisation: test_organisation_without_2sv, | ||
require_2sv: true, | ||
otp_secret_key: "I5X6Y3VN3CAATYQRBPAZ7KMFLK2RWYJ5", | ||
) | ||
|
||
User.create!( | ||
name: "Test User from organisation with mandatory 2SV", | ||
email: "[email protected]", | ||
password: "6fe552ca-d406-4c54-b7a6-041ed1ade6cd", | ||
role: :normal, | ||
confirmed_at: Time.zone.now, | ||
organisation: test_organisation_with_2sv, | ||
require_2sv: true, | ||
otp_secret_key: "I5X6Y3VN3CAATYQRBPAZ7KMFLK2RWYJ5", | ||
) | ||
|
@@ -79,3 +99,13 @@ | |
confirmed_at: Time.zone.now, | ||
require_2sv: false, | ||
) | ||
|
||
application = Doorkeeper::Application.create!( | ||
name: "Test Application 1", | ||
redirect_uri: "https://www.gov.uk", | ||
) | ||
|
||
SupportedPermission.create!( | ||
name: "Editor", | ||
application:, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
class InvitationsControllerTest < ActionController::TestCase | ||
setup do | ||
request.env["devise.mapping"] = Devise.mappings[:user] | ||
@user = create(:admin_user) | ||
@user = create(:superadmin_user) | ||
sign_in @user | ||
end | ||
|
||
|
@@ -60,6 +60,42 @@ class InvitationsControllerTest < ActionController::TestCase | |
post :create, params: { user: { name: "Testing Org Admins", email: "[email protected]" } } | ||
assert_redirected_to root_path | ||
end | ||
|
||
should "save user and render 2SV form when user assigned to organisation that does not require 2SV" do | ||
organisation = create(:organisation, require_2sv: false) | ||
|
||
post :create, params: { user: { name: "User Name", email: "[email protected]", organisation_id: organisation.id } } | ||
|
||
assert_redirected_to require_2sv_user_path(User.last) | ||
assert_equal "User Name", User.last.name | ||
end | ||
|
||
should "save user and not render 2SV form when user assigned to organisation that requires 2SV" do | ||
organisation = create(:organisation, require_2sv: true) | ||
|
||
post :create, params: { user: { name: "User Name", email: "[email protected]", organisation_id: organisation.id } } | ||
|
||
assert_redirected_to users_path | ||
assert_equal "User Name", User.last.name | ||
end | ||
|
||
should "not render 2SV form and saves user when user is a superadmin" do | ||
organisation = create(:organisation, require_2sv: false) | ||
|
||
post :create, params: { user: { name: "User Name", email: "[email protected]", organisation_id: organisation.id, role: "superadmin" } } | ||
|
||
assert_redirected_to users_path | ||
assert_equal "User Name", User.last.name | ||
end | ||
|
||
should "not render 2SV form and saves user when user is an admin" do | ||
organisation = create(:organisation, require_2sv: false) | ||
|
||
post :create, params: { user: { name: "User Name", email: "[email protected]", organisation_id: organisation.id, role: "admin" } } | ||
|
||
assert_redirected_to users_path | ||
assert_equal "User Name", User.last.name | ||
end | ||
end | ||
|
||
context "POST resend" do | ||
|
Oops, something went wrong.