powerhome-activeldap 3.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +6 -0
  3. data/COPYING +340 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE +59 -0
  6. data/README.textile +140 -0
  7. data/TODO +32 -0
  8. data/benchmark/README.md +64 -0
  9. data/benchmark/bench-backend.rb +247 -0
  10. data/benchmark/bench-instantiate.rb +98 -0
  11. data/benchmark/config.yaml.sample +5 -0
  12. data/doc/text/development.textile +54 -0
  13. data/doc/text/news.textile +811 -0
  14. data/doc/text/rails.textile +144 -0
  15. data/doc/text/tutorial.textile +1010 -0
  16. data/examples/config.yaml.example +5 -0
  17. data/examples/example.der +0 -0
  18. data/examples/example.jpg +0 -0
  19. data/examples/groupadd +41 -0
  20. data/examples/groupdel +35 -0
  21. data/examples/groupls +49 -0
  22. data/examples/groupmod +42 -0
  23. data/examples/lpasswd +55 -0
  24. data/examples/objects/group.rb +13 -0
  25. data/examples/objects/ou.rb +4 -0
  26. data/examples/objects/user.rb +20 -0
  27. data/examples/ouadd +38 -0
  28. data/examples/useradd +45 -0
  29. data/examples/useradd-binary +53 -0
  30. data/examples/userdel +34 -0
  31. data/examples/userls +50 -0
  32. data/examples/usermod +42 -0
  33. data/examples/usermod-binary-add +50 -0
  34. data/examples/usermod-binary-add-time +54 -0
  35. data/examples/usermod-binary-del +48 -0
  36. data/examples/usermod-lang-add +43 -0
  37. data/lib/active_ldap.rb +85 -0
  38. data/lib/active_ldap/action_controller/ldap_benchmarking.rb +55 -0
  39. data/lib/active_ldap/acts/tree.rb +78 -0
  40. data/lib/active_ldap/adapter/base.rb +707 -0
  41. data/lib/active_ldap/adapter/jndi.rb +184 -0
  42. data/lib/active_ldap/adapter/jndi_connection.rb +185 -0
  43. data/lib/active_ldap/adapter/ldap.rb +290 -0
  44. data/lib/active_ldap/adapter/ldap_ext.rb +105 -0
  45. data/lib/active_ldap/adapter/net_ldap.rb +309 -0
  46. data/lib/active_ldap/adapter/net_ldap_ext.rb +23 -0
  47. data/lib/active_ldap/association/belongs_to.rb +47 -0
  48. data/lib/active_ldap/association/belongs_to_many.rb +58 -0
  49. data/lib/active_ldap/association/children.rb +21 -0
  50. data/lib/active_ldap/association/collection.rb +105 -0
  51. data/lib/active_ldap/association/has_many.rb +31 -0
  52. data/lib/active_ldap/association/has_many_utils.rb +44 -0
  53. data/lib/active_ldap/association/has_many_wrap.rb +75 -0
  54. data/lib/active_ldap/association/proxy.rb +107 -0
  55. data/lib/active_ldap/associations.rb +205 -0
  56. data/lib/active_ldap/attribute_methods.rb +23 -0
  57. data/lib/active_ldap/attribute_methods/before_type_cast.rb +24 -0
  58. data/lib/active_ldap/attribute_methods/dirty.rb +43 -0
  59. data/lib/active_ldap/attribute_methods/query.rb +31 -0
  60. data/lib/active_ldap/attribute_methods/read.rb +44 -0
  61. data/lib/active_ldap/attribute_methods/write.rb +38 -0
  62. data/lib/active_ldap/attributes.rb +176 -0
  63. data/lib/active_ldap/base.rb +1410 -0
  64. data/lib/active_ldap/callbacks.rb +71 -0
  65. data/lib/active_ldap/command.rb +49 -0
  66. data/lib/active_ldap/compatible.rb +44 -0
  67. data/lib/active_ldap/configuration.rb +147 -0
  68. data/lib/active_ldap/connection.rb +299 -0
  69. data/lib/active_ldap/distinguished_name.rb +291 -0
  70. data/lib/active_ldap/entry_attribute.rb +78 -0
  71. data/lib/active_ldap/escape.rb +12 -0
  72. data/lib/active_ldap/get_text.rb +20 -0
  73. data/lib/active_ldap/get_text/parser.rb +161 -0
  74. data/lib/active_ldap/helper.rb +92 -0
  75. data/lib/active_ldap/human_readable.rb +133 -0
  76. data/lib/active_ldap/ldap_error.rb +74 -0
  77. data/lib/active_ldap/ldif.rb +930 -0
  78. data/lib/active_ldap/log_subscriber.rb +50 -0
  79. data/lib/active_ldap/object_class.rb +95 -0
  80. data/lib/active_ldap/operations.rb +624 -0
  81. data/lib/active_ldap/persistence.rb +100 -0
  82. data/lib/active_ldap/populate.rb +53 -0
  83. data/lib/active_ldap/railtie.rb +43 -0
  84. data/lib/active_ldap/railties/controller_runtime.rb +48 -0
  85. data/lib/active_ldap/schema.rb +701 -0
  86. data/lib/active_ldap/schema/syntaxes.rb +422 -0
  87. data/lib/active_ldap/timeout.rb +75 -0
  88. data/lib/active_ldap/timeout_stub.rb +17 -0
  89. data/lib/active_ldap/user_password.rb +99 -0
  90. data/lib/active_ldap/validations.rb +200 -0
  91. data/lib/active_ldap/version.rb +3 -0
  92. data/lib/active_ldap/xml.rb +139 -0
  93. data/lib/rails/generators/active_ldap/model/USAGE +18 -0
  94. data/lib/rails/generators/active_ldap/model/model_generator.rb +47 -0
  95. data/lib/rails/generators/active_ldap/model/templates/model_active_ldap.rb +3 -0
  96. data/lib/rails/generators/active_ldap/scaffold/scaffold_generator.rb +14 -0
  97. data/lib/rails/generators/active_ldap/scaffold/templates/ldap.yml +19 -0
  98. data/po/en/active-ldap.po +4029 -0
  99. data/po/ja/active-ldap.po +4060 -0
  100. data/test/add-phonetic-attribute-options-to-slapd.ldif +10 -0
  101. data/test/al-test-utils.rb +428 -0
  102. data/test/command.rb +111 -0
  103. data/test/config.yaml.sample +6 -0
  104. data/test/fixtures/lower_case_object_class_schema.rb +802 -0
  105. data/test/run-test.rb +34 -0
  106. data/test/test_acts_as_tree.rb +60 -0
  107. data/test/test_adapter.rb +121 -0
  108. data/test/test_associations.rb +701 -0
  109. data/test/test_attributes.rb +117 -0
  110. data/test/test_base.rb +1214 -0
  111. data/test/test_base_per_instance.rb +61 -0
  112. data/test/test_bind.rb +62 -0
  113. data/test/test_callback.rb +31 -0
  114. data/test/test_configuration.rb +40 -0
  115. data/test/test_connection.rb +82 -0
  116. data/test/test_connection_per_class.rb +112 -0
  117. data/test/test_connection_per_dn.rb +112 -0
  118. data/test/test_dirty.rb +98 -0
  119. data/test/test_dn.rb +172 -0
  120. data/test/test_find.rb +176 -0
  121. data/test/test_groupadd.rb +50 -0
  122. data/test/test_groupdel.rb +46 -0
  123. data/test/test_groupls.rb +107 -0
  124. data/test/test_groupmod.rb +51 -0
  125. data/test/test_ldif.rb +1890 -0
  126. data/test/test_load.rb +133 -0
  127. data/test/test_lpasswd.rb +75 -0
  128. data/test/test_object_class.rb +74 -0
  129. data/test/test_persistence.rb +131 -0
  130. data/test/test_reflection.rb +175 -0
  131. data/test/test_schema.rb +559 -0
  132. data/test/test_syntax.rb +444 -0
  133. data/test/test_user.rb +217 -0
  134. data/test/test_user_password.rb +108 -0
  135. data/test/test_useradd-binary.rb +62 -0
  136. data/test/test_useradd.rb +57 -0
  137. data/test/test_userdel.rb +48 -0
  138. data/test/test_userls.rb +91 -0
  139. data/test/test_usermod-binary-add-time.rb +65 -0
  140. data/test/test_usermod-binary-add.rb +64 -0
  141. data/test/test_usermod-binary-del.rb +66 -0
  142. data/test/test_usermod-lang-add.rb +59 -0
  143. data/test/test_usermod.rb +58 -0
  144. data/test/test_validation.rb +274 -0
  145. metadata +379 -0
