activesambaldap 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/NEWS.en +9 -0
  2. data/NEWS.ja +10 -0
  3. data/README.en +310 -0
  4. data/README.ja +307 -0
  5. data/Rakefile +95 -0
  6. data/bin/asl-groupadd +70 -0
  7. data/bin/asl-groupdel +58 -0
  8. data/bin/asl-groupmod +133 -0
  9. data/bin/asl-groupshow +31 -0
  10. data/bin/asl-passwd +99 -0
  11. data/bin/asl-populate +96 -0
  12. data/bin/asl-purge +24 -0
  13. data/bin/asl-samba-computeradd +94 -0
  14. data/bin/asl-samba-groupadd +55 -0
  15. data/bin/asl-samba-groupdel +53 -0
  16. data/bin/asl-samba-groupmod +98 -0
  17. data/bin/asl-samba-useradd +98 -0
  18. data/bin/asl-samba-userdel +47 -0
  19. data/bin/asl-samba-usermod +92 -0
  20. data/bin/asl-useradd +263 -0
  21. data/bin/asl-userdel +75 -0
  22. data/bin/asl-usermod +335 -0
  23. data/bin/asl-usershow +31 -0
  24. data/lib/active_samba_ldap/account.rb +199 -0
  25. data/lib/active_samba_ldap/base.rb +126 -0
  26. data/lib/active_samba_ldap/command.rb +94 -0
  27. data/lib/active_samba_ldap/computer.rb +13 -0
  28. data/lib/active_samba_ldap/computer_account.rb +34 -0
  29. data/lib/active_samba_ldap/configuration.rb +322 -0
  30. data/lib/active_samba_ldap/dc.rb +17 -0
  31. data/lib/active_samba_ldap/entry.rb +80 -0
  32. data/lib/active_samba_ldap/group.rb +182 -0
  33. data/lib/active_samba_ldap/idmap.rb +17 -0
  34. data/lib/active_samba_ldap/ou.rb +18 -0
  35. data/lib/active_samba_ldap/populate.rb +254 -0
  36. data/lib/active_samba_ldap/samba_account.rb +200 -0
  37. data/lib/active_samba_ldap/samba_computer.rb +20 -0
  38. data/lib/active_samba_ldap/samba_group.rb +126 -0
  39. data/lib/active_samba_ldap/samba_user.rb +39 -0
  40. data/lib/active_samba_ldap/unix_id_pool.rb +41 -0
  41. data/lib/active_samba_ldap/user.rb +14 -0
  42. data/lib/active_samba_ldap/user_account.rb +30 -0
  43. data/lib/active_samba_ldap/version.rb +3 -0
  44. data/lib/active_samba_ldap.rb +29 -0
  45. data/lib/samba/encrypt.rb +86 -0
  46. data/misc/rd2html.rb +42 -0
  47. data/rails/plugin/active_samba_ldap/README +30 -0
  48. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/scaffold_asl_generator.rb +28 -0
  49. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/computer.rb +3 -0
  50. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/dc.rb +3 -0
  51. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/group.rb +3 -0
  52. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/idmap.rb +3 -0
  53. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/ldap.yml +24 -0
  54. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/ou.rb +3 -0
  55. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/samba_controller.rb +12 -0
  56. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/samba_helper.rb +2 -0
  57. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/samba_index.rhtml +17 -0
  58. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/samba_populate.rhtml +15 -0
  59. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/samba_purge.rhtml +10 -0
  60. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/unix_id_pool.rb +3 -0
  61. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/user.rb +3 -0
  62. data/rails/plugin/active_samba_ldap/init.rb +6 -0
  63. data/test/asl-test-utils.rb +276 -0
  64. data/test/command.rb +64 -0
  65. data/test/config.yaml.sample +17 -0
  66. data/test/run-test.rb +18 -0
  67. data/test/test-unit-ext/always-show-result.rb +28 -0
  68. data/test/test-unit-ext/priority.rb +159 -0
  69. data/test/test-unit-ext.rb +2 -0
  70. data/test/test_asl_groupadd.rb +69 -0
  71. data/test/test_asl_groupdel.rb +88 -0
  72. data/test/test_asl_groupmod.rb +256 -0
  73. data/test/test_asl_groupshow.rb +21 -0
  74. data/test/test_asl_passwd.rb +125 -0
  75. data/test/test_asl_populate.rb +92 -0
  76. data/test/test_asl_purge.rb +21 -0
  77. data/test/test_asl_useradd.rb +710 -0
  78. data/test/test_asl_userdel.rb +73 -0
  79. data/test/test_asl_usermod.rb +541 -0
  80. data/test/test_asl_usershow.rb +27 -0
  81. data/test/test_group.rb +21 -0
  82. data/test/test_password.rb +51 -0
  83. data/test/test_samba_encrypt.rb +36 -0
  84. data/test/test_user_home_directory.rb +43 -0
  85. metadata +177 -0
