File tree Expand file tree Collapse file tree 3 files changed +28
-4
lines changed
spec/facter/resolvers/linux Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -68,9 +68,9 @@ def hostname_and_no_domain?(hostname, domain)
6868
6969 def read_domain
7070 file_content = Facter ::Util ::FileHelper . safe_read ( '/etc/resolv.conf' )
71- if file_content =~ /^domain\s +(\S +)/
71+ if file_content =~ /^domain\s +([^.] \S +)/
7272 Regexp . last_match ( 1 )
73- elsif file_content =~ /^search\s +(\S +)/
73+ elsif file_content =~ /^search\s +([^.] \S +)/
7474 Regexp . last_match ( 1 )
7575 end
7676 end
Original file line number Diff line number Diff line change @@ -96,9 +96,9 @@ def hostname_and_no_domain?(hostname, domain)
9696
9797 def read_domain
9898 file_content = Facter ::Util ::FileHelper . safe_read ( '/etc/resolv.conf' )
99- if file_content =~ /^domain\s +(\S +)/
99+ if file_content =~ /^domain\s +([^.] \S +)/
100100 Regexp . last_match ( 1 )
101- elsif file_content =~ /^search\s +(\S +)/
101+ elsif file_content =~ /^search\s +([^.] \S +)/
102102 Regexp . last_match ( 1 )
103103 end
104104 end
Original file line number Diff line number Diff line change 7979
8080 it_behaves_like 'detects values'
8181 end
82+
83+ context 'when /etc/resolv.conf has "search ."' do
84+ let ( :resolv_conf ) { "search .\n " }
85+ let ( :domain ) { nil }
86+ let ( :fqdn ) { hostname }
87+
88+ it_behaves_like 'detects values'
89+ end
90+
91+ context 'when /etc/resolv.conf has "search ." with multiple entires' do
92+ let ( :resolv_conf ) { 'search . foo.bar' }
93+ let ( :domain ) { nil }
94+ let ( :fqdn ) { hostname }
95+
96+ it_behaves_like 'detects values'
97+ end
98+
99+ context 'when /etc/resolv.conf has "search" with multiple entires' do
100+ let ( :resolv_conf ) { 'search foo.bar example.com' }
101+ let ( :domain ) { 'foo.bar' }
102+ let ( :fqdn ) { "#{ hostname } .#{ domain } " }
103+
104+ it_behaves_like 'detects values'
105+ end
82106 end
83107
84108 context 'when FFI is not installed' do
You can’t perform that action at this time.
0 commit comments