data/TODO ADDED
@@ -0,0 +1,32 @@
1
+ - [1.1.x] add :readonly option to :has_many.
2
+ - Work as framework on Rails.
3
+ - How to support dSCorePropagationData? ignore it?
4
+ all systemOnly == "TRUE" attribute can be ignored?
5
+ - Add parsing position to DistinguishedNameInvalid error like
6
+ <NAME=VALUE,INVALID_HERE>@<REST=INPUT>.
7
+ - Support TLS optioins (e.g. CA certification file and so on)
8
+ - Provide FormHelper for LDAP entry's attribute to handle multiple values
9
+ (["foo", "bar", ...]) and option value ({"binary" => "..."},
10
+ {"lang-en-us" => "..."})
11
+ - Test SASL bind.
12
+ - Add result pagination via LDAP::Controls
13
+ - serialize & serialized_attributes
14
+ - schema mgmt - how does AR handle it?
15
+ - columns() -- ?
16
+ http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000865
17
+ - provide full documentation for new API.
18
+ - handle all exception raised from Ruby/LDAP and wrap as
19
+ ActiveLdap exception. I think we need to develop an
20
+ application using ActiveLdap.
21
+ - Add locking around Timeout.alarm() to ensure a multithreaded ruby
22
+ app doesn't hit any race conditions
23
+ - Add AR matching exceptions:
24
+ * ActiveRecordError -- ActiveLdapError as base
25
+ * AssociationTypeMismatch
26
+ * SerializationTypeMismatch
27
+ * ConnectionNotEstablished
28
+ * RecordNotFound
29
+ * LdapActionInvalid - like StatementInvalid
30
+ * MultiparameterAssignmentErrors
31
+ * AttributeAssignmentError
32
+ * RecordNotSaved
@@ -0,0 +1,64 @@
1
+ # README
2
+
3
+ This document describes how to run benchmarks under
4
+ benchmark/ directory.
5
+
6
+ ## Configure your LDAP server
7
+
8
+ You need a LDAP server to run benchmarks. This is dependes
9
+ on your environment.
10
+
11
+ In this document, we assume that you configure your LDAP
12
+ server by the following configuration:
13
+
14
+ * host: 127.0.0.1
15
+ * base DN: dc=bench,dc=local
16
+ * encryption: startTLS
17
+ * bind DN: cn=admin,dc=local
18
+ * password: secret
19
+
20
+ ## Configure ActiveLdap to connect to your LDAP server
21
+
22
+ You need an ActiveLdap configuration in
23
+ benchmark/config.yaml to connect to your LDAP server. There
24
+ is a sample configuration in
25
+ benchmark/config.yaml.sample. It's good to start from it.
26
+
27
+ % cp benchmark/config.yaml.sample benchmark/config.yaml
28
+ % editor benchmark/config.yaml
29
+
30
+ The configuration uses the same format of ldap.yaml.
31
+
32
+ ## Run benchmarks
33
+
34
+ You just run a bencmark script. It loads
35
+ benchmark/config.yaml and populate benchmark data automatically.
36
+
37
+ % ruby benchmark/bench-backend.rb
38
+ Populating...
39
+
40
+ Rehearsal ---------------------------------------------------------------
41
+ 1x: AL(LDAP) 0.220000 0.000000 0.220000 ( 0.234775)
42
+ 1x: AL(Net::LDAP) 0.280000 0.000000 0.280000 ( 0.273048)
43
+ 1x: AL(LDAP: No Obj) 0.000000 0.000000 0.000000 ( 0.009217)
44
+ 1x: AL(Net::LDAP: No Obj) 0.060000 0.000000 0.060000 ( 0.056727)
45
+ 1x: LDAP 0.000000 0.000000 0.000000 ( 0.003261)
46
+ 1x: Net::LDAP 0.040000 0.000000 0.040000 ( 0.029862)
47
+ ------------------------------------------------------ total: 0.600000sec
48
+
49
+ user system total real
50
+ 1x: AL(LDAP) 0.200000 0.000000 0.200000 ( 0.195660)
51
+ 1x: AL(Net::LDAP) 0.220000 0.000000 0.220000 ( 0.213444)
52
+ 1x: AL(LDAP: No Obj) 0.010000 0.000000 0.010000 ( 0.009000)
53
+ 1x: AL(Net::LDAP: No Obj) 0.030000 0.000000 0.030000 ( 0.026847)
54
+ 1x: LDAP 0.000000 0.000000 0.000000 ( 0.003377)
55
+ 1x: Net::LDAP 0.020000 0.000000 0.020000 ( 0.022662)
56
+
57
+ Entries processed by Ruby/ActiveLdap + LDAP: 100
58
+ Entries processed by Ruby/ActiveLdap + Net::LDAP: 100
59
+ Entries processed by Ruby/ActiveLdap + LDAP: (without object creation): 100
60
+ Entries processed by Ruby/ActiveLdap + Net::LDAP: (without object creation): 100
61
+ Entries processed by Ruby/LDAP: 100
62
+ Entries processed by Net::LDAP: 100
63
+
64
+ Cleaning...
@@ -0,0 +1,247 @@
1
+ base = File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift(File.expand_path(base))
3
+ $LOAD_PATH.unshift(File.expand_path(File.join(base, "..", "lib")))
4
+
5
+ require "active_ldap"
6
+ require "benchmark"
7
+
8
+ include ActiveLdap::GetTextSupport
9
+
10
+ argv = ARGV.dup
11
+ unless argv.include?("--config")
12
+ argv.unshift("--config", File.join(base, "config.yaml"))
13
+ end
14
+ argv, opts, options = ActiveLdap::Command.parse_options(argv) do |opts, options|
15
+ options.prefix = "ou=People"
16
+
17
+ opts.on("--prefix=PREFIX",
18
+ _("Specify prefix for benchmarking"),
19
+ _("(default: %s)") % options.prefix) do |prefix|
20
+ options.prefix = prefix
21
+ end
22
+ end
23
+
24
+ ActiveLdap::Base.setup_connection
25
+ config = ActiveLdap::Base.configuration
26
+
27
+ LDAP_HOST = config[:host]
28
+ LDAP_METHOD = config[:method]
29
+ if LDAP_METHOD == :ssl
30
+ LDAP_PORT = config[:port] || URI::LDAPS::DEFAULT_PORT
31
+ else
32
+ LDAP_PORT = config[:port] || URI::LDAP::DEFAULT_PORT
33
+ end
34
+ LDAP_BASE = config[:base]
35
+ LDAP_PREFIX = options.prefix
36
+ LDAP_USER = config[:bind_dn]
37
+ LDAP_PASSWORD = config[:password]
38
+
39
+ class ALUser < ActiveLdap::Base
40
+ ldap_mapping :dn_attribute => 'uid', :prefix => LDAP_PREFIX,
41
+ :classes => ['posixAccount', 'person']
42
+ end
43
+
44
+ class ALUserLdap < ALUser
45
+ end
46
+ ALUserLdap.setup_connection(config.merge(:adapter => "ldap"))
47
+
48
+ class ALUserNetLdap < ALUser
49
+ end
50
+ ALUserNetLdap.setup_connection(config.merge(:adapter => "net-ldap"))
51
+
52
+ def search_al_ldap
53
+ count = 0
54
+ ALUserLdap.find(:all).each do |e|
55
+ count += 1
56
+ end
57
+ count
58
+ end
59
+
60
+ def search_al_net_ldap
61
+ count = 0
62
+ ALUserNetLdap.find(:all).each do |e|
63
+ count += 1
64
+ end
65
+ count
66
+ end
67
+
68
+ def search_al_ldap_without_object_creation
69
+ count = 0
70
+ ALUserLdap.search.each do |e|
71
+ count += 1
72
+ end
73
+ count
74
+ end
75
+
76
+ def search_al_net_ldap_without_object_creation
77
+ count = 0
78
+ ALUserNetLdap.search.each do |e|
79
+ count += 1
80
+ end
81
+ count
82
+ end
83
+
84
+ # === search_ldap
85
+ #
86
+ def search_ldap(conn)
87
+ count = 0
88
+ conn.search("#{LDAP_PREFIX},#{LDAP_BASE}",
89
+ LDAP::LDAP_SCOPE_SUBTREE,
90
+ "(uid=*)") do |e|
91
+ count += 1
92
+ end
93
+ count
94
+ end # -- search_ldap
95
+
96
+ def search_net_ldap(conn)
97
+ count = 0
98
+ conn.search(:base => "#{LDAP_PREFIX},#{LDAP_BASE}",
99
+ :scope => Net::LDAP::SearchScope_WholeSubtree,
100
+ :filter => "(uid=*)") do |e|
101
+ count += 1
102
+ end
103
+ count
104
+ end
105
+
106
+ def ldap_connection
107
+ require 'ldap'
108
+ if LDAP_METHOD == :tls
109
+ conn = LDAP::SSLConn.new(LDAP_HOST, LDAP_PORT, true)
110
+ else
111
+ conn = LDAP::Conn.new(LDAP_HOST, LDAP_PORT)
112
+ end
113
+ conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3)
114
+ conn.bind(LDAP_USER, LDAP_PASSWORD) if LDAP_USER and LDAP_PASSWORD
115
+ conn
116
+ rescue LoadError
117
+ nil
118
+ end
119
+
120
+ def net_ldap_connection
121
+ require 'net/ldap'
122
+ net_ldap_conn = Net::LDAP::Connection.new(:host => LDAP_HOST,
123
+ :port => LDAP_PORT)
124
+ if LDAP_USER and LDAP_PASSWORD
125
+ net_ldap_conn.setup_encryption(:method => :start_tls) if LDAP_METHOD == :tls
126
+ net_ldap_conn.bind(:method => :simple,
127
+ :username => LDAP_USER,
128
+ :password => LDAP_PASSWORD)
129
+ end
130
+ net_ldap_conn
131
+ rescue LoadError
132
+ nil
133
+ end
134
+
135
+ def populate_base
136
+ ActiveLdap::Populate.ensure_base
137
+ if ActiveLdap::Base.search.empty?
138
+ raise "Can't populate #{ActiveLdap::Base.base}"
139
+ end
140
+ end
141
+
142
+ def populate_users
143
+ ou_class = Class.new(ActiveLdap::Base)
144
+ ou_class.ldap_mapping :dn_attribute => "ou",
145
+ :prefix => "",
146
+ :classes => ["top", "organizationalUnit"]
147
+ ou_class.new(LDAP_PREFIX.split(/=/)[1]).save!
148
+
149
+ 100.times do |i|
150
+ name = i.to_s
151
+ user = ALUser.new(name)
152
+ user.uid_number = 100000 + i
153
+ user.gid_number = 100000 + i
154
+ user.cn = name
155
+ user.sn = name
156
+ user.home_directory = "/nonexistent"
157
+ user.save!
158
+ end
159
+ end
160
+
161
+ def populate
162
+ populate_base
163
+ populate_users
164
+ end
165
+
166
+ # === main
167
+ #
168
+ def main(do_populate)
169
+ if do_populate
170
+ puts(_("Populating..."))
171
+ dumped_data = ActiveLdap::Base.dump(:scope => :sub)
172
+ ActiveLdap::Base.delete_all(nil, :scope => :sub)
173
+ populate
174
+ puts
175
+ end
176
+
177
+ # Standard connection
178
+ #
179
+ ldap_conn = ldap_connection
180
+ net_ldap_conn = net_ldap_connection
181
+
182
+ al_ldap_count = 0
183
+ al_net_ldap_count = 0
184
+ al_ldap_count_without_object_creation = 0
185
+ al_net_ldap_count_without_object_creation = 0
186
+ ldap_count = 0
187
+ net_ldap_count = 0
188
+ Benchmark.bmbm(20) do |x|
189
+ [1].each do |n|
190
+ GC.start
191
+ x.report("%3dx: AL(LDAP)" % n) do
192
+ n.times {al_ldap_count = search_al_ldap}
193
+ end
194
+ GC.start
195
+ x.report("%3dx: AL(Net::LDAP)" % n) do
196
+ n.times {al_net_ldap_count = search_al_net_ldap}
197
+ end
198
+ GC.start
199
+ x.report("%3dx: AL(LDAP: No Obj)" % n) do
200
+ n.times do
201
+ al_ldap_count_without_object_creation =
202
+ search_al_ldap_without_object_creation
203
+ end
204
+ end
205
+ x.report("%3dx: AL(Net::LDAP: No Obj)" % n) do
206
+ n.times do
207
+ al_net_ldap_count_without_object_creation =
208
+ search_al_net_ldap_without_object_creation
209
+ end
210
+ end
211
+ GC.start
212
+ if ldap_conn
213
+ x.report("%3dx: LDAP" % n) do
214
+ n.times {ldap_count = search_ldap(ldap_conn)}
215
+ end
216
+ end
217
+ GC.start
218
+ if net_ldap_conn
219
+ x.report("%3dx: Net::LDAP" % n) do
220
+ n.times {net_ldap_count = search_net_ldap(net_ldap_conn)}
221
+ end
222
+ end
223
+ end
224
+ end
225
+
226
+ puts
227
+ puts(_("Entries processed by Ruby/ActiveLdap + LDAP: %d") % al_ldap_count)
228
+ puts(_("Entries processed by Ruby/ActiveLdap + Net::LDAP: %d") % \
229
+ al_net_ldap_count)
230
+ puts(_("Entries processed by Ruby/ActiveLdap + LDAP: " \
231
+ "(without object creation): %d") % \
232
+ al_ldap_count_without_object_creation)
233
+ puts(_("Entries processed by Ruby/ActiveLdap + Net::LDAP: " \
234
+ "(without object creation): %d") % \
235
+ al_net_ldap_count_without_object_creation)
236
+ puts(_("Entries processed by Ruby/LDAP: %d") % ldap_count)
237
+ puts(_("Entries processed by Net::LDAP: %d") % net_ldap_count)
238
+ ensure
239
+ if do_populate
240
+ puts
241
+ puts(_("Cleaning..."))
242
+ ActiveLdap::Base.delete_all(nil, :scope => :sub)
243
+ ActiveLdap::Base.load(dumped_data)
244
+ end
245
+ end
246
+
247
+ main(LDAP_USER && LDAP_PASSWORD)
@@ -0,0 +1,98 @@
1
+ base = File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift(File.expand_path(base))
3
+ $LOAD_PATH.unshift(File.expand_path(File.join(base, "..", "lib")))
4
+
5
+ require "active_ldap"
6
+ require "benchmark"
7
+
8
+ include ActiveLdap::GetTextSupport
9
+
10
+ argv = ARGV.dup
11
+ unless argv.include?("--config")
12
+ argv.unshift("--config", File.join(base, "config.yaml"))
13
+ end
14
+ argv, opts, options = ActiveLdap::Command.parse_options(argv) do |opts, options|
15
+ options.prefix = "ou=People"
16
+
17
+ opts.on("--prefix=PREFIX",
18
+ _("Specify prefix for benchmarking"),
19
+ _("(default: %s)") % options.prefix) do |prefix|
20
+ options.prefix = prefix
21
+ end
22
+ end
23
+
24
+ ActiveLdap::Base.setup_connection
25
+ config = ActiveLdap::Base.configuration
26
+
27
+ LDAP_PREFIX = options.prefix
28
+ LDAP_USER = config[:bind_dn]
29
+ LDAP_PASSWORD = config[:password]
30
+
31
+ N_USERS = 100
32
+
33
+ class ALUser < ActiveLdap::Base
34
+ ldap_mapping :dn_attribute => 'uid', :prefix => LDAP_PREFIX,
35
+ :classes => ['posixAccount', 'person']
36
+ end
37
+
38
+ def populate_base
39
+ ActiveLdap::Populate.ensure_base
40
+ if ActiveLdap::Base.search.empty?
41
+ raise "Can't populate #{ActiveLdap::Base.base}"
42
+ end
43
+ end
44
+
45
+ def populate_users
46
+ ou_class = Class.new(ActiveLdap::Base)
47
+ ou_class.ldap_mapping :dn_attribute => "ou",
48
+ :prefix => "",
49
+ :classes => ["top", "organizationalUnit"]
50
+ ou_class.new(LDAP_PREFIX.split(/=/)[1]).save!
51
+
52
+ N_USERS.times do |i|
53
+ name = i.to_s
54
+ user = ALUser.new(name)
55
+ user.uid_number = 100000 + i
56
+ user.gid_number = 100000 + i
57
+ user.cn = name
58
+ user.sn = name
59
+ user.home_directory = "/nonexistent"
60
+ user.save!
61
+ end
62
+ end
63
+
64
+ def populate
65
+ populate_base
66
+ populate_users
67
+ end
68
+
69
+ def main(do_populate)
70
+ if do_populate
71
+ puts(_("Populating..."))
72
+ dumped_data = ActiveLdap::Base.dump(:scope => :sub)
73
+ ActiveLdap::Base.delete_all(nil, :scope => :sub)
74
+ populate
75
+ puts
76
+ end
77
+
78
+ Benchmark.bmbm(20) do |x|
79
+ n = 100
80
+ GC.start
81
+ x.report("search 100 entries") do
82
+ n.times {ALUser.search}
83
+ end
84
+ GC.start
85
+ x.report("instantiate 1 entry") do
86
+ n.times {ALUser.first}
87
+ end
88
+ end
89
+ ensure
90
+ if do_populate
91
+ puts
92
+ puts(_("Cleaning..."))
93
+ ActiveLdap::Base.delete_all(nil, :scope => :sub)
94
+ ActiveLdap::Base.load(dumped_data)
95
+ end
96
+ end
97
+
98
+ main(LDAP_USER && LDAP_PASSWORD)
@@ -0,0 +1,5 @@
1
+ host: 127.0.0.1
2
+ base: dc=bench,dc=local
3
+ method: :tls
4
+ bind_dn: cn=admin,dc=local
5
+ password: secret