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