Merge pull request #344 from highb/imp/master/QENG-7530_update_hostname_handling_for_human_hostnames

(QENG-7530) Fix hostname_shorten regex
This commit is contained in:
mattkirby 2019-11-01 15:22:54 -07:00 committed by GitHub
commit 1df13e4974
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View file

@ -140,7 +140,7 @@ module Vmpooler
end
def hostname_shorten(hostname, domain=nil)
if domain && hostname =~ /^\w+\.#{domain}$/
if domain && hostname =~ /^[\w-]+\.#{domain}$/
hostname = hostname[/[^\.]+/]
end

View file

@ -19,6 +19,8 @@ describe Vmpooler::API::Helpers do
['example.com', 'not-example.com', 'example.com'],
['example.com', 'example.com', 'example.com'],
['sub.example.com', 'example.com', 'sub'],
['adjective-noun.example.com', 'example.com', 'adjective-noun'],
['abc123.example.com', 'example.com', 'abc123'],
['example.com', nil, 'example.com']
].each do |hostname, domain, expected|
it { expect(subject.hostname_shorten(hostname, domain)).to eq expected }