summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Renatus <srenatus@chef.io>2017-05-31 11:04:38 +0200
committerStephan Renatus <srenatus@chef.io>2017-05-31 16:27:02 +0200
commita57b15ae42925301840e35bc15659fa28c245099 (patch)
tree53aa3edc7a236682c8d9a7ba8b8a6f19a3468adb
parent73ed88e08a3be39128481ebfdd08ac6e170b4965 (diff)
downloadchef-zero-a57b15ae42925301840e35bc15659fa28c245099.tar.gz
GET /users?email=ME@MINE.COM -- compare emails ignoring casesr/pool-608/search-users-by-case-insensitive-email
As of POOL-608, the query will return users with the mail `me@mine.com`, too. While this is technically a little incorrect (only the host part is case insensitive), most mail providers treat the user part as case insensitive as well. Note that this implies that the response may involve more than one user. But chef-zero behaves like chef-server does, returning them all. Signed-off-by: Stephan Renatus <srenatus@chef.io>
-rw-r--r--lib/chef_zero/endpoints/actors_endpoint.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/chef_zero/endpoints/actors_endpoint.rb b/lib/chef_zero/endpoints/actors_endpoint.rb
index 1dcbe42..4a6d8c9 100644
--- a/lib/chef_zero/endpoints/actors_endpoint.rb
+++ b/lib/chef_zero/endpoints/actors_endpoint.rb
@@ -13,7 +13,7 @@ module ChefZero
if value = request.query_params["external_authentication_uid"]
response[2] = filter("external_authentication_uid", value, request, response[2])
elsif value = request.query_params["email"]
- response[2] = filter("email", value, request, response[2])
+ response[2] = filter("email", value, request, response[2], insensitive: true)
end
if request.query_params["verbose"]
@@ -83,18 +83,22 @@ module ChefZero
private
- def filter(key, value, request, resp)
+ def filter(key, value, request, resp, opts = {})
results = parse_json(resp)
new_results = {}
results.each do |name, url|
record = get_data(request, request.rest_path + [ name ], :nil)
if record
record = parse_json(record)
- new_results[name] = url if record[key] == value
+ new_results[name] = url if record[key] && is_equal(record[key], value, opts[:insensitive])
end
end
to_json(new_results)
end
+
+ def is_equal(a, b, ignore_case)
+ ignore_case ? a.casecmp(b).zero? : a == b
+ end
end
end
end