mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
BUG: SPF split doesn't produce consistent output (#1865)
This commit is contained in:
@ -2,13 +2,26 @@ package normalize
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/StackExchange/dnscontrol/v3/models"
|
"github.com/StackExchange/dnscontrol/v3/models"
|
||||||
"github.com/StackExchange/dnscontrol/v3/pkg/spflib"
|
"github.com/StackExchange/dnscontrol/v3/pkg/spflib"
|
||||||
|
"golang.org/x/exp/constraints"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func sortedKeys[K constraints.Ordered, V any](m map[K]V) []K {
|
||||||
|
keys := make([]K, len(m))
|
||||||
|
i := 0
|
||||||
|
for k := range m {
|
||||||
|
keys[i] = k
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] })
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
||||||
// hasSpfRecords returns true if this record requests SPF unrolling.
|
// hasSpfRecords returns true if this record requests SPF unrolling.
|
||||||
func flattenSPFs(cfg *models.DNSConfig) []error {
|
func flattenSPFs(cfg *models.DNSConfig) []error {
|
||||||
var cache spflib.CachingResolver
|
var cache spflib.CachingResolver
|
||||||
@ -74,7 +87,9 @@ func flattenSPFs(cfg *models.DNSConfig) []error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
recs := rec.TXTSplit(split+"."+domain.Name, overhead1, txtMaxSize)
|
recs := rec.TXTSplit(split+"."+domain.Name, overhead1, txtMaxSize)
|
||||||
for k, v := range recs {
|
|
||||||
|
for _, k := range sortedKeys(recs) {
|
||||||
|
v := recs[k]
|
||||||
if k == "@" {
|
if k == "@" {
|
||||||
txt.SetTargetTXTs(v)
|
txt.SetTargetTXTs(v)
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user