diff options
Diffstat (limited to 'test/controllers')
| -rw-r--r-- | test/controllers/users_controller_test.rb | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/test/controllers/users_controller_test.rb b/test/controllers/users_controller_test.rb index b6f0970d..d7d8b9a6 100644 --- a/test/controllers/users_controller_test.rb +++ b/test/controllers/users_controller_test.rb | |||
| @@ -6,7 +6,7 @@ class UsersControllerTest < ActionController::TestCase | |||
| 6 | login_as :quentin | 6 | login_as :quentin |
| 7 | get :index | 7 | get :index |
| 8 | assert_redirected_to admin_path | 8 | assert_redirected_to admin_path |
| 9 | assert_equal I18n.t("flash.common.admin_required"), flash[:error] | 9 | assert_equal I18n.t("flash.common.redaktion_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 |
| @@ -53,7 +53,7 @@ class UsersControllerTest < ActionController::TestCase | |||
| 53 | assert !User.last.admin | 53 | assert !User.last.admin |
| 54 | end | 54 | end |
| 55 | 55 | ||
| 56 | test "creating new admin users being logged in as admin" do | 56 | test "creating a Redaktion account" do |
| 57 | login_as :aaron | 57 | login_as :aaron |
| 58 | elevate_session! | 58 | elevate_session! |
| 59 | assert_difference "User.count", +1 do | 59 | assert_difference "User.count", +1 do |
| @@ -63,13 +63,14 @@ class UsersControllerTest < ActionController::TestCase | |||
| 63 | :email => "foo@bar.com", | 63 | :email => "foo@bar.com", |
| 64 | :password => "xxxzzz", | 64 | :password => "xxxzzz", |
| 65 | :password_confirmation => "xxxzzz", | 65 | :password_confirmation => "xxxzzz", |
| 66 | :roles => ["admin", "redaktion"] | 66 | :roles => ["redaktion"] |
| 67 | } | 67 | } |
| 68 | } | 68 | } |
| 69 | end | 69 | end |
| 70 | 70 | ||
| 71 | assert_redirected_to user_path(User.last) | 71 | assert_redirected_to user_path(User.last) |
| 72 | assert User.last.admin | 72 | assert User.last.redaktion? |
| 73 | assert_not User.last.is_admin? | ||
| 73 | end | 74 | end |
| 74 | 75 | ||
| 75 | test "creating new users not being logged as regular user wont work" do | 76 | test "creating new users not being logged as regular user wont work" do |
| @@ -196,6 +197,7 @@ class UsersControllerTest < ActionController::TestCase | |||
| 196 | login_as :aaron | 197 | login_as :aaron |
| 197 | elevate_session! | 198 | elevate_session! |
| 198 | user = users(:quentin) | 199 | user = users(:quentin) |
| 200 | user.update_column(:otp_secret, ROTP::Base32.random) | ||
| 199 | put :update, params: { :id => user.id, :user => {:roles => ["admin", "redaktion"]} } | 201 | put :update, params: { :id => user.id, :user => {:roles => ["admin", "redaktion"]} } |
| 200 | 202 | ||
| 201 | assert_equal true, user.reload.is_admin? | 203 | assert_equal true, user.reload.is_admin? |
| @@ -261,4 +263,14 @@ class UsersControllerTest < ActionController::TestCase | |||
| 261 | 263 | ||
| 262 | assert_not user.reload.is_admin? | 264 | assert_not user.reload.is_admin? |
| 263 | end | 265 | end |
| 266 | |||
| 267 | test "an account without a second factor cannot be promoted to admin" do | ||
| 268 | login_as :aaron | ||
| 269 | elevate_session! | ||
| 270 | user = users(:quentin) | ||
| 271 | |||
| 272 | put :update, params: { :id => user.id, :user => { :roles => ["admin"] } } | ||
| 273 | |||
| 274 | assert_not user.reload.is_admin? | ||
| 275 | end | ||
| 264 | end | 276 | end |
