Skip to content

Commit

Permalink
test 'incomplete spamaway test does not create new user record', and …
Browse files Browse the repository at this point in the history
…fix users controller to prevent user creation in this scenario (publiclab#8467)

* test 'incomplete spamaway test does not create new user record'

* Update signup_flow_test.rb

* Update users_controller.rb

* Update users_controller.rb

* make blank field actually blank? otherwise 2 errors

* Update signup_flow_test.rb

* Update signup_flow_test.rb

* Update signup_flow_test.rb
  • Loading branch information
jywarren authored and wichanart committed Oct 26, 2021
1 parent 837e8f0 commit e781ca2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 1 addition & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def create
recaptcha = verify_recaptcha(model: @user) if using_recaptcha
@spamaway = Spamaway.new(spamaway_params) unless using_recaptcha

saved_user = @user.save
if ((@spamaway&.valid?) || recaptcha) && saved_user
if ((@spamaway&.valid?) || recaptcha) && @user.save # pass spamaway validation FIRST then try saving the user; https://github.com/publiclab/plots2/issues/8463
if current_user.crypted_password.nil? # the user has not created a pwd in the new site
flash[:warning] = I18n.t('users_controller.account_migrated_create_new_password')
redirect_to "/profile/edit"
Expand Down
18 changes: 18 additions & 0 deletions test/integration/signup_flow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ def setup
assert response.body.include? 'Email should look like an email address.'
end

test 'incomplete spamaway test does not create new user record, returns useful validation' do
assert_difference 'User.count', 0 do
post '/register', params: {
user: {
username: "newuser",
email: @new_user[:email],
password: @new_user[:password],
password_confirmation: @new_user[:password]
},
spamaway: {
follow_instructions: ""
}
}
end
assert response.body.include? '1 error prohibited this user from being saved'
assert response.body.include? "It doesn't seem like you are a real person! If you disagree or are having trouble, please see https://publiclab.org/registration-test."
end

test 'spamaway text area not blank error message' do
post '/register', params: {
user: {
Expand Down

0 comments on commit e781ca2

Please sign in to comment.