]> git.openstreetmap.org Git - rails.git/blobdiff - test/controllers/users_controller_test.rb
Prevent CSRF bypass updating account details
[rails.git] / test / controllers / users_controller_test.rb
index c21f820469b42844242ce4cebf76dc8b7ea218a8..02e5db7db25dd54d5cd3ae5d19f85817040fca82 100644 (file)
@@ -949,6 +949,14 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
       assert_equal "/user/#{ERB::Util.u(user.display_name)}/account", form.attr("action").to_s
     end
 
+    # Updating the description using GET should fail
+    user.description = "new description"
+    user.preferred_editor = "default"
+    get user_account_path(user), :params => { :user => user.attributes }
+    assert_response :success
+    assert_template :account
+    assert_not_equal user.description, User.find(user.id).description
+
     # Updating the description should work
     user.description = "new description"
     user.preferred_editor = "default"
@@ -958,9 +966,8 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
     get user_account_path(user)
     assert_response :success
     assert_template :account
-    assert_select "div#errorExplanation", false
     assert_select ".notice", /^User information updated successfully/
-    assert_select "form#accountForm > fieldset > div.standard-form-row > div#user_description_container > div#user_description_content > textarea#user_description", user.description
+    assert_select "form#accountForm > div.form-group > div#user_description_container > div#user_description_content > textarea#user_description", user.description
 
     # Changing to a invalid editor should fail
     user.preferred_editor = "unknown"
@@ -968,8 +975,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
     assert_response :success
     assert_template :account
     assert_select ".notice", false
-    assert_select "div#errorExplanation"
-    assert_select "form#accountForm > fieldset > div.standard-form-row > select#user_preferred_editor > option[selected]", false
+    assert_select "form#accountForm > div.form-group > select#user_preferred_editor > option[selected]", false
 
     # Changing to a valid editor should work
     user.preferred_editor = "id"
@@ -979,9 +985,8 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
     get user_account_path(user)
     assert_response :success
     assert_template :account
-    assert_select "div#errorExplanation", false
     assert_select ".notice", /^User information updated successfully/
-    assert_select "form#accountForm > fieldset > div.standard-form-row > select#user_preferred_editor > option[selected][value=?]", "id"
+    assert_select "form#accountForm > div.form-group > select#user_preferred_editor > option[selected][value=?]", "id"
 
     # Changing to the default editor should work
     user.preferred_editor = "default"
@@ -991,9 +996,8 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
     get user_account_path(user)
     assert_response :success
     assert_template :account
-    assert_select "div#errorExplanation", false
     assert_select ".notice", /^User information updated successfully/
-    assert_select "form#accountForm > fieldset > div.standard-form-row > select#user_preferred_editor > option[selected]", false
+    assert_select "form#accountForm > div.form-group > select#user_preferred_editor > option[selected]", false
 
     # Changing to an uploaded image should work
     image = Rack::Test::UploadedFile.new("test/gpx/fixtures/a.gif", "image/gif")
@@ -1003,9 +1007,8 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
     get user_account_path(user)
     assert_response :success
     assert_template :account
-    assert_select "div#errorExplanation", false
     assert_select ".notice", /^User information updated successfully/
-    assert_select "form#accountForm > fieldset > div.standard-form-row.accountImage input[name=avatar_action][checked][value=?]", "keep"
+    assert_select "form#accountForm > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-check > input[name=avatar_action][checked][value=?]", "keep"
 
     # Changing to a gravatar image should work
     post user_account_path(user), :params => { :avatar_action => "gravatar", :user => user.attributes }
@@ -1014,9 +1017,8 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
     get user_account_path(user)
     assert_response :success
     assert_template :account
-    assert_select "div#errorExplanation", false
     assert_select ".notice", /^User information updated successfully/
