Skip to content

Commit

Permalink
test(rrset): Add 'unquoted TXT record' test
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony TREUILLIER <[email protected]>
  • Loading branch information
antrema committed Oct 29, 2024
1 parent 1cc92e6 commit 5913346
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
59 changes: 59 additions & 0 deletions internal/controller/rrset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1178,4 +1178,63 @@ var _ = Describe("RRset Controller", func() {
Expect(createdResource.GetFinalizers()).To(ContainElement(FINALIZER_NAME), "RRset should contain the finalizer")
})
})

Context("When creating a wrong RRset", func() {
It("should reconcile the resource with Failed status", Label("wrong-rrset", "unquoted-txt"), func() {
ctx := context.Background()
// Specific test variables
unquotedResourceName := "unquoted"
unquotedResourceDNSName := "txt"
unquotedResourceType := "TXT"
unquotedResourceRecords := []string{"An unquoted record"}
unquotedResourceComment := "This is an unquoted-TXT Record"

By("Creating the RRset resource")
unquotedResource := &dnsv1alpha1.RRset{
ObjectMeta: metav1.ObjectMeta{
Name: unquotedResourceName,
Namespace: resourceNamespace,
},
}
unquotedResource.SetResourceVersion("")
_, err := controllerutil.CreateOrUpdate(ctx, k8sClient, unquotedResource, func() error {
unquotedResource.Spec = dnsv1alpha1.RRsetSpec{
ZoneRef: dnsv1alpha1.ZoneRef{
Name: zoneName,
},
Type: unquotedResourceType,
Name: unquotedResourceDNSName,
TTL: resourceTTL,
Records: unquotedResourceRecords,
Comment: &unquotedResourceComment,
}
return nil
})
unquotedRRsetLookupKey := types.NamespacedName{
Name: unquotedResourceName,
Namespace: resourceNamespace,
}

Expect(err).NotTo(HaveOccurred())
Eventually(func() bool {
err := k8sClient.Get(ctx, unquotedRRsetLookupKey, unquotedResource)
return err == nil && unquotedResource.Status.SyncStatus != nil
}, timeout, interval).Should(BeTrue())

DnsFqdn := getRRsetName(unquotedResource)

By("Getting the created resource")
createdResource := &dnsv1alpha1.RRset{}
Eventually(func() bool {
err := k8sClient.Get(ctx, unquotedRRsetLookupKey, createdResource)
return err == nil
}, timeout, interval).Should(BeTrue())

Expect(getMockedRecordsForType(DnsFqdn, unquotedResourceType)).To(Equal([]string{}), "RRset should not have been created in backend")
Expect(*createdResource.Status.SyncStatus).To(Equal(FAILED_STATUS), "RRset status should be 'Failed'")
Expect(createdResource.GetOwnerReferences()).NotTo(BeEmpty(), "RRset should have setOwnerReference")
Expect(createdResource.GetOwnerReferences()[0].Name).To(Equal(zoneRef), "RRset should have setOwnerReference to Zone")
Expect(createdResource.GetFinalizers()).To(ContainElement(FINALIZER_NAME), "RRset should contain the finalizer")
})
})
})
9 changes: 9 additions & 0 deletions internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,15 @@ func (m mockRecordsClient) Change(ctx context.Context, domain string, name strin
}
}

// Preliminary test - Linked to 'wrong-rrset && unquoted-txt' test
if string(recordType) == "TXT" && content[0] == strings.TrimSuffix(content[0], "\"") && content[0] == strings.TrimPrefix(content[0], "\"") {
return &powerdns.Error{
StatusCode: 422,
Status: "422 Unprocessable Entity",
Message: "Record " + name + "/TXT '" + strings.Join(content, ",") + "': Parsing record content (try 'pdnsutil check-zone'): Data field in DNS should start with quote(\") at position 0 of '" + strings.Join(content, ",") + "'",
}
}

var isRRsetIdentical, isNewRRset, ok bool
var rrset *powerdns.RRset
var comment, specifiedComment string
Expand Down

0 comments on commit 5913346

Please sign in to comment.