Skip to content

Commit bb577bd

Browse files
authored
Do not set Nsec3Param if DNSsec is disabled (joeig#32)
* Do not set Nsec3Param if DNSsec is disabled * Add ChangeZone with/without DNSsec tests
1 parent fec0b15 commit bb577bd

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

zones.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ func (z *ZonesService) Change(ctx context.Context, domain string, zone *Zone) er
165165
zone.Name = nil
166166
zone.Type = nil
167167
zone.URL = nil
168+
if zone.DNSsec != nil && !*zone.DNSsec {
169+
zone.Nsec3Param = nil
170+
}
168171

169172
req, err := z.client.newRequest(ctx, "PUT", fmt.Sprintf("servers/%s/zones/%s", z.client.VHost, trimDomain(domain)), nil, zone)
170173
if err != nil {

zones_test.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ func TestAddMasterZoneWithoutDNSSec(t *testing.T) {
394394

395395
p := initialisePowerDNSTestClient()
396396
zone, err := p.Zones.AddMaster(context.Background(), testDomain, false, "", false, "foo", "foo", true, []string{"ns.foo.tld."})
397-
398397
if err != nil {
399398
t.Errorf("%s", err)
400399
}
@@ -483,7 +482,28 @@ func TestAddZoneError(t *testing.T) {
483482
}
484483
}
485484

486-
func TestChangeZone(t *testing.T) {
485+
func TestChangeZoneWithDNSSec(t *testing.T) {
486+
testDomain := generateTestZone(true)
487+
488+
httpmock.Activate()
489+
defer httpmock.DeactivateAndReset()
490+
registerZoneMockResponder(testDomain, NativeZoneKind)
491+
492+
p := initialisePowerDNSTestClient()
493+
494+
t.Run("ChangeValidZone", func(t *testing.T) {
495+
if err := p.Zones.Change(context.Background(), testDomain, &Zone{Nameservers: []string{"ns23.foo.tld."}, Nsec3Param: String(""), DNSsec: Bool(true)}); err != nil {
496+
t.Errorf("%s", err)
497+
}
498+
})
499+
t.Run("ChangeInvalidZone", func(t *testing.T) {
500+
if err := p.Zones.Change(context.Background(), "doesnt-exist", &Zone{Nameservers: []string{"ns23.foo.tld."}, Nsec3Param: String(""), DNSsec: Bool(true)}); err == nil {
501+
t.Errorf("Changing an invalid zone does not return an error")
502+
}
503+
})
504+
}
505+
506+
func TestChangeZoneWithoutDNSSec(t *testing.T) {
487507
testDomain := generateTestZone(true)
488508

489509
httpmock.Activate()
@@ -493,12 +513,12 @@ func TestChangeZone(t *testing.T) {
493513
p := initialisePowerDNSTestClient()
494514

495515
t.Run("ChangeValidZone", func(t *testing.T) {
496-
if err := p.Zones.Change(context.Background(), testDomain, &Zone{Nameservers: []string{"ns23.foo.tld."}}); err != nil {
516+
if err := p.Zones.Change(context.Background(), testDomain, &Zone{Nameservers: []string{"ns23.foo.tld."}, Nsec3Param: String(""), DNSsec: Bool(false)}); err != nil {
497517
t.Errorf("%s", err)
498518
}
499519
})
500520
t.Run("ChangeInvalidZone", func(t *testing.T) {
501-
if err := p.Zones.Change(context.Background(), "doesnt-exist", &Zone{Nameservers: []string{"ns23.foo.tld."}}); err == nil {
521+
if err := p.Zones.Change(context.Background(), "doesnt-exist", &Zone{Nameservers: []string{"ns23.foo.tld."}, Nsec3Param: String(""), DNSsec: Bool(false)}); err == nil {
502522
t.Errorf("Changing an invalid zone does not return an error")
503523
}
504524
})

0 commit comments

Comments
 (0)