diff options
author | danielsdeleo <dan@getchef.com> | 2015-02-23 10:40:51 -0800 |
---|---|---|
committer | danielsdeleo <dan@getchef.com> | 2015-02-23 10:40:51 -0800 |
commit | 21b2f7843dd2de72ae2226e92e1daa7ed4eec03c (patch) | |
tree | 87c9b6492df57e699ab1576963de60b7201ae0ea /lib/chef_zero/endpoints | |
parent | d430ad28c69d4d234c3f114106cba9f02ebab46d (diff) | |
download | chef-zero-21b2f7843dd2de72ae2226e92e1daa7ed4eec03c.tar.gz |
Policyfile revision_id field is mandatory, validate format
Diffstat (limited to 'lib/chef_zero/endpoints')
-rw-r--r-- | lib/chef_zero/endpoints/policies_endpoint.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/chef_zero/endpoints/policies_endpoint.rb b/lib/chef_zero/endpoints/policies_endpoint.rb index 992d5ae..4803d0d 100644 --- a/lib/chef_zero/endpoints/policies_endpoint.rb +++ b/lib/chef_zero/endpoints/policies_endpoint.rb @@ -41,7 +41,8 @@ module ChefZero def validate(request) req_object = validate_json(request.body) - validate_name(request, req_object) || + validate_revision_id(request, req_object) || + validate_name(request, req_object) || validate_run_list(req_object) || validate_each_run_list_item(req_object) || validate_cookbook_locks_collection(req_object) || @@ -54,6 +55,16 @@ module ChefZero # error(400, "Must specify #{identity_keys.map { |k| k.inspect }.join(' or ')} in JSON") end + def validate_revision_id(request, req_object) + if !req_object.key?("revision_id") + error(400, "Must specify 'revision_id' in JSON") + elsif req_object["revision_id"].size > 255 + error(400, "'revision_id' field in JSON must be 255 characters or fewer") + elsif req_object["revision_id"] !~ /^[\-[:alnum:]_\.\:]+$/ + error(400, "'revision_id' field in JSON must be contain only alphanumeric, hypen, underscore, and dot characters") + end + end + def validate_name(request, req_object) if !req_object.key?("name") error(400, "Must specify 'name' in JSON") |