diff --git a/pkg/util/filter.go b/pkg/util/filter.go index a75eeb171..c4594e8dd 100644 --- a/pkg/util/filter.go +++ b/pkg/util/filter.go @@ -57,15 +57,15 @@ func StringFilter(fn FilterFn, in ...string) StringFilterWrapper { } func RemoveDuplicates(in []string) []string { - dedupMap := make(map[string]struct{}) + var found []string +Outer: for _, i := range in { - dedupMap[i] = struct{}{} + for _, i2 := range found { + if i2 == i { + continue Outer + } + } + found = append(found, i) } - out := make([]string, len(dedupMap)) - i := 0 - for s := range dedupMap { - out[i] = s - i++ - } - return out + return found } diff --git a/pkg/util/pki/csr_test.go b/pkg/util/pki/csr_test.go index e54274dcc..a6faaa57a 100644 --- a/pkg/util/pki/csr_test.go +++ b/pkg/util/pki/csr_test.go @@ -102,6 +102,18 @@ func TestDNSNamesForCertificate(t *testing.T) { crtDNSNames: []string{"dnsname1", "dnsname2"}, expectDNSNames: []string{"dnsname1", "dnsname2"}, }, + { + name: "certificate with dnsName[0] set to equal common name", + crtCN: "cn", + crtDNSNames: []string{"cn", "dnsname"}, + expectDNSNames: []string{"cn", "dnsname"}, + }, + { + name: "certificate with a dnsName equal to cn", + crtCN: "cn", + crtDNSNames: []string{"dnsname", "cn"}, + expectDNSNames: []string{"cn", "dnsname"}, + }, } testFn := func(test testT) func(*testing.T) { return func(t *testing.T) {