diff --git a/dn_test.go b/dn_test.go index ee181310..d93ba650 100644 --- a/dn_test.go +++ b/dn_test.go @@ -171,6 +171,50 @@ func TestDNEqual(t *testing.T) { } } +func TestDNEqualFold(t *testing.T) { + testcases := []struct { + A string + B string + Equal bool + }{ + // Match on case insensitive + {"o=A", "o=a", true}, + {"o=A,o=b", "o=a,o=B", true}, + {"o=a+o=B", "o=A+o=b", true}, + { + "cn=users,ou=example,dc=com", + "cn=Users,ou=example,dc=com", + true, + }, + + // Match on case insensitive and case mismatch in type + {"o=A", "O=a", true}, + {"o=A,o=b", "o=a,O=B", true}, + {"o=a+o=B", "o=A+O=b", true}, + } + + for i, tc := range testcases { + a, err := ParseDN(tc.A) + if err != nil { + t.Errorf("%d: %v", i, err) + continue + } + b, err := ParseDN(tc.B) + if err != nil { + t.Errorf("%d: %v", i, err) + continue + } + if expected, actual := tc.Equal, a.EqualFold(b); expected != actual { + t.Errorf("%d: when comparing '%s' and '%s' expected %v, got %v", i, tc.A, tc.B, expected, actual) + continue + } + if expected, actual := tc.Equal, b.EqualFold(a); expected != actual { + t.Errorf("%d: when comparing '%s' and '%s' expected %v, got %v", i, tc.A, tc.B, expected, actual) + continue + } + } +} + func TestDNAncestor(t *testing.T) { testcases := []struct { A string diff --git a/v3/dn_test.go b/v3/dn_test.go index ee181310..d93ba650 100644 --- a/v3/dn_test.go +++ b/v3/dn_test.go @@ -171,6 +171,50 @@ func TestDNEqual(t *testing.T) { } } +func TestDNEqualFold(t *testing.T) { + testcases := []struct { + A string + B string + Equal bool + }{ + // Match on case insensitive + {"o=A", "o=a", true}, + {"o=A,o=b", "o=a,o=B", true}, + {"o=a+o=B", "o=A+o=b", true}, + { + "cn=users,ou=example,dc=com", + "cn=Users,ou=example,dc=com", + true, + }, + + // Match on case insensitive and case mismatch in type + {"o=A", "O=a", true}, + {"o=A,o=b", "o=a,O=B", true}, + {"o=a+o=B", "o=A+O=b", true}, + } + + for i, tc := range testcases { + a, err := ParseDN(tc.A) + if err != nil { + t.Errorf("%d: %v", i, err) + continue + } + b, err := ParseDN(tc.B) + if err != nil { + t.Errorf("%d: %v", i, err) + continue + } + if expected, actual := tc.Equal, a.EqualFold(b); expected != actual { + t.Errorf("%d: when comparing '%s' and '%s' expected %v, got %v", i, tc.A, tc.B, expected, actual) + continue + } + if expected, actual := tc.Equal, b.EqualFold(a); expected != actual { + t.Errorf("%d: when comparing '%s' and '%s' expected %v, got %v", i, tc.A, tc.B, expected, actual) + continue + } + } +} + func TestDNAncestor(t *testing.T) { testcases := []struct { A string