Skip to content

Commit

Permalink
allow using ; as RDN separator according to rfc2253 (#352)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpuschma authored Jan 4, 2022
1 parent f61ea45 commit 13008e4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
4 changes: 2 additions & 2 deletions dn.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ func ParseDN(str string) (*DN, error) {
buffer.WriteString(packet.Data.String())
i += len(data) - 1
}
case char == ',' || char == '+':
case char == ',' || char == '+' || char == ';':
// We're done with this RDN or value, push it
if len(attribute.Type) == 0 {
return nil, errors.New("incomplete type, value pair")
}
attribute.Value = stringFromBuffer()
rdn.Attributes = append(rdn.Attributes, attribute)
attribute = new(AttributeTypeAndValue)
if char == ',' {
if char == ',' || char == ';' {
dn.RDNs = append(dn.RDNs, rdn)
rdn = new(RelativeDN)
rdn.Attributes = make([]*AttributeTypeAndValue, 0)
Expand Down
13 changes: 13 additions & 0 deletions dn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ func TestSuccessfulDNParsing(t *testing.T) {
{[]*AttributeTypeAndValue{
{" A ", " 1 "},
{" B ", " 2 "}}}}},

`cn=john.doe;dc=example,dc=net`: {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"cn", "john.doe"}}},
{[]*AttributeTypeAndValue{{"dc", "example"}}},
{[]*AttributeTypeAndValue{{"dc", "net"}}}}},

// Escaped `;` should not be treated as RDN
`cn=john.doe\;weird name,dc=example,dc=net`: {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"cn", "john.doe;weird name"}}},
{[]*AttributeTypeAndValue{{"dc", "example"}}},
{[]*AttributeTypeAndValue{{"dc", "net"}}}}},
}

for test, answer := range testcases {
Expand Down Expand Up @@ -147,6 +158,8 @@ func TestDNEqual(t *testing.T) {
"cn=John Doe, ou=People, dc=sun.com",
false,
},
// Test parsing of `;` for separating RDNs
{"cn=john;dc=example,dc=com", "cn=john,dc=example,dc=com", true}, // missing values matter
}

for i, tc := range testcases {
Expand Down
4 changes: 2 additions & 2 deletions v3/dn.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ func ParseDN(str string) (*DN, error) {
buffer.WriteString(packet.Data.String())
i += len(data) - 1
}
case char == ',' || char == '+':
case char == ',' || char == '+' || char == ';':
// We're done with this RDN or value, push it
if len(attribute.Type) == 0 {
return nil, errors.New("incomplete type, value pair")
}
attribute.Value = stringFromBuffer()
rdn.Attributes = append(rdn.Attributes, attribute)
attribute = new(AttributeTypeAndValue)
if char == ',' {
if char == ',' || char == ';' {
dn.RDNs = append(dn.RDNs, rdn)
rdn = new(RelativeDN)
rdn.Attributes = make([]*AttributeTypeAndValue, 0)
Expand Down
13 changes: 13 additions & 0 deletions v3/dn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ func TestSuccessfulDNParsing(t *testing.T) {
{[]*AttributeTypeAndValue{
{" A ", " 1 "},
{" B ", " 2 "}}}}},

`cn=john.doe;dc=example,dc=net`: {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"cn", "john.doe"}}},
{[]*AttributeTypeAndValue{{"dc", "example"}}},
{[]*AttributeTypeAndValue{{"dc", "net"}}}}},

// Escaped `;` should not be treated as RDN
`cn=john.doe\;weird name,dc=example,dc=net`: {[]*RelativeDN{
{[]*AttributeTypeAndValue{{"cn", "john.doe;weird name"}}},
{[]*AttributeTypeAndValue{{"dc", "example"}}},
{[]*AttributeTypeAndValue{{"dc", "net"}}}}},
}

for test, answer := range testcases {
Expand Down Expand Up @@ -147,6 +158,8 @@ func TestDNEqual(t *testing.T) {
"cn=John Doe, ou=People, dc=sun.com",
false,
},
// Test parsing of `;` for separating RDNs
{"cn=john;dc=example,dc=com", "cn=john,dc=example,dc=com", true}, // missing values matter
}

for i, tc := range testcases {
Expand Down

0 comments on commit 13008e4

Please sign in to comment.