Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/admin/api/buyers_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create
authorize! :create, user

user.unflattened_attributes = flat_params
user.signup_type = :api
user.signup_type = :created_by_provider
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users created via API will have the :created_by_provider type from now on. However, we still have about 50k users in the DB with the :api type, and I don't plan to migrate them in any way. See other my other comments to see how I handled this.


user.save

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/api/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def create
authorize! :create, user

user.unflattened_attributes = flat_params
user.signup_type = :api
user.signup_type = :created_by_provider

user.save

Expand Down
14 changes: 3 additions & 11 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,6 @@ def minimal_signup?
signup.minimal?
end

def api_signup?
signup.api?
end

Comment on lines -240 to -243
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, and api? are not called from anywhere now. Can can cleanup them.

def cas_signup?
signup.cas?
end
Expand Down Expand Up @@ -437,10 +433,6 @@ def minimal?
signup_type == :minimal
end

def api?
signup_type == :api
end

def open_id?
@user.open_id.present?
end
Expand All @@ -450,19 +442,19 @@ def oauth2?
end

def created_by_provider?
signup_type == :created_by_provider
%i[created_by_provider api].include?(signup_type)
end

def cas?
@user.cas_identifier.present?
end

def machine?
minimal? || api? || created_by_provider? || open_id? || cas? || oauth2?
minimal? || created_by_provider? || open_id? || cas? || oauth2?
end

def by_user?
not machine?
!machine?
end

private
Expand Down
11 changes: 11 additions & 0 deletions test/functional/partners/providers_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ def provider_params
assert_equal true, body['success']
end

test 'post without password or open_id rejected' do
prepare_master_account
post :create, params: provider_params.except(:open_id)

assert_response :unprocessable_entity
body = JSON.parse(response.body)

assert_not body['success']
assert body['errors']['user']['password'].present?
end

Comment on lines +103 to +113
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests about partner users are not directly related to the changes, but they ensure no regressions are caused. We need them.

test 'post with weak password rejected when strong passwords enabled' do
prepare_master_account

Expand Down
10 changes: 10 additions & 0 deletions test/functional/partners/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ def setup
assert body['success']
end

test 'create user without password or open_id rejected' do
post :create, params: { provider_id: @account.id, api_key: @partner.api_key, email: "foo@example.net", username: "aaron" }

assert_response :unprocessable_entity
body = JSON.parse(response.body)

assert_not body['success']
assert body['errors']['password'].present?
end

test 'create user with invalid params returns 422' do
post :create, params: { provider_id: @account.id, api_key: @partner.api_key, email: "invalid-email", username: "aaron" }

Expand Down
12 changes: 12 additions & 0 deletions test/unit/liquid/drops/user_drop_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ def test_oauth2
assert @user.signup.machine?
assert_not @drop.password_required?
end

test '#password_required? returns false for legacy :api signup type' do
@user.signup_type = :api

assert_not @drop.password_required?
end

test '#password_required? returns false for :created_by_provider signup type' do
@user.signup_type = :created_by_provider

assert_not @drop.password_required?
end
end

class BuyerUserTest < Liquid::Drops::UserDropTest
Expand Down
37 changes: 37 additions & 0 deletions test/unit/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,43 @@ def test_accessible_services
assert created_by_provider_user.errors[:password].blank?
end

test 'by_user? returns true only for :new_signup, nil, and :partner signup types' do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also test how open_id?, cas? and oauth2? responses affect the by_user? return value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here: b006abf

user = User.new

%i[new_signup partner].each do |type|
user.signup_type = type
assert user.signup.by_user?
end

user.signup_type = nil
assert user.signup.by_user?

%i[minimal api created_by_provider].each do |type|
user.signup_type = type
assert_not user.signup.by_user?
end
end

test 'by_user? returns false when user has SSO identifiers regardless of signup type' do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be part of 'by_user? returns true only for :new_signup, nil, and :partner signup types' test. But not a showstopper for me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind changing it, but if I do, I'll lose the approval and have to run tests again just for this. I'm gonna wait for @mayorova's comments, if she requests more changes I'll change this as well.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must finally give you a token with approve privileges so you stop complaining about approvals.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, please do!!!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No other comments so far :)

user = User.new
user.signup_type = :new_signup

user.open_id = 'some-open-id'
assert_not user.signup.by_user?
user.open_id = nil

user.stubs(:any_sso_authorizations?).returns(true)
assert_not user.signup.by_user?
user.unstub(:any_sso_authorizations?)

user.authentication_id = 'some-auth-id'
assert_not user.signup.by_user?
user.authentication_id = nil

user.cas_identifier = 'some-cas-id'
assert_not user.signup.by_user?
end

test 'reset password' do
user = FactoryBot.create(:simple_user, username: 'person', password: 'superSecret1234#')
user.activate!
Expand Down