Skip to content

Commit

Permalink
Supporting unit tests for EqualFold #307
Browse files Browse the repository at this point in the history
  • Loading branch information
zerodayz authored and stefanmcshane committed Apr 27, 2021
1 parent 9b5f02b commit e71be52
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
44 changes: 44 additions & 0 deletions dn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions v3/dn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e71be52

Please sign in to comment.