diff options
author | Adam Leff <adam@leff.co> | 2016-12-07 15:51:14 -0500 |
---|---|---|
committer | Adam Leff <adam@leff.co> | 2016-12-07 15:53:08 -0500 |
commit | 9e77f0401b857b2ba1e4d00d8fa5ebc805050a88 (patch) | |
tree | 903a358c8d7a5e8667b1e7b0a2b685e6f4c7e811 | |
parent | e2c5935b818c8d1a74e24ba624de1ae489909fdb (diff) | |
download | chef-9e77f0401b857b2ba1e4d00d8fa5ebc805050a88.tar.gz |
Fix Data Collector organization parsing regex
The regex used to pluck the Chef Server Organization from the
chef_server_url config value did not permit hyphens in org names
even though they are allowed by Chef Server. This caused org names
to get incorrectly truncated when sending the payload to Data
Collector servers.
Re: Chef bug IPO-500
Signed-off-by: Adam Leff <adam@leff.co>
-rw-r--r-- | lib/chef/data_collector/messages/helpers.rb | 2 | ||||
-rw-r--r-- | spec/unit/data_collector/messages/helpers_spec.rb | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/chef/data_collector/messages/helpers.rb b/lib/chef/data_collector/messages/helpers.rb index d257b74893..a56ea4e829 100644 --- a/lib/chef/data_collector/messages/helpers.rb +++ b/lib/chef/data_collector/messages/helpers.rb @@ -76,7 +76,7 @@ class Chef def chef_server_organization return "unknown_organization" unless Chef::Config[:chef_server_url] - Chef::Config[:chef_server_url].match(%r{/+organizations/+(\w+)}).nil? ? "unknown_organization" : $1 + Chef::Config[:chef_server_url].match(%r{/+organizations/+([\w-]+)}).nil? ? "unknown_organization" : $1 end # diff --git a/spec/unit/data_collector/messages/helpers_spec.rb b/spec/unit/data_collector/messages/helpers_spec.rb index b0d9f4d09d..a241bda699 100644 --- a/spec/unit/data_collector/messages/helpers_spec.rb +++ b/spec/unit/data_collector/messages/helpers_spec.rb @@ -72,6 +72,13 @@ describe Chef::DataCollector::Messages::Helpers do expect(TestMessage.chef_server_organization).to eq("unknown_organization") end end + + context "when the organization in the URL contains hyphens" do + it "returns the full org name" do + Chef::Config[:chef_server_url] = "http://mycompany.com/organizations/myorg-test" + expect(TestMessage.chef_server_organization).to eq("myorg-test") + end + end end describe "#collector_source" do |