2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2003-10-05 02:09:26 -04:00
|
|
|
require 'test/unit'
|
2003-10-04 00:02:16 -04:00
|
|
|
require 'uri/ldap'
|
2003-10-05 02:09:26 -04:00
|
|
|
|
2003-10-04 00:02:16 -04:00
|
|
|
module URI
|
|
|
|
|
2003-10-05 02:09:26 -04:00
|
|
|
|
|
|
|
class TestLDAP < Test::Unit::TestCase
|
2003-10-04 00:02:16 -04:00
|
|
|
def setup
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
end
|
|
|
|
|
2003-10-05 02:09:26 -04:00
|
|
|
def uri_to_ary(uri)
|
|
|
|
uri.class.component.collect {|c| uri.send(c)}
|
|
|
|
end
|
|
|
|
|
2003-10-04 00:02:16 -04:00
|
|
|
def test_parse
|
|
|
|
url = 'ldap://ldap.jaist.ac.jp/o=JAIST,c=JP?sn?base?(sn=ttate*)'
|
|
|
|
u = URI.parse(url)
|
|
|
|
assert_kind_of(URI::LDAP, u)
|
|
|
|
assert_equal(url, u.to_s)
|
|
|
|
assert_equal('o=JAIST,c=JP', u.dn)
|
|
|
|
assert_equal('sn', u.attributes)
|
|
|
|
assert_equal('base', u.scope)
|
|
|
|
assert_equal('(sn=ttate*)', u.filter)
|
|
|
|
assert_equal(nil, u.extensions)
|
|
|
|
|
|
|
|
u.scope = URI::LDAP::SCOPE_SUB
|
|
|
|
u.attributes = 'sn,cn,mail'
|
|
|
|
assert_equal('ldap://ldap.jaist.ac.jp/o=JAIST,c=JP?sn,cn,mail?sub?(sn=ttate*)', u.to_s)
|
|
|
|
assert_equal('o=JAIST,c=JP', u.dn)
|
|
|
|
assert_equal('sn,cn,mail', u.attributes)
|
|
|
|
assert_equal('sub', u.scope)
|
|
|
|
assert_equal('(sn=ttate*)', u.filter)
|
|
|
|
assert_equal(nil, u.extensions)
|
|
|
|
|
|
|
|
# from RFC2255, section 6.
|
2010-12-05 20:41:10 -05:00
|
|
|
{
|
2003-10-04 00:02:16 -04:00
|
|
|
'ldap:///o=University%20of%20Michigan,c=US' =>
|
2009-03-05 22:56:38 -05:00
|
|
|
['ldap', nil, URI::LDAP::DEFAULT_PORT,
|
|
|
|
'o=University%20of%20Michigan,c=US',
|
2003-10-04 00:02:16 -04:00
|
|
|
nil, nil, nil, nil],
|
|
|
|
|
|
|
|
'ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US' =>
|
2009-03-05 22:56:38 -05:00
|
|
|
['ldap', 'ldap.itd.umich.edu', URI::LDAP::DEFAULT_PORT,
|
|
|
|
'o=University%20of%20Michigan,c=US',
|
2003-10-04 00:02:16 -04:00
|
|
|
nil, nil, nil, nil],
|
|
|
|
|
|
|
|
'ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress' =>
|
2009-03-05 22:56:38 -05:00
|
|
|
['ldap', 'ldap.itd.umich.edu', URI::LDAP::DEFAULT_PORT,
|
2003-10-04 00:02:16 -04:00
|
|
|
'o=University%20of%20Michigan,c=US',
|
|
|
|
'postalAddress', nil, nil, nil],
|
|
|
|
|
|
|
|
'ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)' =>
|
2009-03-05 22:56:38 -05:00
|
|
|
['ldap', 'host.com', 6666,
|
2003-10-04 00:02:16 -04:00
|
|
|
'o=University%20of%20Michigan,c=US',
|
|
|
|
nil, 'sub', '(cn=Babs%20Jensen)', nil],
|
|
|
|
|
|
|
|
'ldap://ldap.itd.umich.edu/c=GB?objectClass?one' =>
|
2009-03-05 22:56:38 -05:00
|
|
|
['ldap', 'ldap.itd.umich.edu', URI::LDAP::DEFAULT_PORT,
|
|
|
|
'c=GB',
|
2003-10-04 00:02:16 -04:00
|
|
|
'objectClass', 'one', nil, nil],
|
|
|
|
|
|
|
|
'ldap://ldap.question.com/o=Question%3f,c=US?mail' =>
|
2009-03-05 22:56:38 -05:00
|
|
|
['ldap', 'ldap.question.com', URI::LDAP::DEFAULT_PORT,
|
2003-10-04 00:02:16 -04:00
|
|
|
'o=Question%3f,c=US',
|
|
|
|
'mail', nil, nil, nil],
|
|
|
|
|
|
|
|
'ldap://ldap.netscape.com/o=Babsco,c=US??(int=%5c00%5c00%5c00%5c04)' =>
|
2009-03-05 22:56:38 -05:00
|
|
|
['ldap', 'ldap.netscape.com', URI::LDAP::DEFAULT_PORT,
|
2003-10-04 00:02:16 -04:00
|
|
|
'o=Babsco,c=US',
|
|
|
|
nil, '(int=%5c00%5c00%5c00%5c04)', nil, nil],
|
|
|
|
|
|
|
|
'ldap:///??sub??bindname=cn=Manager%2co=Foo' =>
|
2009-03-05 22:56:38 -05:00
|
|
|
['ldap', nil, URI::LDAP::DEFAULT_PORT,
|
2003-10-04 00:02:16 -04:00
|
|
|
'',
|
|
|
|
nil, 'sub', nil, 'bindname=cn=Manager%2co=Foo'],
|
|
|
|
|
|
|
|
'ldap:///??sub??!bindname=cn=Manager%2co=Foo' =>
|
2009-03-05 22:56:38 -05:00
|
|
|
['ldap', nil, URI::LDAP::DEFAULT_PORT,
|
2003-10-04 00:02:16 -04:00
|
|
|
'',
|
|
|
|
nil, 'sub', nil, '!bindname=cn=Manager%2co=Foo'],
|
2010-01-25 18:12:50 -05:00
|
|
|
}.each do |url2, ary|
|
|
|
|
u = URI.parse(url2)
|
2003-10-05 02:09:26 -04:00
|
|
|
assert_equal(ary, uri_to_ary(u))
|
2003-10-04 00:02:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_select
|
|
|
|
u = URI.parse('ldap:///??sub??!bindname=cn=Manager%2co=Foo')
|
2003-10-05 02:09:26 -04:00
|
|
|
assert_equal(uri_to_ary(u), u.select(*u.component))
|
2008-09-24 13:44:39 -04:00
|
|
|
assert_raise(ArgumentError) do
|
2003-10-04 00:02:16 -04:00
|
|
|
u.select(:scheme, :host, :not_exist, :port)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2003-10-05 02:09:26 -04:00
|
|
|
|
2003-10-04 00:02:16 -04:00
|
|
|
end
|