Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Roles and Users endpoints integration tests #174

Merged
merged 5 commits into from
Jul 2, 2019
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 lib/auth0/api/v2/roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def remove_role_permissions(role_id, permissions)
raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty?

permissions = validate_permissions_array(permissions)
delete "#{roles_path}/#{role_id}/permissions", permissions: permissions
delete_with_body("#{roles_path}/#{role_id}/permissions", permissions: permissions)
end

private
Expand Down
11 changes: 6 additions & 5 deletions lib/auth0/api/v2/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,14 @@ def link_user_account(user_id, body)
# @param secondary_user_id [string] The unique identifier for the user for the identity.
#
# @return [json] Returns the array of the unlinked account identities.
def unlink_users_account(user_id, provider, secondary_user_id)
def unlink_user_account(user_id, provider, secondary_user_id)
raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
raise Auth0::MissingUserId, 'Must supply a valid secondary user_id' if secondary_user_id.to_s.empty?
raise Auth0::InvalidParameter, 'Must supply a valid provider' if provider.to_s.empty?
path = "#{users_path}/#{user_id}/identities/#{provider}/#{secondary_user_id}"
delete(path)
end
alias unlink_users_account unlink_user_account

# Retrieve every log event for a specific user id
# @see https://auth0.com/docs/api/management/v2#!/Users/get_logs_by_user
Expand Down Expand Up @@ -220,19 +221,19 @@ def remove_user_roles(user_id, roles)
raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
validate_strings_array roles
path = "#{users_path}/#{user_id}/roles"
delete(path, { roles: roles })
delete_with_body path, roles: roles
Copy link
Contributor

Choose a reason for hiding this comment

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

I see inconsistencies on the syntax when calling a function with parameters.

delete(path, {param: value} vs delete path, param:value.

Should we add a linter as a precommit for this repo as well or is this change on purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a linter that I run, rubocop, but it doesn't pick this up

end

# Add one or more roles to a specific user.
# @see https://auth0.com/docs/api/management/v2#!/Users/post_user_roles
#
# @param user_id [string] The user_id of the roles to add.
# @param roles [array] An array of role names to add.
# @param roles [array] An array of role ids to add.
def add_user_roles(user_id, roles)
raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
validate_strings_array roles
path = "#{users_path}/#{user_id}/roles"
post(path, { roles: roles })
post(path, roles: roles)
end

# Get all Guardian enrollments for a specific user
Expand Down Expand Up @@ -265,7 +266,7 @@ def get_user_permissions(user_id)
def remove_user_permissions(user_id, permissions)
raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?
permissions = validate_permissions_array permissions
delete "#{users_path}/#{user_id}/permissions", permissions: permissions
delete_with_body "#{users_path}/#{user_id}/permissions", permissions: permissions
end

# Add one or more permissions from a specific user.
Expand Down
4 changes: 3 additions & 1 deletion lib/auth0/mixins/httpproxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module HTTPProxy
attr_accessor :headers, :base_uri, :timeout

# proxying requests from instance methods to HTTP class methods
%i(get post post_file put patch delete).each do |method|
%i(get post post_file put patch delete delete_with_body).each do |method|
define_method(method) do |path, body = {}, extra_headers = {}|
safe_path = URI.escape(path)
body = body.delete_if { |_, v| v.nil? }
Expand All @@ -20,6 +20,8 @@ module HTTPProxy
call(:get, url(safe_path), timeout, get_headers)
elsif method == :delete
call(:delete, url(safe_path), timeout, add_headers({params: body}))
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this params:body header for? I guess you meant to send a query instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oddly, sending it as params: converts it to a query ... one of the many quirks of this HTTP library

elsif method == :delete_with_body
call(:delete, url(safe_path), timeout, headers, body)
elsif method == :post_file
body.merge!(multipart: true)
call(:post, url(safe_path), timeout, headers, body)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading