To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 5d / 5d08d1e25f5add23341eebe953f9997482bf5a56.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (1.73 KB)
| 1 |
# $Id: testldif.rb 61 2006-04-18 20:55:55Z blackhedd $ |
|---|---|
| 2 |
# |
| 3 |
# |
| 4 |
|
| 5 |
|
| 6 |
$:.unshift "lib" |
| 7 |
|
| 8 |
require 'test/unit' |
| 9 |
|
| 10 |
require 'net/ldap' |
| 11 |
require 'net/ldif' |
| 12 |
|
| 13 |
require 'sha1' |
| 14 |
require 'base64' |
| 15 |
|
| 16 |
class TestLdif < Test::Unit::TestCase |
| 17 |
|
| 18 |
TestLdifFilename = "tests/testdata.ldif" |
| 19 |
|
| 20 |
def test_empty_ldif |
| 21 |
ds = Net::LDAP::Dataset::read_ldif( StringIO.new ) |
| 22 |
assert_equal( true, ds.empty? ) |
| 23 |
end |
| 24 |
|
| 25 |
def test_ldif_with_comments |
| 26 |
str = ["# Hello from LDIF-land", "# This is an unterminated comment"] |
| 27 |
io = StringIO.new( str[0] + "\r\n" + str[1] ) |
| 28 |
ds = Net::LDAP::Dataset::read_ldif( io ) |
| 29 |
assert_equal( str, ds.comments ) |
| 30 |
end |
| 31 |
|
| 32 |
def test_ldif_with_password |
| 33 |
psw = "goldbricks" |
| 34 |
hashed_psw = "{SHA}" + Base64::encode64( SHA1.new(psw).digest ).chomp
|
| 35 |
|
| 36 |
ldif_encoded = Base64::encode64( hashed_psw ).chomp |
| 37 |
ds = Net::LDAP::Dataset::read_ldif( StringIO.new( "dn: Goldbrick\r\nuserPassword:: #{ldif_encoded}\r\n\r\n" ))
|
| 38 |
recovered_psw = ds["Goldbrick"][:userpassword].shift |
| 39 |
assert_equal( hashed_psw, recovered_psw ) |
| 40 |
end |
| 41 |
|
| 42 |
def test_ldif_with_continuation_lines |
| 43 |
ds = Net::LDAP::Dataset::read_ldif( StringIO.new( "dn: abcdefg\r\n hijklmn\r\n\r\n" )) |
| 44 |
assert_equal( true, ds.has_key?( "abcdefg hijklmn" )) |
| 45 |
end |
| 46 |
|
| 47 |
# TODO, INADEQUATE. We need some more tests |
| 48 |
# to verify the content. |
| 49 |
def test_ldif |
| 50 |
File.open( TestLdifFilename, "r" ) {|f|
|
| 51 |
ds = Net::LDAP::Dataset::read_ldif( f ) |
| 52 |
assert_equal( 13, ds.length ) |
| 53 |
} |
| 54 |
end |
| 55 |
|
| 56 |
# TODO, need some tests. |
| 57 |
# Must test folded lines and base64-encoded lines as well as normal ones. |
| 58 |
def test_to_ldif |
| 59 |
File.open( TestLdifFilename, "r" ) {|f|
|
| 60 |
ds = Net::LDAP::Dataset::read_ldif( f ) |
| 61 |
ds.to_ldif |
| 62 |
assert_equal( true, false ) # REMOVE WHEN WE HAVE SOME TESTS HERE. |
| 63 |
} |
| 64 |
end |
| 65 |
|
| 66 |
|
| 67 |
end |
| 68 |
|
| 69 |
|