context'when given a BER encoded attribute value with a space in it'do
let(:given){'#aa aa'}
it'raises MalformedError'do
expect{subject}.toraise_error(Gitlab::LDAP::DN::MalformedError,"Expected the end of an attribute value, but got \"a\"")
end
end
context'when given a BER encoded attribute value with a non-hex character in it'do
let(:given){'#aaXaaa'}
it'raises MalformedError'do
expect{subject}.toraise_error(Gitlab::LDAP::DN::MalformedError,"Expected the first character of a hex pair, but got \"X\"")
end
end
context'when given a BER encoded attribute value with a non-hex character in it'do
let(:given){'#aaaYaa'}
it'raises MalformedError'do
expect{subject}.toraise_error(Gitlab::LDAP::DN::MalformedError,"Expected the second character of a hex pair, but got \"Y\"")
end
end
context'when given a hex pair with a non-hex character in it, inside double quotes'do
let(:given){'"Sebasti\\cX\\a1n"'}
it'raises MalformedError'do
expect{subject}.toraise_error(Gitlab::LDAP::DN::MalformedError,"Expected the second character of a hex pair inside a double quoted value, but got \"X\"")
end
end
context'with an open (as opposed to closed) double quote'do
context'when given a BER encoded attribute value with a space in it'do
let(:given){'0.9.2342.19200300.100.1.25=#aa aa'}
it'raises MalformedError'do
expect{subject}.toraise_error(Gitlab::LDAP::DN::MalformedError,"Expected the end of an attribute value, but got \"a\"")
end
end
context'when given a BER encoded attribute value with a non-hex character in it'do
let(:given){'0.9.2342.19200300.100.1.25=#aaXaaa'}
it'raises MalformedError'do
expect{subject}.toraise_error(Gitlab::LDAP::DN::MalformedError,"Expected the first character of a hex pair, but got \"X\"")
end
end
context'when given a BER encoded attribute value with a non-hex character in it'do
let(:given){'0.9.2342.19200300.100.1.25=#aaaYaa'}
it'raises MalformedError'do
expect{subject}.toraise_error(Gitlab::LDAP::DN::MalformedError,"Expected the second character of a hex pair, but got \"Y\"")
end
end
context'when given a hex pair with a non-hex character in it, inside double quotes'do
let(:given){'uid="Sebasti\\cX\\a1n"'}
it'raises MalformedError'do
expect{subject}.toraise_error(Gitlab::LDAP::DN::MalformedError,"Expected the second character of a hex pair inside a double quoted value, but got \"X\"")
'downcases the whole string'|'UID=John Smith,ou=People,dc=example,dc=com'|'uid=john smith,ou=people,dc=example,dc=com'
'for a null DN (empty string), returns empty string and does not error'|''|''
'does not strip an escaped leading space in an attribute value'|'uid=\\ John Smith,ou=People,dc=example,dc=com'|'uid=\\ john smith,ou=people,dc=example,dc=com'
'does not strip an escaped leading space in the last attribute value'|'uid=\\ John Smith'|'uid=\\ john smith'
'does not strip an escaped trailing space in an attribute value'|'uid=John Smith\\ ,ou=People,dc=example,dc=com'|'uid=john smith\\ ,ou=people,dc=example,dc=com'
'strips extraneous spaces after an escaped trailing space'|'uid=John Smith\\ ,ou=People,dc=example,dc=com'|'uid=john smith\\ ,ou=people,dc=example,dc=com'
'strips extraneous spaces after an escaped trailing space at the end of the DN'|'uid=John Smith,ou=People,dc=example,dc=com\\ '|'uid=john smith,ou=people,dc=example,dc=com\\ '
'properly preserves escaped trailing space after unescaped trailing spaces'|'uid=John Smith \\ ,ou=People,dc=example,dc=com'|'uid=john smith \\ ,ou=people,dc=example,dc=com'
'preserves multiple inner spaces in an attribute value'|'uid=John Smith,ou=People,dc=example,dc=com'|'uid=john smith,ou=people,dc=example,dc=com'
'preserves inner spaces after an escaped space'|'uid=John\\ Smith,ou=People,dc=example,dc=com'|'uid=john smith,ou=people,dc=example,dc=com'
'hex-escapes an escaped leading newline in an attribute value'|"uid=\\\nJohn Smith,ou=People,dc=example,dc=com"|"uid=\\0ajohn smith,ou=people,dc=example,dc=com"
'hex-escapes and does not strip an escaped trailing newline in an attribute value'|"uid=John Smith\\\n,ou=People,dc=example,dc=com"|"uid=john smith\\0a,ou=people,dc=example,dc=com"
'hex-escapes an unescaped leading newline (actually an invalid DN?)'|"uid=\nJohn Smith,ou=People,dc=example,dc=com"|"uid=\\0ajohn smith,ou=people,dc=example,dc=com"
'strips an unescaped trailing newline (actually an invalid DN?)'|"uid=John Smith\n,ou=People,dc=example,dc=com"|"uid=john smith,ou=people,dc=example,dc=com"
'does not strip if no extraneous whitespace'|'uid=John Smith,ou=People,dc=example,dc=com'|'uid=john smith,ou=people,dc=example,dc=com'
'does not modify an escaped equal sign in an attribute value'|'uid= foo \\= bar'|'uid=foo \\= bar'
'converts an escaped hex equal sign to an escaped equal sign in an attribute value'|'uid= foo \\3D bar'|'uid=foo \\= bar'
'does not modify an escaped comma in an attribute value'|'uid= John C. Smith, ou=San Francisco\\, CA'|'uid=john c. smith,ou=san francisco\\, ca'
'converts an escaped hex comma to an escaped comma in an attribute value'|'uid= John C. Smith, ou=San Francisco\\2C CA'|'uid=john c. smith,ou=san francisco\\, ca'
'does not modify an escaped hex carriage return character in an attribute value'|'uid= John C. Smith, ou=San Francisco\\,\\0DCA'|'uid=john c. smith,ou=san francisco\\,\\0dca'
'does not modify an escaped hex line feed character in an attribute value'|'uid= John C. Smith, ou=San Francisco\\,\\0ACA'|'uid=john c. smith,ou=san francisco\\,\\0aca'
'does not modify an escaped hex CRLF in an attribute value'|'uid= John C. Smith, ou=San Francisco\\,\\0D\\0ACA'|'uid=john c. smith,ou=san francisco\\,\\0d\\0aca'
'allows attribute type name OIDs'|'0.9.2342.19200300.100.1.25=Example,0.9.2342.19200300.100.1.25=Com'|'0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com'
'strips extraneous whitespace from attribute type name OIDs'|'0.9.2342.19200300.100.1.25 = Example, 0.9.2342.19200300.100.1.25 = Com'|'0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com'