From 7641419904898ab93871c6c1e47e0cf17c0d5e15 Mon Sep 17 00:00:00 2001 From: Martin Weindel Date: Thu, 29 Aug 2024 13:39:04 +0200 Subject: [PATCH] fix NPE if certificate contains invalid domain name (#387) --- pkg/dns/provider/entry.go | 8 ++++---- test/integration/entryLivecycle_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/pkg/dns/provider/entry.go b/pkg/dns/provider/entry.go index 2c669a58..b4fd7910 100644 --- a/pkg/dns/provider/entry.go +++ b/pkg/dns/provider/entry.go @@ -476,10 +476,6 @@ func (this *EntryVersion) Setup(logger logger.LogContext, state *state, p *Entry } spec, targets, warnings, verr := validate(logger, state, this, p) - if p.provider != nil && spec.TTL != nil { - this.status.TTL = spec.TTL - } - if verr != nil { hello.Infof(logger, "validation failed: %s", verr) @@ -491,6 +487,10 @@ func (this *EntryVersion) Setup(logger logger.LogContext, state *state, p *Entry hello.Infof(logger, "validation ok") + if p.provider != nil && spec.TTL != nil { + this.status.TTL = spec.TTL + } + if this.IsDeleting() { logger.Infof("update state to %s", api.STATE_DELETING) this.status.State = api.STATE_DELETING diff --git a/test/integration/entryLivecycle_test.go b/test/integration/entryLivecycle_test.go index d7d7201d..ef8a4a92 100644 --- a/test/integration/entryLivecycle_test.go +++ b/test/integration/entryLivecycle_test.go @@ -312,4 +312,28 @@ var _ = Describe("EntryLivecycle", func() { err = testEnv.DeleteProviderAndSecret(pr) Ω(err).ShouldNot(HaveOccurred()) }) + + It("handles entry with invalid domain name correctly", func() { + pr, domain, _, err := testEnv.CreateSecretAndProvider("inmemory.mock", 0) + Ω(err).ShouldNot(HaveOccurred()) + + defer testEnv.DeleteProviderAndSecret(pr) + + setSpec := func(e *v1alpha1.DNSEntry) { + e.Spec.DNSName = fmt.Sprintf("invalid-*.%s", domain) + e.Spec.Targets = []string{"1.2.3.4"} + } + e0, err := testEnv.CreateEntryGeneric(0, setSpec) + Ω(err).ShouldNot(HaveOccurred()) + + checkProvider(pr) + + Ω(testEnv.AwaitEntryInvalid(e0.GetName())).ShouldNot(HaveOccurred()) + + err = testEnv.DeleteEntryAndWait(e0) + Ω(err).ShouldNot(HaveOccurred()) + + err = testEnv.DeleteProviderAndSecret(pr) + Ω(err).ShouldNot(HaveOccurred()) + }) })