powerhome-activeldap 3.2.3

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,108 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestUserPassword < Test::Unit::TestCase
4
+ priority :must
5
+
6
+ priority :normal
7
+ def test_valid?
8
+ {
9
+ "{CRYPT}.yNLaKqtwQbnY" => 'wibble', #CRYPT
10
+ "{MD5}DRB9CfW75Ayt495ccenptw==" => 'letmein', #MD5
11
+ "{SMD5}8L2iXJuazftLVHrAf7ptPFQIDaw=" => 'letmein', #SMD5 as generated by slappasswd (4 bytes of salt)
12
+ "{SMD5}kXibTNG+O98gaQtkugYcmSTiE+M2Z5TA" => 'letmein', #SMD5 as generated by Apache Directory Studio (8 bytes of salt)
13
+ "{SHA}t6h1/B6iKLkGEEG3zsS9PFKrPOM=" => 'letmein', #SHA
14
+ "{SSHA}YA87hc9/L/cCGR1HValcJb7a8AYxZXY4" => 'wibble', # SSHA as generated by slappasswd (4 bytes of salt)
15
+ "{SSHA}6J6Ios3l1panY9sm0+g9l3/jFz2kwOPrVA4+OA==" => 'letmein', # SSHA as generated by Apache Directory Studio (8 bytes of salt)
16
+ "letmein" => 'letmein', #Cleartext password
17
+ }.each do |hash, plain|
18
+ assert_send([ActiveLdap::UserPassword, :valid?,
19
+ plain, hash])
20
+ assert_not_send([ActiveLdap::UserPassword, :valid?,
21
+ "not#{plain}", hash])
22
+ end
23
+ end
24
+
25
+ def test_crypt
26
+ salt = ".WoUoU9f3IlUx9Hh7D/8y.xA6ziklGib"
27
+ assert_equal("{CRYPT}.W57FZhV52w0s",
28
+ ActiveLdap::UserPassword.crypt("password", salt))
29
+
30
+ password = "PASSWORD"
31
+ hashed_password = ActiveLdap::UserPassword.crypt(password)
32
+ salt = hashed_password.sub(/^\{CRYPT\}/, '')
33
+ assert_equal(hashed_password,
34
+ ActiveLdap::UserPassword.crypt(password, salt))
35
+ end
36
+
37
+ def test_extract_salt_for_crypt
38
+ assert_extract_salt(:crypt, "AB", "ABCDE")
39
+ assert_extract_salt(:crypt, "$1", "$1")
40
+ assert_extract_salt(:crypt, "$1$$", "$1$")
41
+ assert_extract_salt(:crypt, "$1$$", "$1$$")
42
+ assert_extract_salt(:crypt, "$1$abcdefgh$", "$1$abcdefgh$")
43
+ assert_extract_salt(:crypt, "$1$abcdefgh$", "$1$abcdefghi$")
44
+ end
45
+
46
+ def test_md5
47
+ assert_equal("{MD5}X03MO1qnZdYdgyfeuILPmQ==",
48
+ ActiveLdap::UserPassword.md5("password"))
49
+ end
50
+
51
+ def test_smd5
52
+ assert_equal("{SMD5}gjz+SUSfZaux99Xsji/No200cGI=",
53
+ ActiveLdap::UserPassword.smd5("password", "m4pb"))
54
+
55
+ password = "PASSWORD"
56
+ hashed_password = ActiveLdap::UserPassword.smd5(password)
57
+ salt = decode64(hashed_password.sub(/^\{SMD5\}/, ''))[-4, 4]
58
+ assert_equal(hashed_password,
59
+ ActiveLdap::UserPassword.smd5(password, salt))
60
+ end
61
+
62
+ def test_extract_salt_for_smd5
63
+ assert_extract_salt(:smd5, 'this', encode64("1234567890123456this"))
64
+ assert_extract_salt(:smd5, 'this is the salt', encode64("1234567890123456this is the salt"))
65
+ assert_extract_salt(:smd5, nil, encode64("123456789"))
66
+ assert_extract_salt(:smd5, nil, encode64("123456789012345"))
67
+ assert_extract_salt(:smd5, nil, encode64("1234567890123456"))
68
+ end
69
+
70
+ def test_sha
71
+ assert_equal("{SHA}W6ph5Mm5Pz8GgiULbPgzG37mj9g=",
72
+ ActiveLdap::UserPassword.sha("password"))
73
+ end
74
+
75
+ def test_ssha
76
+ assert_equal("{SSHA}ipnlCLA1HaK3mm3hyneJIp+Px2h1RGk3",
77
+ ActiveLdap::UserPassword.ssha("password", "uDi7"))
78
+
79
+ password = "PASSWORD"
80
+ hashed_password = ActiveLdap::UserPassword.ssha(password)
81
+ salt = decode64(hashed_password.sub(/^\{SSHA\}/, ''))[-4, 4]
82
+ assert_equal(hashed_password,
83
+ ActiveLdap::UserPassword.ssha(password, salt))
84
+ end
85
+
86
+ def test_extract_salt_for_ssha
87
+ assert_extract_salt(:ssha, 'this', encode64("12345678901234567890this"))
88
+ assert_extract_salt(:ssha, 'this is the salt', encode64("12345678901234567890this is the salt"))
89
+ assert_extract_salt(:ssha, nil, encode64("12345678901234"))
90
+ assert_extract_salt(:ssha, nil, encode64("1234567890123456789"))
91
+ assert_extract_salt(:ssha, nil, encode64("12345678901234567890"))
92
+ end
93
+
94
+ private
95
+ def assert_extract_salt(type, expected, hashed_password)
96
+ actual = ActiveLdap::UserPassword.send("extract_salt_for_#{type}",
97
+ hashed_password)
98
+ assert_equal(expected, actual)
99
+ end
100
+
101
+ def encode64(string)
102
+ [string].pack('m').chomp
103
+ end
104
+
105
+ def decode64(string)
106
+ string.unpack('m')[0]
107
+ end
108
+ end
@@ -0,0 +1,62 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestUseraddBinary < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ def setup
7
+ super
8
+ @command = File.join(@examples_dir, "useradd-binary")
9
+ make_ou("People")
10
+ @user_class.prefix = "ou=People"
11
+ end
12
+
13
+ priority :must
14
+
15
+ priority :normal
16
+ def test_exist_user
17
+ make_temporary_user do |user, password|
18
+ assert(@user_class.exists?(user.uid))
19
+ assert_equal([false, "User #{user.uid} already exists.\n"],
20
+ run_command(user.uid, user.cn, user.uid_number))
21
+ assert(@user_class.exists?(user.uid))
22
+ end
23
+ end
24
+
25
+ def test_add_user
26
+ ensure_delete_user("test-user") do |uid,|
27
+ assert_useradd_binary_successfully(uid, uid, 10000)
28
+ end
29
+ end
30
+
31
+ private
32
+ def assert_useradd_binary_successfully(name, cn, uid, *args, &block)
33
+ _wrap_assertion do
34
+ assert(!@user_class.exists?(name))
35
+ args.concat([name, cn, uid])
36
+ assert_equal([true, ""], run_command(*args, &block))
37
+ assert(@user_class.exists?(name))
38
+
39
+ user = @user_class.find(name)
40
+ assert_equal(name, user.uid)
41
+ assert_equal(cn, user.cn)
42
+ assert_equal(uid.to_i, user.uid_number)
43
+ assert_equal(uid.to_i, user.gid_number)
44
+ assert_equal(uid.to_s, user.uid_number_before_type_cast)
45
+ assert_equal(uid.to_s, user.gid_number_before_type_cast)
46
+ assert_equal(['person', 'posixAccount', 'shadowAccount',
47
+ 'strongAuthenticationUser'].sort, user.classes.sort)
48
+ cert = File.read(File.join(@examples_dir, 'example.der'))
49
+ cert.force_encoding('ascii-8bit') if cert.respond_to?(:force_encoding)
50
+ assert_equal(cert, user.user_certificate)
51
+ end
52
+ end
53
+
54
+ def assert_useradd_binary_failed(name, cn, uid, message, *args, &block)
55
+ _wrap_assertion do
56
+ assert(!@user_class.exists?(name))
57
+ args.concat([name, cn, uid])
58
+ assert_equal([false, message], run_command(*args, &block))
59
+ assert(!@user_class.exists?(name))
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,57 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestUseradd < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ def setup
7
+ super
8
+ @command = File.join(@examples_dir, "useradd")
9
+ make_ou("People")
10
+ @user_class.prefix = "ou=People"
11
+ end
12
+
13
+ priority :must
14
+
15
+ priority :normal
16
+ def test_exist_user
17
+ make_temporary_user do |user, password|
18
+ assert(@user_class.exists?(user.uid))
19
+ assert_equal([false, "User #{user.uid} already exists.\n"],
20
+ run_command(user.uid, user.cn, user.uid_number))
21
+ assert(@user_class.exists?(user.uid))
22
+ end
23
+ end
24
+
25
+ def test_add_user
26
+ ensure_delete_user("test-user") do |uid,|
27
+ assert_useradd_successfully(uid, uid, 10000)
28
+ end
29
+ end
30
+
31
+ private
32
+ def assert_useradd_successfully(name, cn, uid, *args, &block)
33
+ _wrap_assertion do
34
+ assert(!@user_class.exists?(name))
35
+ args.concat([name, cn, uid])
36
+ assert_equal([true, ""], run_command(*args, &block))
37
+ assert(@user_class.exists?(name))
38
+
39
+ user = @user_class.find(name)
40
+ assert_equal(name, user.uid)
41
+ assert_equal(cn, user.cn)
42
+ assert_equal(uid.to_i, user.uid_number)
43
+ assert_equal(uid.to_i, user.gid_number)
44
+ assert_equal(uid.to_s, user.uid_number_before_type_cast)
45
+ assert_equal(uid.to_s, user.gid_number_before_type_cast)
46
+ end
47
+ end
48
+
49
+ def assert_useradd_failed(name, cn, uid, message, *args, &block)
50
+ _wrap_assertion do
51
+ assert(!@user_class.exists?(name))
52
+ args.concat([name, cn, uid])
53
+ assert_equal([false, message], run_command(*args, &block))
54
+ assert(!@user_class.exists?(name))
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,48 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestUserdel < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ def setup
7
+ super
8
+ @command = File.join(@examples_dir, "userdel")
9
+ make_ou("People")
10
+ @user_class.prefix = "ou=People"
11
+ end
12
+
13
+ priority :must
14
+
15
+ priority :normal
16
+ def test_non_exist_user
17
+ ensure_delete_user("test-user") do |uid,|
18
+ assert(!@user_class.exists?(uid))
19
+ assert_equal([false, "User #{uid} doesn't exist.\n"], run_command(uid))
20
+ assert(!@user_class.exists?(uid))
21
+ end
22
+ end
23
+
24
+ def test_delete_user
25
+ make_temporary_user do |user, password|
26
+ assert_userdel_successfully(user.uid)
27
+ end
28
+ end
29
+
30
+ private
31
+ def assert_userdel_successfully(name, *args, &block)
32
+ _wrap_assertion do
33
+ assert(@user_class.exists?(name))
34
+ args.concat([name])
35
+ assert_equal([true, ""], run_command(*args, &block))
36
+ assert(!@user_class.exists?(name))
37
+ end
38
+ end
39
+
40
+ def assert_userdel_failed(name, message, *args, &block)
41
+ _wrap_assertion do
42
+ assert(@user_class.exists?(name))
43
+ args.concat([name])
44
+ assert_equal([false, message], run_command(*args, &block))
45
+ assert(@user_class.exists?(name))
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,91 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestUserls < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ def setup
7
+ super
8
+ @command = File.join(@examples_dir, "userls")
9
+ make_ou("People")
10
+ @user_class.prefix = "ou=People"
11
+ end
12
+
13
+ priority :must
14
+
15
+ priority :normal
16
+ def test_non_exist_user
17
+ ensure_delete_user("test-user") do |uid,|
18
+ assert(!@user_class.exists?(uid))
19
+ assert_equal([false, "User #{uid} doesn't exist.\n"], run_command(uid))
20
+ assert(!@user_class.exists?(uid))
21
+ end
22
+ end
23
+
24
+ def test_list_user_no_group
25
+ make_temporary_user do |user, password|
26
+ assert_userls_successfully(user.uid, [], [])
27
+ end
28
+ end
29
+
30
+ def test_list_user_have_primary_group
31
+ make_temporary_group do |group|
32
+ make_temporary_user(:gid_number => group.gid_number) do |user, password|
33
+ assert_userls_successfully(user.uid, [group], [])
34
+ end
35
+ end
36
+ end
37
+
38
+ def test_list_user_have_groups
39
+ make_temporary_group do |group1|
40
+ make_temporary_group do |group2|
41
+ options = {:gid_number => group2.gid_number.succ}
42
+ make_temporary_user(options) do |user, password|
43
+ user.groups << group1
44
+ user.groups << group2
45
+ assert_userls_successfully(user.uid, [], [group1, group2])
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ def test_list_user_have_groups_and_primary_group
52
+ make_temporary_group do |group1|
53
+ make_temporary_user(:gid_number => group1.gid_number) do |user, password|
54
+ make_temporary_group do |group2|
55
+ make_temporary_group do |group3|
56
+ user.groups << group2
57
+ user.groups << group3
58
+ assert_userls_successfully(user.uid, [group1], [group2, group3])
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ private
66
+ def assert_userls_successfully(name, primary_groups, groups, *args, &block)
67
+ _wrap_assertion do
68
+ assert(@user_class.exists?(name))
69
+ args.concat([name])
70
+ user = @user_class.find(name)
71
+ group_names = groups.collect {|g| "#{g.cn}"}
72
+ group_infos = (primary_groups + groups).collect do |g|
73
+ "#{g.cn}[#{g.gid_number}]"
74
+ end
75
+ result = user.to_ldif
76
+ result << "Groups by name only: #{group_names.join(', ')}\n"
77
+ result << "Groups: #{group_infos.join(', ')}\n"
78
+ assert_equal([true, result], run_command(*args, &block))
79
+ assert(@user_class.exists?(name))
80
+ end
81
+ end
82
+
83
+ def assert_userls_failed(name, message, *args, &block)
84
+ _wrap_assertion do
85
+ assert(@user_class.exists?(name))
86
+ args.concat([name])
87
+ assert_equal([false, message], run_command(*args, &block))
88
+ assert(@user_class.exists?(name))
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,65 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestUsermodBinaryAddTime < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ def setup
7
+ super
8
+ @command = File.join(@examples_dir, "usermod-binary-add-time")
9
+ make_ou("People")
10
+ @user_class.prefix = "ou=People"
11
+ end
12
+
13
+ priority :must
14
+
15
+ priority :normal
16
+ def test_non_exist_user
17
+ ensure_delete_user("test-user") do |uid,|
18
+ assert(!@user_class.exists?(uid))
19
+ assert_equal([false, "User #{uid} doesn't exist.\n"],
20
+ run_command(uid, "New CN", 11111))
21
+ assert(!@user_class.exists?(uid))
22
+ end
23
+ end
24
+
25
+ def test_modify_user
26
+ make_temporary_user do |user, password|
27
+ assert_usermod_binary_add_time_successfully(user.uid, "New #{user.cn}",
28
+ user.uid_number.to_i + 100)
29
+ end
30
+ end
31
+
32
+ private
33
+ def assert_usermod_binary_add_time_successfully(name, cn, uid, *args, &block)
34
+ _wrap_assertion do
35
+ assert(@user_class.exists?(name))
36
+ previous_classes = @user_class.find(name).classes
37
+ args.concat([name, cn, uid])
38
+ assert_equal([true, ""], run_command(*args, &block))
39
+ assert(@user_class.exists?(name))
40
+
41
+ user = @user_class.find(name)
42
+ assert_equal(name, user.uid)
43
+ assert_equal(cn, user.cn)
44
+ assert_equal(uid.to_i, user.uid_number)
45
+ assert_equal(uid.to_i, user.gid_number)
46
+ assert_equal(uid.to_s, user.uid_number_before_type_cast)
47
+ assert_equal(uid.to_s, user.gid_number_before_type_cast)
48
+ assert_equal((previous_classes + ['strongAuthenticationUser']).sort,
49
+ user.classes.sort)
50
+ cert = File.read(File.join(@examples_dir, 'example.der'))
51
+ cert.force_encoding("ascii-8bit") if cert.respond_to?(:force_encoding)
52
+ assert_equal(cert, user.user_certificate)
53
+ end
54
+ end
55
+
56
+ def assert_usermod_binary_add_time_failed(name, cn, uid, message,
57
+ *args, &block)
58
+ _wrap_assertion do
59
+ assert(@user_class.exists?(name))
60
+ args.concat([name, cn, uid])
61
+ assert_equal([false, message], run_command(*args, &block))
62
+ assert(@user_class.exists?(name))
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,64 @@
1
+ require 'al-test-utils'
2
+
3
+ class TestUsermodBinaryAdd < Test::Unit::TestCase
4
+ include AlTestUtils
5
+
6
+ def setup
7
+ super
8
+ @command = File.join(@examples_dir, "usermod-binary-add")
9
+ make_ou("People")
10
+ @user_class.prefix = "ou=People"
11
+ end
12
+
13
+ priority :must
14
+
15
+ priority :normal
16
+ def test_non_exist_user
17
+ ensure_delete_user("test-user") do |uid,|
18
+ assert(!@user_class.exists?(uid))
19
+ assert_equal([false, "User #{uid} doesn't exist.\n"],
20
+ run_command(uid, "New CN", 11111))
21
+ assert(!@user_class.exists?(uid))
22
+ end
23
+ end
24
+
25
+ def test_modify_user
26
+ make_temporary_user do |user, password|
27
+ assert_usermod_binary_add_successfully(user.uid, "New #{user.cn}",
28
+ user.uid_number.to_i + 100)
29
+ end
30
+ end
31
+
32
+ private
33
+ def assert_usermod_binary_add_successfully(name, cn, uid, *args, &block)
34
+ _wrap_assertion do
35
+ assert(@user_class.exists?(name))
36
+ previous_classes = @user_class.find(name).classes
37
+ args.concat([name, cn, uid])
38
+ assert_equal([true, ""], run_command(*args, &block))
39
+ assert(@user_class.exists?(name))
40
+
41
+ user = @user_class.find(name)
42
+ assert_equal(name, user.uid)
43
+ assert_equal(cn, user.cn)
44
+ assert_equal(uid.to_i, user.uid_number)
45
+ assert_equal(uid.to_i, user.gid_number)
46
+ assert_equal(uid.to_s, user.uid_number_before_type_cast)
47
+ assert_equal(uid.to_s, user.gid_number_before_type_cast)
48
+ assert_equal((previous_classes + ['strongAuthenticationUser']).sort,
49
+ user.classes.sort)
50
+ cert = File.read(File.join(@examples_dir, 'example.der'))
51
+ cert.force_encoding("ascii-8bit") if cert.respond_to?(:force_encoding)
52
+ assert_equal(cert, user.user_certificate)
53
+ end
54
+ end
55
+
56
+ def assert_usermod_binary_add_failed(name, cn, uid, message, *args, &block)
57
+ _wrap_assertion do
58
+ assert(@user_class.exists?(name))
59
+ args.concat([name, cn, uid])
60
+ assert_equal([false, message], run_command(*args, &block))
61
+ assert(@user_class.exists?(name))
62
+ end
63
+ end
64
+ end