@@ -0,0 +1,710 @@
1
+ require 'asl-test-utils'
2
+
3
+ class AslUserAddTest < Test::Unit::TestCase
4
+ include AslTestUtils
5
+
6
+ def setup
7
+ super
8
+ @command = File.join(@bin_dir, "asl-useradd")
9
+ end
10
+
11
+ def test_run_as_normal_user
12
+ assert_equal([false, "", "need root authority.\n"],
13
+ run_asl_useradd_as_normal_user("user-name"))
14
+ assert_equal([false, "", "need root authority.\n"],
15
+ run_asl_useradd_as_normal_user("computer-name$",
16
+ "--computer-account"))
17
+ end
18
+
19
+ def test_exist_user
20
+ make_dummy_user do |user, password|
21
+ assert(@user_class.exists?(user.uid))
22
+ assert_equal([false, "", "user '#{user.uid}' already exists.\n"],
23
+ run_asl_useradd(user.uid))
24
+ assert(@user_class.exists?(user.uid))
25
+ end
26
+ end
27
+
28
+ def test_exist_computer
29
+ make_dummy_computer do |computer, password|
30
+ uid = computer.uid
31
+ assert(@computer_class.exists?(uid))
32
+ assert_equal([false, "", "computer '#{uid}' already exists.\n"],
33
+ run_asl_useradd(uid, "--computer-account"))
34
+ assert(@computer_class.exists?(uid))
35
+ end
36
+ end
37
+
38
+ def test_add_user
39
+ ensure_delete_user("test-user") do |uid,|
40
+ assert_asl_useradd_successfully(uid)
41
+ end
42
+ end
43
+
44
+ def test_add_computer
45
+ ensure_delete_computer("test-computer$") do |uid,|
46
+ assert_asl_useradd_successfully(uid, "--computer-account")
47
+ end
48
+
49
+ ensure_delete_computer("test-computer") do |uid,|
50
+ assert_asl_useradd_successfully(uid, "--computer-account")
51
+ end
52
+ end
53
+
54
+ def test_ou_user
55
+ ensure_delete_ou("SubOu") do |ou|
56
+ ou_class = Class.new(ActiveSambaLdap::Ou)
57
+ ou_class.ldap_mapping :prefix => @user_class.prefix
58
+ assert(!ou_class.exists?(ou))
59
+
60
+ ensure_delete_user("test-user") do |uid,|
61
+ user_class = Class.new(ActiveSambaLdap::User)
62
+ user_class.ldap_mapping :prefix => "ou=#{ou},#{@user_class.prefix}"
63
+
64
+ assert(!user_class.exists?(uid))
65
+ assert_equal([true, "", ""], run_asl_useradd(uid, "--ou", ou))
66
+ assert(user_class.exists?(uid))
67
+
68
+ user = user_class.find(uid)
69
+ assert_match(/\Auid=#{uid},ou=#{ou},/, user.dn)
70
+ end
71
+
72
+ assert(ou_class.exists?(ou))
73
+ end
74
+ end
75
+
76
+ def test_ou_computer
77
+ ensure_delete_ou("SubOu") do |ou|
78
+ ou_class = Class.new(ActiveSambaLdap::Ou)
79
+ ou_class.ldap_mapping :prefix => @computer_class.prefix
80
+ assert(!ou_class.exists?(ou))
81
+
82
+ ensure_delete_computer("test-computer$") do |uid,|
83
+ computer_class = Class.new(ActiveSambaLdap::Computer)
84
+ computer_class.ldap_mapping :prefix =>
85
+ "ou=#{ou},#{@computer_class.prefix}"
86
+
87
+ assert(!computer_class.exists?(uid))
88
+ assert_equal([true, "", ""], run_asl_useradd(uid, "--computer-account",
89
+ "--ou", ou))
90
+ assert(computer_class.exists?(uid))
91
+
92
+ computer = computer_class.find(uid)
93
+ assert_match(/\Auid=#{Regexp.escape(uid)},ou=#{ou},/, computer.dn)
94
+ end
95
+
96
+ assert(ou_class.exists?(ou))
97
+ end
98
+ end
99
+
100
+ def test_uid_number
101
+ ensure_delete_user("test-user") do |uid,|
102
+ uid_number = Integer(next_uid_number) + 10
103
+ assert_asl_useradd_successfully(uid, "--uid", uid_number)
104
+ user = @user_class.find(uid)
105
+ assert_equal(uid_number, user.uid_number.to_i)
106
+ end
107
+
108
+ ensure_delete_computer("test-computer$") do |uid,|
109
+ uid_number = Integer(next_uid_number) + 10
110
+ assert_asl_useradd_successfully(uid, "--computer-account",
111
+ "--uid", uid_number)
112
+ computer = @computer_class.find(uid)
113
+ assert_equal(uid_number, computer.uid_number.to_i)
114
+ end
115
+ end
116
+
117
+ def test_gid_number
118
+ make_dummy_group("test-group") do |group|
119
+ gid_number = group.gid_number
120
+
121
+ ensure_delete_user("test-user") do |uid,|
122
+ assert_asl_useradd_successfully(uid, "--gid", gid_number)
123
+ user = @user_class.find(uid)
124
+ assert_equal(gid_number, user.gid_number)
125
+ end
126
+
127
+ ensure_delete_computer("test-computer") do |uid,|
128
+ assert_asl_useradd_successfully(uid, "--computer-account",
129
+ "--gid", gid_number)
130
+ computer = @computer_class.find(uid)
131
+ assert_equal(gid_number, computer.gid_number)
132
+ end
133
+ end
134
+ end
135
+
136
+ def test_groups
137
+ make_dummy_group do |group1|
138
+ make_dummy_group do |group2|
139
+ make_dummy_group do |group3|
140
+ gid_numbers = [group1.gid_number,
141
+ group2.gid_number,
142
+ group3.gid_number]
143
+
144
+ ensure_delete_user("test-user") do |uid,|
145
+ args = ["--groups", gid_numbers.join(",")]
146
+ assert_asl_useradd_successfully(uid, *args)
147
+
148
+ user = @user_class.find(uid)
149
+ primary_group = @group_class.find(:first,
150
+ :attribute => "gidNumber",
151
+ :value => user.gid_number)
152
+ groups = @group_class.find(:all,
153
+ :attribute => "memberUid",
154
+ :value => uid)
155
+ assert_equal([primary_group.cn,
156
+ group1.cn,
157
+ group2.cn,
158
+ group3.cn].sort,
159
+ groups.collect {|g| g.cn}.sort)
160
+ end
161
+
162
+ ensure_delete_computer("test-computer$") do |uid,|
163
+ args = ["--computer-account", "--groups", gid_numbers.join(",")]
164
+ assert_asl_useradd_successfully(uid, *args)
165
+
166
+ computer = @computer_class.find(uid)
167
+ primary_group = @group_class.find(:first,
168
+ :attribute => "gidNumber",
169
+ :value => computer.gid_number)
170
+ groups = @group_class.find(:all,
171
+ :attribute => "memberUid",
172
+ :value => uid)
173
+ assert_equal([primary_group.cn,
174
+ group1.cn,
175
+ group2.cn,
176
+ group3.cn].sort,
177
+ groups.collect {|g| g.cn}.sort)
178
+ end
179
+ end
180
+ end
181
+ end
182
+ end
183
+
184
+ def test_create_group_user
185
+ ensure_delete_group("test-user") do |gid,|
186
+ ensure_delete_user("test-user") do |uid,|
187
+ assert_equal(gid, uid)
188
+ assert(!@group_class.exists?(gid))
189
+ assert_asl_useradd_successfully(uid, "--create-group")
190
+ assert(@group_class.exists?(gid))
191
+
192
+ user = @user_class.find(uid)
193
+ group = @group_class.find(gid)
194
+ assert_equal(group.gid_number, user.gid_number)
195
+ end
196
+ end
197
+ end
198
+
199
+ def test_create_group_computer
200
+ ensure_delete_group("test-computer") do |gid,|
201
+ ensure_delete_computer("test-computer$") do |uid,|
202
+ assert_equal("#{gid}$", uid)
203
+ assert(!@group_class.exists?(gid))
204
+ assert_asl_useradd_successfully(uid, "--create-group",
205
+ "--computer-account")
206
+ assert(@group_class.exists?(gid))
207
+
208
+ computer = @computer_class.find(uid)
209
+ group = @group_class.find(gid)
210
+ assert_equal(group.gid_number, computer.gid_number)
211
+ end
212
+ end
213
+ end
214
+
215
+ def test_comment_user
216
+ ensure_delete_user("test-user") do |uid,|
217
+ gecos = "gecos for the user #{uid}"
218
+ assert_asl_useradd_successfully(uid, "--comment", gecos)
219
+ user = @user_class.find(uid)
220
+ assert_equal(gecos, user.gecos)
221
+ end
222
+ end
223
+
224
+ def test_comment_computer
225
+ ensure_delete_computer("test-computer$") do |uid,|
226
+ gecos = "gecos for the computer #{uid}"
227
+ assert_asl_useradd_successfully(uid, "--computer-account",
228
+ "--comment", gecos)
229
+ computer = @computer_class.find(uid)
230
+ assert_equal(gecos, computer.gecos)
231
+ end
232
+ end
233
+
234
+ def test_shell_user
235
+ ensure_delete_user("test-user") do |uid,|
236
+ shell = "/bin/zsh"
237
+ assert_asl_useradd_successfully(uid, "--shell", shell)
238
+ user = @user_class.find(uid)
239
+ assert_equal(shell, user.login_shell)
240
+ end
241
+ end
242
+
243
+ def test_shell_computer
244
+ ensure_delete_computer("test-computer") do |uid,|
245
+ shell = "/bin/zsh"
246
+ assert_asl_useradd_successfully(uid, "--computer-account",
247
+ "--shell", shell)
248
+ computer = @computer_class.find(uid)
249
+ assert_equal(shell, computer.login_shell)
250
+ end
251
+ end
252
+
253
+ def test_canonical_name_user
254
+ ensure_delete_user("test-user") do |uid,|
255
+ cn = "John Kennedy"
256
+ assert_asl_useradd_successfully(uid, "--canonical-name", cn)
257
+ user = @user_class.find(uid)
258
+ assert_equal(uid, user.given_name)
259
+ assert_equal(uid, user.surname)
260
+ assert_equal(cn, user.cn)
261
+ end
262
+ end
263
+
264
+ def test_canonical_name_computer
265
+ ensure_delete_computer("test-computer$") do |uid,|
266
+ cn = "A computer"
267
+ assert_asl_useradd_successfully(uid, "--computer-account",
268
+ "--canonical-name", cn)
269
+ computer = @computer_class.find(uid)
270
+ assert_equal(uid, computer.given_name)
271
+ assert_equal(uid, computer.surname)
272
+ assert_equal(cn, computer.cn)
273
+ end
274
+ end
275
+
276
+ def test_given_name_user
277
+ ensure_delete_user("test-user") do |uid,|
278
+ given_name = "John"
279
+ assert_asl_useradd_successfully(uid, "--given-name", given_name)
280
+ user = @user_class.find(uid)
281
+ assert_equal(given_name, user.given_name)
282
+ assert_equal(uid, user.cn)
283
+ end
284
+ end
285
+
286
+ def test_given_name_computer
287
+ ensure_delete_computer("test-computer$") do |uid,|
288
+ given_name = "John"
289
+ assert_asl_useradd_successfully(uid, "--computer-account",
290
+ "--given-name", given_name)
291
+ computer = @computer_class.find(uid)
292
+ assert_equal(given_name, computer.given_name)
293
+ assert_equal(uid, computer.cn)
294
+ end
295
+ end
296
+
297
+ def test_surname_user
298
+ ensure_delete_user("test-user") do |uid,|
299
+ surname = "Kennedy"
300
+ assert_asl_useradd_successfully(uid, "--surname", surname)
301
+ user = @user_class.find(uid)
302
+ assert_equal(surname, user.surname)
303
+ assert_equal(uid, user.cn)
304
+ end
305
+ end
306
+
307
+ def test_surname_computer
308
+ ensure_delete_computer("test-computer$") do |uid,|
309
+ surname = "Kennedy"
310
+ assert_asl_useradd_successfully(uid, "--computer-account",
311
+ "--surname", surname)
312
+ computer = @computer_class.find(uid)
313
+ assert_equal(surname, computer.surname)
314
+ assert_equal(uid, computer.cn)
315
+ end
316
+ end
317
+
318
+ def test_given_name_and_surname_user
319
+ ensure_delete_user("test-user") do |uid,|
320
+ given_name = "John"
321
+ surname = "Kennedy"
322
+ assert_asl_useradd_successfully(uid,
323
+ "--given-name", given_name,
324
+ "--surname", surname)
325
+ user = @user_class.find(uid)
326
+ assert_equal(given_name, user.given_name)
327
+ assert_equal(surname, user.surname)
328
+ assert_equal("#{given_name} #{surname}", user.cn)
329
+ end
330
+ end
331
+
332
+ def test_given_name_and_surname_computer
333
+ ensure_delete_computer("test-computer$") do |uid,|
334
+ given_name = "John"
335
+ surname = "Kennedy"
336
+ assert_asl_useradd_successfully(uid,
337
+ "--computer-account",
338
+ "--given-name", given_name,
339
+ "--surname", surname)
340
+ computer = @computer_class.find(uid)
341
+ assert_equal(given_name, computer.given_name)
342
+ assert_equal(surname, computer.surname)
343
+ assert_equal("#{given_name} #{surname}", computer.cn)
344
+ end
345
+ end
346
+
347
+ def test_home_directory_user
348
+ ensure_delete_user("test-user") do |uid,|
349
+ home_directory = "/tmp/#{File.basename(__FILE__)}.#{Process.pid}"
350
+ begin
351
+ assert_asl_useradd_successfully(uid,
352
+ "--home-directory", home_directory,
353
+ "--setup-home-directory")
354
+ assert(File.exist?(home_directory))
355
+ assert_equal(@user_class.configuration[:user_home_directory_mode],
356
+ ("%o" % File.stat(home_directory).mode)[-3, 3].to_i(8))
357
+ ensure
358
+ FileUtils.rm_rf(home_directory)
359
+ end
360
+ end
361
+ end
362
+
363
+ def test_home_directory_user_with_mode
364
+ ensure_delete_user("test-user") do |uid,|
365
+ home_directory = "/tmp/#{File.basename(__FILE__)}.#{Process.pid}"
366
+ begin
367
+ assert_asl_useradd_successfully(uid,
368
+ "--home-directory", home_directory,
369
+ "--setup-home-directory",
370
+ "--home-directory-mode", "0700")
371
+ assert(File.exist?(home_directory))
372
+ assert_equal(0700,
373
+ ("%o" % File.stat(home_directory).mode)[-3, 3].to_i(8))
374
+ ensure
375
+ FileUtils.rm_rf(home_directory)
376
+ end
377
+ end
378
+ end
379
+
380
+ def test_home_directory_computer
381
+ ensure_delete_computer("test-computer$") do |uid,|
382
+ home_directory = "/tmp/#{File.basename(__FILE__)}.#{Process.pid}"
383
+ begin
384
+ assert_asl_useradd_successfully(uid,
385
+ "--computer-account",
386
+ "--home-directory", home_directory,
387
+ "--setup-home-directory")
388
+ assert(File.exist?(home_directory))
389
+ ensure
390
+ FileUtils.rm_rf(home_directory)
391
+ end
392
+ end
393
+ end
394
+
395
+ def test_skeleton_directory
396
+ home_directory = File.join(Dir.tmpdir,
397
+ "#{File.basename(__FILE__)}.#{Process.pid}")
398
+ skeleton_directory = "#{home_directory}.skel"
399
+ begin
400
+ normal_file = "hello"
401
+ dot_file = ".hello"
402
+ deep_file = File.join("dir", "hello")
403
+ FileUtils.touch([normal_file, dot_file, deep_file].collect do |f|
404
+ target = File.join(skeleton_directory, f)
405
+ FileUtils.mkdir_p(File.dirname(target))
406
+ target
407
+ end)
408
+
409
+ ensure_delete_user("test-user") do |uid,|
410
+ assert_asl_useradd_successfully(uid,
411
+ "--home-directory", home_directory,
412
+ "--skeleton-directory",
413
+ skeleton_directory,
414
+ "--setup-home-directory")
415
+ assert(File.exist?(home_directory))
416
+ assert(File.exist?(File.join(home_directory, normal_file)))
417
+ assert(File.exist?(File.join(home_directory, dot_file)))
418
+ assert(File.exist?(File.join(home_directory, deep_file)))
419
+ end
420
+
421
+ ensure_delete_computer("test-computer$") do |uid,|
422
+ assert_asl_useradd_successfully(uid,
423
+ "--computer-account",
424
+ "--home-directory", home_directory,
425
+ "--skeleton-directory",
426
+ skeleton_directory,
427
+ "--setup-home-directory")
428
+ assert(File.exist?(home_directory))
429
+ assert(File.exist?(File.join(home_directory, normal_file)))
430
+ assert(File.exist?(File.join(home_directory, dot_file)))
431
+ assert(File.exist?(File.join(home_directory, deep_file)))
432
+ end
433
+ ensure
434
+ FileUtils.rm_rf([home_directory, skeleton_directory])
435
+ end
436
+ end
437
+
438
+ def test_expire_date_user
439
+ ensure_delete_user("test-user") do |uid,|
440
+ expire_date = Time.now + 60 * 24
441
+ assert_asl_useradd_successfully(uid, "--expire-date", expire_date.iso8601)
442
+ user = @user_class.find(uid)
443
+ assert_equal(expire_date.to_i.to_s, user.samba_kickoff_time)
444
+ end
445
+ end
446
+
447
+ def test_expire_date_computer
448
+ ensure_delete_computer("test-computer$") do |uid,|
449
+ expire_date = Time.now + 60 * 24
450
+ assert_asl_useradd_successfully(uid, "--computer-account",
451
+ "--expire-date", expire_date.iso8601)
452
+ computer = @computer_class.find(uid)
453
+ assert_nil(computer.samba_kickoff_time)
454
+ end
455
+ end
456
+
457
+ def test_can_change_password_user
458
+ ensure_delete_user("test-user") do |uid,|
459
+ assert_asl_useradd_successfully(uid, "--can-change-password")
460
+ user = @user_class.find(uid)
461
+ assert(user.can_change_password?)
462
+ end
463
+ end
464
+
465
+ def test_can_change_password_computer
466
+ ensure_delete_computer("test-computer$") do |uid,|
467
+ ensure_delete_computer("test-computer2$") do |uid2,|
468
+ assert_asl_useradd_successfully(uid, "--computer-account")
469
+ assert_asl_useradd_successfully(uid2, "--computer-account",
470
+ "--can-change-password")
471
+ computer = @computer_class.find(uid)
472
+ computer2 = @computer_class.find(uid2)
473
+ assert_equal(computer.can_change_password?,
474
+ computer2.can_change_password?)
475
+ end
476
+ end
477
+ end
478
+
479
+ def test_no_can_change_password_user
480
+ ensure_delete_user("test-user") do |uid,|
481
+ assert_asl_useradd_successfully(uid, "--no-can-change-password")
482
+ user = @user_class.find(uid)
483
+ assert(!user.can_change_password?)
484
+ end
485
+ end
486
+
487
+ def test_no_can_change_password_computer
488
+ ensure_delete_computer("test-computer$") do |uid,|
489
+ ensure_delete_computer("test-computer2$") do |uid2,|
490
+ assert_asl_useradd_successfully(uid, "--computer-account")
491
+ assert_asl_useradd_successfully(uid2, "--computer-account",
492
+ "--no-can-change-password")
493
+ computer = @computer_class.find(uid)
494
+ computer2 = @computer_class.find(uid2)
495
+ assert_equal(computer.can_change_password?,
496
+ computer2.can_change_password?)
497
+ end
498
+ end
499
+ end
500
+
501
+ def test_must_change_password_user
502
+ ensure_delete_user("test-user") do |uid,|
503
+ assert_asl_useradd_successfully(uid, "--must-change-password")
504
+ user = @user_class.find(uid)
505
+ assert(user.must_change_password?)
506
+ end
507
+ end
508
+
509
+ def test_must_change_password_computer
510
+ ensure_delete_computer("test-computer$") do |uid,|
511
+ ensure_delete_computer("test-computer2$") do |uid2,|
512
+ assert_asl_useradd_successfully(uid, "--computer-account")
513
+ assert_asl_useradd_successfully(uid2, "--computer-account",
514
+ "--must-change-password")
515
+ computer = @computer_class.find(uid)
516
+ computer2 = @computer_class.find(uid2)
517
+ assert_equal(computer.must_change_password?,
518
+ computer2.must_change_password?)
519
+ end
520
+ end
521
+ end
522
+
523
+ def test_no_must_change_password_user
524
+ ensure_delete_user("test-user") do |uid,|
525
+ assert_asl_useradd_successfully(uid, "--no-must-change-password")
526
+ user = @user_class.find(uid)
527
+ assert(!user.must_change_password?)
528
+ end
529
+ end
530
+
531
+ def test_no_must_change_password_computer
532
+ ensure_delete_computer("test-computer$") do |uid,|
533
+ ensure_delete_computer("test-computer2$") do |uid2,|
534
+ assert_asl_useradd_successfully(uid, "--computer-account")
535
+ assert_asl_useradd_successfully(uid2, "--computer-account",
536
+ "--no-must-change-password")
537
+ computer = @computer_class.find(uid)
538
+ computer2 = @computer_class.find(uid2)
539
+ assert_equal(computer.must_change_password?,
540
+ computer2.must_change_password?)
541
+ end
542
+ end
543
+ end
544
+
545
+ def test_samba_home_path_user
546
+ ensure_delete_user("test-user") do |uid,|
547
+ home_path = "\\\\ANYWHERE\\here\\%U"
548
+ assert_asl_useradd_successfully(uid, "--samba-home-path", home_path)
549
+ user = @user_class.find(uid)
550
+ assert_equal(home_path.gsub(/%U/, uid), user.samba_home_path)
551
+ end
552
+ end
553
+
554
+ def test_samba_home_path_computer
555
+ ensure_delete_computer("test-computer$") do |uid,|
556
+ home_path = "\\\\ANYWHERE\\here\\%U"
557
+ assert_asl_useradd_successfully(uid, "--computer-account",
558
+ "--samba-home-path", home_path)
559
+ computer = @computer_class.find(uid)
560
+ assert_nil(computer.samba_home_path)
561
+ end
562
+ end
563
+
564
+ def test_samba_home_drive_user
565
+ ensure_delete_user("test-user") do |uid,|
566
+ home_drive = "X:"
567
+ assert_asl_useradd_successfully(uid, "--samba-home-drive", home_drive)
568
+ user = @user_class.find(uid)
569
+ assert_equal(home_drive, user.samba_home_drive)
570
+ end
571
+ end
572
+
573
+ def test_samba_home_drive_computer
574
+ ensure_delete_computer("test-computer$") do |uid,|
575
+ home_drive = "X:"
576
+ assert_asl_useradd_successfully(uid, "--computer-account",
577
+ "--samba-home-drive", home_drive)
578
+ computer = @computer_class.find(uid)
579
+ assert_nil(computer.samba_home_drive)
580
+ end
581
+ end
582
+
583
+ def test_samba_home_drive_abbrev_user
584
+ ensure_delete_user("test-user") do |uid,|
585
+ home_drive = "X"
586
+ assert_asl_useradd_successfully(uid, "--samba-home-drive", home_drive)
587
+ user = @user_class.find(uid)
588
+ assert_equal("#{home_drive}:", user.samba_home_drive)
589
+ end
590
+ end
591
+
592
+ def test_samba_home_drive_abbrev_computer
593
+ ensure_delete_computer("test-computer$") do |uid,|
594
+ home_drive = "X"
595
+ assert_asl_useradd_successfully(uid, "--computer-account",
596
+ "--samba-home-drive", home_drive)
597
+ computer = @computer_class.find(uid)
598
+ assert_nil(computer.samba_home_drive)
599
+ end
600
+ end
601
+
602
+ def test_samba_logon_script_user
603
+ ensure_delete_user("test-user") do |uid,|
604
+ script = "%U-logon.bat"
605
+ assert_asl_useradd_successfully(uid, "--samba-logon-script", script)
606
+ user = @user_class.find(uid)
607
+ assert_equal(script.gsub(/%U/, uid), user.samba_logon_script)
608
+ end
609
+ end
610
+
611
+ def test_samba_logon_script_computer
612
+ ensure_delete_computer("test-computer$") do |uid,|
613
+ script = "%U-logon.bat"
614
+ assert_asl_useradd_successfully(uid, "--computer-account",
615
+ "--samba-logon-script", script)
616
+ computer = @computer_class.find(uid)
617
+ assert_nil(computer.samba_logon_script)
618
+ end
619
+ end
620
+
621
+ def test_samba_profile_path_user
622
+ ensure_delete_user("test-user") do |uid,|
623
+ profile = "\\\\ANYWHERE\\profiles\\profile-%U"
624
+ assert_asl_useradd_successfully(uid, "--samba-profile-path", profile)
625
+ user = @user_class.find(uid)
626
+ assert_equal(profile.gsub(/%U/, uid), user.samba_profile_path)
627
+ end
628
+ end
629
+
630
+ def test_samba_profile_path_computer
631
+ ensure_delete_computer("test-computer$") do |uid,|
632
+ profile = "\\\\ANYWHERE\\profiles\\profile-%U"
633
+ assert_asl_useradd_successfully(uid, "--computer-account",
634
+ "--samba-profile-path", profile)
635
+ computer = @computer_class.find(uid)
636
+ assert_nil(computer.samba_profile_path)
637
+ end
638
+ end
639
+
640
+ def test_samba_account_flags_user
641
+ ensure_delete_user("test-user") do |uid,|
642
+ flags = "[UX]"
643
+ assert_asl_useradd_successfully(uid, "--samba-account-flags", flags)
644
+ user = @user_class.find(uid)
645
+ assert_equal(flags, user.samba_acct_flags)
646
+ end
647
+ end
648
+
649
+ def test_samba_account_flags_computer
650
+ ensure_delete_computer("test-computer$") do |uid,|
651
+ flags = "[WX]"
652
+ assert_asl_useradd_successfully(uid, "--computer-account",
653
+ "--samba-account-flags", flags)
654
+ computer = @computer_class.find(uid)
655
+ assert_equal(flags, computer.samba_acct_flags)
656
+ end
657
+ end
658
+
659
+ private
660
+ def run_asl_useradd(*other_args, &block)
661
+ other_args = prepare_args(other_args)
662
+ run_command(*other_args, &block)
663
+ end
664
+
665
+ def run_asl_useradd_as_normal_user(*other_args, &block)
666
+ other_args = prepare_args(other_args)
667
+ run_command_as_normal_user(*other_args, &block)
668
+ end
669
+
670
+ def prepare_args(args)
671
+ args = args.dup
672
+ if args.grep(/\A--(no-)?setup-home-directory\z/).empty?
673
+ args << "--no-setup-home-directory"
674
+ end
675
+ if args.grep(/\A--(no-)?create-group\z/).empty?
676
+ args << "--no-create-group"
677
+ end
678
+ args
679
+ end
680
+
681
+ def assert_asl_useradd_successfully(name, *args)
682
+ _wrap_assertion do
683
+ if args.grep(/\A--computer-account\z/).empty?
684
+ member_class = @user_class
685
+ else
686
+ name = name.sub(/\$*\z/, '') + "$"
687
+ member_class = @computer_class
688
+ end
689
+ assert(!member_class.exists?(name))
690
+ args << name
691
+ assert_equal([true, "", ""], run_asl_useradd(*args))
692
+ assert(member_class.exists?(name))
693
+ end
694
+ end
695
+
696
+ def assert_asl_useradd_failed(name, message, *args)
697
+ _wrap_assertion do
698
+ if args.grep(/\A--computer-account\z/).empty?
699
+ member_class = @user_class
700
+ else
701
+ name = name.sub(/\$*\z/, '') + "$"
702
+ member_class = @computer_class
703
+ end
704
+ assert(!member_class.exists?(name))
705
+ args << name
706
+ assert_equal([false, "", message], run_asl_useradd(*args))
707
+ assert(!member_class.exists?(name))
708
+ end
709
+ end
710
+ end