Skip to content

Commit

Permalink
Avoid crash with empty resolv.conf
Browse files Browse the repository at this point in the history
Fixes: #417
Signed-off-by: Reinhard Tartler <[email protected]>
  • Loading branch information
Reinhard Tartler authored and siretart committed Nov 8, 2024
1 parent 72b102d commit f3af713
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/services/dns/dns_config_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package dns

import (
"errors"
"github.com/miekg/dns"
)

Expand All @@ -11,6 +12,11 @@ func getDNSHostAndPort() (string, string, error) {
if err != nil {
return "", "", err
}

if len(conf.Servers) == 0 {
return "", "", errors.New("No DNS servers configured in /etc/resolv.conf")
}

// TODO: use all configured nameservers, instead just first one
nameserver := conf.Servers[0]

Expand Down
10 changes: 8 additions & 2 deletions pkg/services/dns/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ var _ = ginkgo.Describe("dns add test", func() {
var server *Server

ginkgo.BeforeEach(func() {
server, _ = New(nil, nil, []types.Zone{})
var err error
server, err = New(nil, nil, []types.Zone{})
if err != nil {
ginkgo.Skip("Skipping test, failed to setup DNS server")
}
})

ginkgo.It("should add dns zone with ip", func() {
Expand Down Expand Up @@ -230,7 +234,9 @@ type ARecord struct {
func TestDNS(t *testing.T) {
log.Infof("starting test DNS servers")
nameserver, cleanup, err := startDNSServer()
require.NoError(t, err)
if err != nil {
t.Skip("Failed to setup start DNS server, skipping test")
}
defer cleanup()
time.Sleep(100 * time.Millisecond)
log.Infof("test DNS servers started")
Expand Down

0 comments on commit f3af713

Please sign in to comment.