File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ def Dataset::read_ldif io
6060 # $1 is the attribute name
6161 # $2 is a colon iff the attr-value is base-64 encoded
6262 # $' is the attr-value
63- #attrvalue = ($2 == ":") ? Base64.decode64($') : $'
63+ # Avoid the Base64 class because not all Ruby versions have it.
6464 attrvalue = ( $2 == ":" ) ? $'. unpack ( 'm' ) . shift : $'
6565 ds [ dn ] [ $1. downcase . intern ] << attrvalue
6666 end
@@ -78,6 +78,28 @@ def initialize
7878 end
7979
8080
81+ def to_ldif
82+ ary = [ ]
83+ ary += ( @comments || [ ] )
84+
85+ keys . sort . each { |dn |
86+ ary << "dn: #{ dn } "
87+
88+ self [ dn ] . keys . map { |sym | sym . to_s } . sort . each { |attr |
89+ self [ dn ] [ attr . intern ] . each { |val |
90+ ary << "#{ attr } : #{ val } "
91+ }
92+ }
93+
94+ ary << ""
95+ }
96+
97+ block_given? and ary . each { |line | yield line }
98+
99+ ary
100+ end
101+
102+
81103end # Dataset
82104
83105end # LDAP
Original file line number Diff line number Diff line change 55
66$:. unshift "lib"
77
8+ require 'test/unit'
9+ require 'tests/testber'
10+ require 'tests/testldif'
11+ require 'tests/testldap'
12+
813require 'net/ldap'
914require 'net/ldif'
1015
@@ -51,6 +56,16 @@ def test_ldif
5156 }
5257 end
5358
59+ # TODO, need some tests.
60+ # Must test folded lines and base64-encoded lines as well as normal ones.
61+ def test_to_ldif
62+ File . open ( TestLdifFilename , "r" ) { |f |
63+ ds = Net ::LDAP ::Dataset ::read_ldif ( f )
64+ ds . to_ldif
65+ assert_equal ( true , false ) # REMOVE WHEN WE HAVE SOME TESTS HERE.
66+ }
67+ end
68+
5469
5570end
5671
You can’t perform that action at this time.
0 commit comments