diff options
author | Adam Leff <adam@leff.co> | 2016-12-16 11:09:14 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-16 11:09:14 -0500 |
commit | a2d18fb555694f5c6c9a62206a2051f352093eb6 (patch) | |
tree | 0e39ea41be4acc247094fdc2ff12513bc0a2feb4 | |
parent | 695e0197e80bc1b93e86ca302b16f3520ee7a86e (diff) | |
parent | 51687eee080618778dc34237d4a3326838a750e0 (diff) | |
download | chef-a2d18fb555694f5c6c9a62206a2051f352093eb6.tar.gz |
Merge pull request #5630 from chef/adamleff/ipo-500/fix-data-collector-org-parsing
Fix Data Collector organization parsing regex
-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..f42ddaaa4e 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/+([a-z0-9][a-z0-9_-]{0,254})}).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 |