-    assert_select "form#accountForm > fieldset > div.standard-form-row.accountImage input[name=avatar_action][checked][value=?]", "gravatar"
+    assert_select "form#accountForm > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-group > div.form-check > input[name=avatar_action][checked][value=?]", "gravatar"
 
     # Removing the image should work
     post user_account_path(user), :params => { :avatar_action => "delete", :user => user.attributes }
@@ -1025,9 +1027,9 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
     get user_account_path(user)
     assert_response :success
     assert_template :account
-    assert_select "div#errorExplanation", false
     assert_select ".notice", /^User information updated successfully/
-    assert_select "form#accountForm > fieldset > div.standard-form-row.accountImage input[name=avatar_action][checked]", false
+    assert_select "form#accountForm > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-check > input[name=avatar_action][checked]", false
+    assert_select "form#accountForm > fieldset.form-group > div.form-row > div.col-sm-10 > div.form-group > div.form-check > input[name=avatar_action][checked]", false
 
     # Adding external authentication should redirect to the auth provider
     post user_account_path(user), :params => { :user => user.attributes.merge(:auth_provider => "openid", :auth_uid => "gmail.com") }
@@ -1040,8 +1042,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
     assert_response :success
     assert_template :account
     assert_select ".notice", false
-    assert_select "div#errorExplanation"
-    assert_select "form#accountForm > fieldset > div.standard-form-row > input.field_with_errors#user_display_name"
+    assert_select "form#accountForm > div.form-group > input.is-invalid#user_display_name"
 
     # Changing name to one that exists should fail, regardless of case
     new_attributes = user.attributes.dup.merge(:display_name => create(:user).display_name.upcase)
@@ -1049,8 +1050,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
     assert_response :success
     assert_template :account
     assert_select ".notice", false
-    assert_select "div#errorExplanation"
-    assert_select "form#accountForm > fieldset > div.standard-form-row > input.field_with_errors#user_display_name"
+    assert_select "form#accountForm > div.form-group > input.is-invalid#user_display_name"
 
     # Changing name to one that doesn't exist should work
     new_attributes = user.attributes.dup.merge(:display_name => "new tester")
@@ -1060,9 +1060,8 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
     get user_account_path(:display_name => "new tester")
     assert_response :success
     assert_template :account
-    assert_select "div#errorExplanation", false
     assert_select ".notice", /^User information updated successfully/
-    assert_select "form#accountForm > fieldset > div.standard-form-row > input#user_display_name[value=?]", "new tester"
+    assert_select "form#accountForm > div.form-group > input#user_display_name[value=?]", "new tester"
 
     # Record the change of name
     user.display_name = "new tester"
@@ -1077,8 +1076,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
     assert_response :success
     assert_template :account
     assert_select ".notice", false
-    assert_select "div#errorExplanation"
-    assert_select "form#accountForm > fieldset > div.standard-form-row > input.field_with_errors#user_new_email"
+    assert_select "form#accountForm > div.form-group > input.is-invalid#user_new_email"
 
     # Changing email to one that exists should fail, regardless of case
     user.new_email = create(:user).email.upcase
@@ -1090,8 +1088,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
     assert_response :success
     assert_template :account
     assert_select ".notice", false
-    assert_select "div#errorExplanation"
-    assert_select "form#accountForm > fieldset > div.standard-form-row > input.field_with_errors#user_new_email"
+    assert_select "form#accountForm > div.form-group > input.is-invalid#user_new_email"
 
     # Changing email to one that doesn't exist should work
     user.new_email = "new_tester@example.com"
@@ -1105,9 +1102,8 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
     get user_account_path(user)
     assert_response :success
     assert_template :account
-    assert_select "div#errorExplanation", false
     assert_select ".notice", /^User information updated successfully/
-    assert_select "form#accountForm > fieldset > div.standard-form-row > input#user_new_email[value=?]", user.new_email
+    assert_select "form#accountForm > div.form-group > input#user_new_email[value=?]", user.new_email
     email = ActionMailer::Base.deliveries.first
     assert_equal 1, email.to.count
     assert_equal user.new_email, email.to.first