Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement(link_local_dns.go): avoid occur runtime panic when the nameservers are empty. #393

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions helper/link_local_dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ type LinkLocalDNS struct {
}

func (l LinkLocalDNS) Execute() (map[string]string, error) {
// In some cases, the nameservers are empty.
// For example, when using the host network, and host '/etc/resolv.conf' file content is empty.
if len(l.Config.Servers) == 0 {
return nil, nil
}

if !net.ParseIP(l.Config.Servers[0]).IsLinkLocalUnicast() {
return nil, nil
}
Expand Down
9 changes: 9 additions & 0 deletions helper/link_local_dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ func testLinkLocalDNS(t *testing.T, context spec.G, it spec.S) {
Expect(ioutil.ReadFile(path)).To(Equal([]byte("test")))
})

it("do nothing if no nameservers", func() {
config := &ddns.ClientConfig{Servers: []string{}}

l := helper.LinkLocalDNS{Config: config}

Expect(l.Execute()).To(BeNil())
Expect(ioutil.ReadFile(path)).To(Equal([]byte(`test`)))
})

it("returns an error if $JAVA_SECURITY_PROPERTIES is not set", func() {
config := &ddns.ClientConfig{Servers: []string{"169.254.0.1"}}
l := helper.LinkLocalDNS{Config: config}
Expand Down