Merge pull request #6720 from fabiofalci/relax_dns_search
Relax dns search to accept empty domain
This commit is contained in:
commit
b4ab982c97
2 changed files with 29 additions and 2 deletions
|
@ -78,8 +78,10 @@ func Build(path string, dns, dnsSearch []string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(dnsSearch) > 0 {
|
if len(dnsSearch) > 0 {
|
||||||
if _, err := content.WriteString("search " + strings.Join(dnsSearch, " ") + "\n"); err != nil {
|
if searchString := strings.Join(dnsSearch, " "); strings.Trim(searchString, " ") != "." {
|
||||||
return err
|
if _, err := content.WriteString("search " + searchString + "\n"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,3 +131,28 @@ func TestBuild(t *testing.T) {
|
||||||
t.Fatalf("Expected to find '%s' got '%s'", expected, content)
|
t.Fatalf("Expected to find '%s' got '%s'", expected, content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildWithZeroLengthDomainSearch(t *testing.T) {
|
||||||
|
file, err := ioutil.TempFile("", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.Remove(file.Name())
|
||||||
|
|
||||||
|
err = Build(file.Name(), []string{"ns1", "ns2", "ns3"}, []string{"."})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := ioutil.ReadFile(file.Name())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if expected := "nameserver ns1\nnameserver ns2\nnameserver ns3\n"; !bytes.Contains(content, []byte(expected)) {
|
||||||
|
t.Fatalf("Expected to find '%s' got '%s'", expected, content)
|
||||||
|
}
|
||||||
|
if notExpected := "search ."; bytes.Contains(content, []byte(notExpected)) {
|
||||||
|
t.Fatalf("Expected to not find '%s' got '%s'", notExpected, content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue