diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-08-01 00:27:34 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-08-01 00:27:34 +0200 |
| commit | 8bcacace28df52fd972c54e6850aa3b93f5c8bdf (patch) | |
| tree | 05e90dd4e8f31ebb142f66239025da15e873901f /test/controllers/users_controller_test.rb | |
| parent | 529f81b28ed77c62acaa63fad957e751798f2440 (diff) | |
Declare role requirements per controller
RoleRequired supplies require_redaktion and require_admin for surfaces that
are not nodes and so cannot be reached by Node#restricted?.
Navigation is content rather than plumbing, so menu_items requires
redaktion. User management is janitorial and requires admin: index, new,
create, reset_otp, deactivate, reactivate. verify_status now also covers
show, without which any logged-in user could read any account by walking a
small id space. Editing your own account stays open.
The dashboard hides the Users and Navigation buttons from those who cannot
use them; everything else stays visible to everyone. Both denials share one
message and land on the dashboard.
Adds redella (redaktion) and alufa (redaktion + alumni) fixtures.
Diffstat (limited to 'test/controllers/users_controller_test.rb')
| -rw-r--r-- | test/controllers/users_controller_test.rb | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index 14133029..fe099928 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb | |||
| @@ -2,11 +2,11 @@ require 'test_helper' | |||
| 2 | 2 | ||
| 3 | class UsersControllerTest < ActionController::TestCase | 3 | class UsersControllerTest < ActionController::TestCase |
| 4 | 4 | ||
| 5 | test "get index as regular user renders stripped partial" do | 5 | test "an editor without admin cannot reach the user list" do |
| 6 | login_as :quentin | 6 | login_as :quentin |
| 7 | get :index | 7 | get :index |
| 8 | assert_response :success | 8 | assert_redirected_to admin_path |
| 9 | assert_select "a", { :count => 0, :text => "Destroy" } | 9 | assert_equal I18n.t("flash.common.admin_required"), flash[:error] |
| 10 | end | 10 | end |
| 11 | 11 | ||
| 12 | test "get index as admin shows every group with per-row actions" do | 12 | test "get index as admin shows every group with per-row actions" do |
| @@ -27,10 +27,10 @@ class UsersControllerTest < ActionController::TestCase | |||
| 27 | login_as :quentin | 27 | login_as :quentin |
| 28 | get :new | 28 | get :new |
| 29 | assert_response :redirect | 29 | assert_response :redirect |
| 30 | assert_redirected_to users_path | 30 | assert_redirected_to admin_path |
| 31 | assert_equal( | 31 | assert_equal( |
| 32 | I18n.t("flash.common.admin_required"), | 32 | I18n.t("flash.common.admin_required"), |
| 33 | flash[:notice] | 33 | flash[:error] |
| 34 | ) | 34 | ) |
| 35 | end | 35 | end |
| 36 | 36 | ||
| @@ -82,20 +82,20 @@ class UsersControllerTest < ActionController::TestCase | |||
| 82 | } | 82 | } |
| 83 | end | 83 | end |
| 84 | 84 | ||
| 85 | assert_redirected_to users_path | 85 | assert_redirected_to admin_path |
| 86 | assert_equal( | 86 | assert_equal( |
| 87 | I18n.t("flash.common.admin_required"), | 87 | I18n.t("flash.common.admin_required"), |
| 88 | flash[:notice] | 88 | flash[:error] |
| 89 | ) | 89 | ) |
| 90 | end | 90 | end |
| 91 | 91 | ||
| 92 | test "get edit of another user being logged in as regular user wont work" do | 92 | test "get edit of another user being logged in as regular user wont work" do |
| 93 | login_as :quentin | 93 | login_as :quentin |
| 94 | get :edit, params: { :id => User.find_by_login("aaron").id } | 94 | get :edit, params: { :id => User.find_by_login("aaron").id } |
| 95 | assert_redirected_to users_path | 95 | assert_redirected_to admin_path |
| 96 | assert_equal( | 96 | assert_equal( |
| 97 | I18n.t("flash.common.admin_required"), | 97 | I18n.t("flash.common.admin_required"), |
| 98 | flash[:notice] | 98 | flash[:error] |
| 99 | ) | 99 | ) |
| 100 | end | 100 | end |
| 101 | 101 | ||
| @@ -115,10 +115,10 @@ class UsersControllerTest < ActionController::TestCase | |||
| 115 | user = User.find_by_login("aaron") | 115 | user = User.find_by_login("aaron") |
| 116 | login_as :quentin | 116 | login_as :quentin |
| 117 | put :update, params: { :id => user.id, :user => {:login => "random"} } | 117 | put :update, params: { :id => user.id, :user => {:login => "random"} } |
| 118 | assert_redirected_to users_path | 118 | assert_redirected_to admin_path |
| 119 | assert_equal( | 119 | assert_equal( |
| 120 | I18n.t("flash.common.admin_required"), | 120 | I18n.t("flash.common.admin_required"), |
| 121 | flash[:notice] | 121 | flash[:error] |
| 122 | ) | 122 | ) |
| 123 | end | 123 | end |
| 124 | 124 | ||
| @@ -140,7 +140,7 @@ class UsersControllerTest < ActionController::TestCase | |||
| 140 | 140 | ||
| 141 | test "showing a user" do | 141 | test "showing a user" do |
| 142 | login_as :quentin | 142 | login_as :quentin |
| 143 | get :show, params: { :id => User.find_by_login("aaron").id } | 143 | get :show, params: { :id => users(:quentin).id } |
| 144 | assert_response :success | 144 | assert_response :success |
| 145 | end | 145 | end |
| 146 | 146 | ||
| @@ -148,7 +148,7 @@ class UsersControllerTest < ActionController::TestCase | |||
| 148 | login_as :quentin | 148 | login_as :quentin |
| 149 | put :deactivate, params: { :id => users(:quentin).id } | 149 | put :deactivate, params: { :id => users(:quentin).id } |
| 150 | 150 | ||
| 151 | assert_redirected_to users_path | 151 | assert_redirected_to admin_path |
| 152 | assert_not users(:quentin).reload.alumni? | 152 | assert_not users(:quentin).reload.alumni? |
| 153 | end | 153 | end |
| 154 | 154 | ||
| @@ -227,4 +227,16 @@ class UsersControllerTest < ActionController::TestCase | |||
| 227 | assert_response :success | 227 | assert_response :success |
| 228 | assert_select "h2", :text => /#{I18n.t("users.index.group_alumni")}/ | 228 | assert_select "h2", :text => /#{I18n.t("users.index.group_alumni")}/ |
| 229 | end | 229 | end |
| 230 | |||
| 231 | test "an editor without admin cannot create accounts" do | ||
| 232 | login_as :quentin | ||
| 233 | get :new | ||
| 234 | assert_redirected_to admin_path | ||
| 235 | end | ||
| 236 | |||
| 237 | test "an editor cannot read another account by id" do | ||
| 238 | login_as :quentin | ||
| 239 | get :show, params: { :id => users(:aaron).id } | ||
| 240 | assert_redirected_to admin_path | ||
| 241 | end | ||
| 230 | end | 242 | end |
