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 11:04:38 +0200
commit3596c549e6fb9508f019e25c16c3c805118140b7 (patch)
tree0d6139887f17e0a4fd25a3372f36507958316f7a
parent52fba9e71c014a179ef6a15a9c0ae6d985573e0c (diff)
downloadchef-zero-sr/pool-608/search-users-by-case-insenstive-email.tar.gz
GET /users?email=ME@MINE.COM -- compare emails ignoring casesr/pool-608/search-users-by-case-insenstive-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