annotate .svn/pristine/5d/5d08d1e25f5add23341eebe953f9997482bf5a56.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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