Skip to content
Closed
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: 3 additions & 3 deletions provider/pihole/clientV6.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ func (p *piholeClientV6) apply(ctx context.Context, action string, ep *endpoint.

switch ep.RecordType {
case endpoint.RecordTypeA, endpoint.RecordTypeAAAA:
apiUrl = p.generateApiUrl(apiUrl, fmt.Sprintf("%s %s", ep.Targets, ep.DNSName))
apiUrl = p.generateApiUrl(apiUrl, fmt.Sprintf("%s %s", ep.Targets[0], ep.DNSName))
case endpoint.RecordTypeCNAME:
if ep.RecordTTL.IsConfigured() {
apiUrl = p.generateApiUrl(apiUrl, fmt.Sprintf("%s,%s,%d", ep.DNSName, ep.Targets, ep.RecordTTL))
apiUrl = p.generateApiUrl(apiUrl, fmt.Sprintf("%s,%s,%d", ep.DNSName, ep.Targets[0], ep.RecordTTL))
} else {
apiUrl = p.generateApiUrl(apiUrl, fmt.Sprintf("%s,%s", ep.DNSName, ep.Targets))
apiUrl = p.generateApiUrl(apiUrl, fmt.Sprintf("%s,%s", ep.DNSName, ep.Targets[0]))
}
}

Expand Down
33 changes: 32 additions & 1 deletion provider/pihole/clientV6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,8 @@ func TestCreateRecordV6(t *testing.T) {
if r.Method == "PUT" && (r.URL.Path == "/api/config/dns/hosts/192.168.1.1 test.example.com" ||
r.URL.Path == "/api/config/dns/hosts/fc00::1:192:168:1:1 test.example.com" ||
r.URL.Path == "/api/config/dns/cnameRecords/source1.example.com,target1.domain.com" ||
r.URL.Path == "/api/config/dns/cnameRecords/source2.example.com,target2.domain.com,500") {
r.URL.Path == "/api/config/dns/cnameRecords/source2.example.com,target2.domain.com,500" ||
r.URL.Path == "/api/config/dns/cnameRecords/source3.example.com,target3.domain.com") {

// Return A records
w.WriteHeader(http.StatusCreated)
Expand Down Expand Up @@ -747,6 +748,16 @@ func TestCreateRecordV6(t *testing.T) {
t.Fatal(err)
}

// Test create A record with multiple targets present and ensure only the first is added
ep = &endpoint.Endpoint{
DNSName: "test.example.com",
Targets: []string{"192.168.1.1", "192.168.1.2"},
RecordType: endpoint.RecordTypeA,
}
if err := cl.createRecord(context.Background(), ep); err != nil {
t.Fatal(err)
}

// Test create AAAA record
ep = &endpoint.Endpoint{
DNSName: "test.example.com",
Expand All @@ -757,6 +768,16 @@ func TestCreateRecordV6(t *testing.T) {
t.Fatal(err)
}

// Test create AAAA record with multiple targets present and ensure only the first is added
ep = &endpoint.Endpoint{
DNSName: "test.example.com",
Targets: []string{"fc00::1:192:168:1:1", "fc00::1:192:168:1:2"},
RecordType: endpoint.RecordTypeAAAA,
}
if err := cl.createRecord(context.Background(), ep); err != nil {
t.Fatal(err)
}

// Test create CNAME record
ep = &endpoint.Endpoint{
DNSName: "source1.example.com",
Expand All @@ -778,6 +799,16 @@ func TestCreateRecordV6(t *testing.T) {
t.Fatal(err)
}

// Test create CNAME record with multiple targets present and ensure only the first is added
ep = &endpoint.Endpoint{
DNSName: "source3.example.com",
Targets: []string{"target3.domain.com", "target4.domain.com"},
RecordType: endpoint.RecordTypeCNAME,
}
if err := cl.createRecord(context.Background(), ep); err != nil {
t.Fatal(err)
}

// Test create a wildcard record and ensure it fails
ep = &endpoint.Endpoint{
DNSName: "*.example.com",
Expand Down
Loading