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,276 @@
1
+ require 'test/unit'
2
+ require 'test-unit-ext'
3
+
4
+ require 'rbconfig'
5
+ require 'fileutils'
6
+ require 'tmpdir'
7
+
8
+ require File.join(File.dirname(__FILE__), "command")
9
+
10
+ require 'active_samba_ldap'
11
+
12
+ module AslTestUtils
13
+ def self.included(base)
14
+ base.class_eval do
15
+ include Configuration
16
+ include Connection
17
+ include Populate
18
+ include TemporaryEntry
19
+ include CommandSupport
20
+ end
21
+ end
22
+
23
+ module Configuration
24
+ def setup
25
+ super
26
+ @test_dir = File.expand_path(File.dirname(__FILE__))
27
+ @top_dir = File.expand_path(File.join(@test_dir, ".."))
28
+ @parent_dir = File.expand_path(File.join(@top_dir, ".."))
29
+ @config_file = File.join(@test_dir, "config.yaml")
30
+ ActiveSambaLdap::Base.configurations = read_config
31
+ end
32
+
33
+ def teardown
34
+ super
35
+ end
36
+
37
+ def reference_configuration
38
+ ActiveSambaLdap::Base.configurations["reference"]
39
+ end
40
+
41
+ def update_configuration
42
+ ActiveSambaLdap::Base.configurations["update"]
43
+ end
44
+
45
+ def read_config
46
+ unless File.exist?(@config_file)
47
+ raise "config file for testing doesn't exist: #{@config_file}"
48
+ end
49
+ ActiveSambaLdap::Configuration.read(@config_file)
50
+ end
51
+ end
52
+
53
+ module Connection
54
+ def setup
55
+ super
56
+ ActiveSambaLdap::Base.establish_connection(update_configuration)
57
+ end
58
+
59
+ def teardown
60
+ super
61
+ ActiveSambaLdap::Base.clear_active_connections!
62
+ end
63
+ end
64
+
65
+ module Populate
66
+ def setup
67
+ super
68
+ @dumped_data = ""
69
+ begin
70
+ @dumped_data = ActiveSambaLdap::Base.dump(:scope => :sub)
71
+ rescue ActiveLdap::ConnectionError
72
+ end
73
+ ActiveSambaLdap::Base.purge
74
+ ActiveSambaLdap::Base.populate
75
+ end
76
+
77
+ def teardown
78
+ super
79
+ ActiveSambaLdap::Base.establish_connection(update_configuration)
80
+ ActiveSambaLdap::Base.purge
81
+ ActiveSambaLdap::Base.load(@dumped_data)
82
+ end
83
+ end
84
+
85
+ module TemporaryEntry
86
+ def setup
87
+ super
88
+ @user_class = Class.new(ActiveSambaLdap::SambaUser)
89
+ @user_class.ldap_mapping
90
+ @computer_class = Class.new(ActiveSambaLdap::SambaComputer)
91
+ @computer_class.ldap_mapping
92
+ @group_class = Class.new(ActiveSambaLdap::SambaGroup)
93
+ @group_class.ldap_mapping
94
+
95
+ @user_class.set_associated_class(:primary_group, @group_class)
96
+ @computer_class.set_associated_class(:primary_group, @group_class)
97
+ @user_class.set_associated_class(:groups, @group_class)
98
+ @computer_class.set_associated_class(:groups, @group_class)
99
+
100
+ @group_class.set_associated_class(:users, @user_class)
101
+ @group_class.set_associated_class(:computers, @computer_class)
102
+ @group_class.set_associated_class(:primary_users, @user_class)
103
+ @group_class.set_associated_class(:primary_computers, @computer_class)
104
+
105
+ @user_index = 0
106
+ @computer_index = 0
107
+ @group_index = 0
108
+ end
109
+
110
+ def make_dummy_user(config={})
111
+ @user_index += 1
112
+ name = config[:name] || "test-user#{@user_index}"
113
+ home_directory = config[:home_directory] || "/tmp/#{name}-#{Process.pid}"
114
+ ensure_delete_user(name, home_directory) do
115
+ password = config[:password] || "password"
116
+ uid_number = config[:uid_number] || "100000#{@user_index}"
117
+ default_user_gid = @user_class.configuration[:default_user_gid]
118
+ gid_number = config[:gid_number] || default_user_gid
119
+ _wrap_assertion do
120
+ assert(!@user_class.exists?(name))
121
+ options = {
122
+ :uid => name,
123
+ :uid_number => uid_number,
124
+ :group => @group_class.find_by_gid_number(gid_number),
125
+ :home_directory => home_directory,
126
+ :password => password,
127
+ }
128
+ user = @user_class.create(options)
129
+ assert_equal([], user.errors.to_a)
130
+ user.save!
131
+ FileUtils.mkdir(home_directory)
132
+ assert(@user_class.exists?(name))
133
+ yield(user, password)
134
+ end
135
+ end
136
+ end
137
+
138
+ def ensure_delete_user(uid, home=nil)
139
+ yield(uid, home)
140
+ ensure
141
+ if @user_class.exists?(uid)
142
+ @user_class.find(uid).destroy(:remove_from_group => true,
143
+ :remove_home_directory => true)
144
+ end
145
+ FileUtils.rm_rf(home) if home
146
+ end
147
+
148
+ def make_dummy_computer(config={})
149
+ @computer_index += 1
150
+ name = config[:name] || "test-computer#{@computer_index}$"
151
+ home_directory = config[:home_directory] || "/tmp/#{name}-#{Process.pid}"
152
+ ensure_delete_computer(name, home_directory) do |name, home_directory|
153
+ password = config[:password]
154
+ uid_number = config[:uid_number] || "100000#{@computer_index}"
155
+ default_computer_gid =
156
+ @computer_class.configuration[:default_computer_gid]
157
+ gid_number = config[:gid_number] || default_computer_gid
158
+ _wrap_assertion do
159
+ assert(!@computer_class.exists?(name))
160
+ options = {
161
+ :uid => name,
162
+ :uid_number => uid_number,
163
+ :group => @group_class.find_by_gid_number(gid_number),
164
+ :password => password,
165
+ }
166
+ computer = @computer_class.create(options)
167
+ assert_equal([], computer.errors.to_a)
168
+ FileUtils.mkdir(home_directory)
169
+ assert(@computer_class.exists?(name))
170
+ yield(computer, password)
171
+ end
172
+ end
173
+ end
174
+
175
+ def ensure_delete_computer(uid, home=nil)
176
+ yield(uid.sub(/\$+\z/, '') + "$", home)
177
+ ensure
178
+ if @computer_class.exists?(uid)
179
+ @computer_class.find(uid).destroy(:remove_from_group => true,
180
+ :remove_home_directory => true)
181
+ end
182
+ FileUtils.rm_rf(home) if home
183
+ end
184
+
185
+ def make_dummy_group(config={})
186
+ @group_index += 1
187
+ name = config[:name] || "test-group#{@group_index}"
188
+ ensure_delete_group(name) do
189
+ gid_number = config[:gid_number] || "200000#{@group_index}"
190
+ group_type = config[:group_type] || "domain"
191
+ _wrap_assertion do
192
+ assert(!@group_class.exists?(name))
193
+ options = {
194
+ :cn => name,
195
+ :gid_number => gid_number,
196
+ :group_type => group_type,
197
+ }
198
+ group = @group_class.create(options)
199
+ assert_equal([], group.errors.to_a)
200
+ assert(@group_class.exists?(name))
201
+ yield(group)
202
+ end
203
+ end
204
+ end
205
+
206
+ def ensure_delete_group(name)
207
+ yield(name)
208
+ ensure
209
+ if @group_class.exists?(name)
210
+ @group_class.find(name).destroy(:remove_members => false)
211
+ end
212
+ end
213
+
214
+ def ensure_delete_ou(ou)
215
+ yield(ou)
216
+ ensure
217
+ ou_class = Class.new(ActiveSambaLdap::Ou)
218
+ ou_class.ldap_mapping
219
+ ou_class.destroy(ou) if ou_class.exists?(ou)
220
+ end
221
+
222
+ def pool
223
+ pool_class = Class.new(ActiveSambaLdap::UnixIdPool)
224
+ pool_class.ldap_mapping
225
+ pool_class.required_configuration_variables :samba_domain
226
+ pool_class.new(pool_class.configuration[:samba_domain])
227
+ end
228
+
229
+ def next_uid_number
230
+ pool.uid_number || @user_class.configuration[:start_uid]
231
+ end
232
+
233
+ def next_gid_number
234
+ pool.gid_number || @group_class.configuration[:start_gid]
235
+ end
236
+ end
237
+
238
+ module CommandSupport
239
+ def setup
240
+ super
241
+ @fakeroot = "fakeroot"
242
+ @ruby = File.join(::Config::CONFIG["bindir"],
243
+ ::Config::CONFIG["RUBY_INSTALL_NAME"])
244
+ @bin_dir = File.join(@top_dir, "bin")
245
+ @lib_dir = File.join(@top_dir, "lib")
246
+ @ruby_args = [
247
+ "-I", @lib_dir,
248
+ "-I", File.join(@parent_dir, "activeldap", "lib"),
249
+ # "-I", File.join(@parent_dir, "ldap", "lib"),
250
+ # "-I", File.join(@parent_dir, "ldap"),
251
+ ]
252
+ end
253
+
254
+ def run_command_as_normal_user(*args, &block)
255
+ run_ruby(*[@command, "--config", @config_file, *args], &block)
256
+ end
257
+
258
+ def run_command_with_fakeroot(*args, &block)
259
+ run_ruby_with_fakeroot(*[@command, "--config", @config_file, *args],
260
+ &block)
261
+ end
262
+ alias_method :run_command, :run_command_with_fakeroot
263
+
264
+ def run_ruby(*ruby_args, &block)
265
+ args = [@ruby, *@ruby_args]
266
+ args.concat(ruby_args)
267
+ Command.run(*args, &block)
268
+ end
269
+
270
+ def run_ruby_with_fakeroot(*ruby_args, &block)
271
+ args = [@fakeroot, @ruby, *@ruby_args]
272
+ args.concat(ruby_args)
273
+ Command.run(*args, &block)
274
+ end
275
+ end
276
+ end
data/test/command.rb ADDED
@@ -0,0 +1,64 @@
1
+ require "thread"
2
+ require "socket"
3
+ require "shellwords"
4
+
5
+ module Command
6
+ class Error < StandardError
7
+ attr_reader :command, :result
8
+ def initialize(command, result)
9
+ @command = command
10
+ @result = result
11
+ super("#{command}: #{result}")
12
+ end
13
+ end
14
+
15
+ module_function
16
+ def detach_io
17
+ require 'fcntl'
18
+ [TCPSocket, ::File].each do |c|
19
+ ObjectSpace.each_object(c) do |io|
20
+ begin
21
+ unless io.closed?
22
+ io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
23
+ end
24
+ rescue SystemCallError,IOError => e
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ def run(cmd, *args)
31
+ raise ArgumentError, "command isn't specified" if cmd.nil?
32
+ if args.any? {|x| x.nil?}
33
+ raise ArgumentError, "args has nil: #{args.inspect}"
34
+ end
35
+ in_r, in_w = IO.pipe
36
+ out_r, out_w = IO.pipe
37
+ err_r, err_w = IO.pipe
38
+ pid = exit_status = nil
39
+ Thread.exclusive do
40
+ verbose = $VERBOSE
41
+ # ruby(>=1.8)'s fork terminates other threads with warning messages
42
+ $VERBOSE = nil
43
+ pid = fork do
44
+ $VERBOSE = verbose
45
+ detach_io
46
+ $stdin.reopen(in_r)
47
+ in_r.close
48
+ $stdout.reopen(out_w)
49
+ $stderr.reopen(err_w)
50
+ out_w.close
51
+ err_w.close
52
+ exec(cmd, *args.collect {|arg| arg.to_s})
53
+ exit!(-1)
54
+ end
55
+ $VERBOSE = verbose
56
+ end
57
+ yield(out_r, in_w) if block_given?
58
+ in_r.close unless in_r.closed?
59
+ out_w.close unless out_w.closed?
60
+ err_w.close unless err_w.closed?
61
+ pid, status = Process.waitpid2(pid)
62
+ [status.exited? && status.exitstatus.zero?, out_r.read, err_r.read]
63
+ end
64
+ end
@@ -0,0 +1,17 @@
1
+ common:
2
+ sid: S-1-5-21-915876905-2926214379-2876160357
3
+ user_home_directory: /home/%U
4
+ user_login_shell: /bin/sh
5
+
6
+ update:
7
+ base: dc=test,dc=local,dc=net
8
+ host: 127.0.0.1
9
+ # method: :tls
10
+ bind_dn: cn=admin,dc=local,dc=net
11
+ password: secret
12
+
13
+ reference:
14
+ base: dc=test,dc=local,dc=net
15
+ host: 127.0.0.1
16
+ # method: :tls
17
+ allow_anonymous: true
data/test/run-test.rb ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "test/unit"
4
+
5
+ top_dir = File.join(File.dirname(__FILE__), "..")
6
+ # $LOAD_PATH.unshift(File.join(top_dir, "..", "ldap", "lib"))
7
+ # $LOAD_PATH.unshift(File.join(top_dir, "..", "ldap"))
8
+ $LOAD_PATH.unshift(File.join(top_dir, "..", "activeldap", "lib"))
9
+ $LOAD_PATH.unshift(File.join(top_dir, "lib"))
10
+ $LOAD_PATH.unshift(File.join(top_dir, "test"))
11
+
12
+ require 'test-unit-ext'
13
+
14
+ if Test::Unit::AutoRunner.respond_to?(:standalone?)
15
+ exit Test::Unit::AutoRunner.run($0, File.dirname($0))
16
+ else
17
+ exit Test::Unit::AutoRunner.run(false, File.dirname($0))
18
+ end
@@ -0,0 +1,28 @@
1
+ require "test/unit/ui/testrunnermediator"
2
+
3
+ module Test
4
+ module Unit
5
+ module UI
6
+ class TestRunnerMediator
7
+ alias_method :original_run_suite, :run_suite
8
+ def run_suite
9
+ @notified_finished = false
10
+ begin_time = Time.now
11
+ original_run_suite
12
+ rescue Interrupt
13
+ unless @notified_finished
14
+ end_time = Time.now
15
+ elapsed_time = end_time - begin_time
16
+ notify_listeners(FINISHED, elapsed_time)
17
+ end
18
+ raise
19
+ end
20
+
21
+ def notify_listeners(channel_name, *arguments)
22
+ @notified_finished = true if channel_name == FINISHED
23
+ super
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,159 @@
1
+ require "test/unit"
2
+
3
+ require "fileutils"
4
+
5
+ module Test
6
+ module Unit
7
+ class TestCase
8
+ class << self
9
+ def inherited(sub)
10
+ super
11
+ sub.instance_variable_set("@priority_initialized", true)
12
+ sub.instance_variable_set("@priority_table", {})
13
+ sub.priority :normal
14
+ end
15
+
16
+ def include(*args)
17
+ args.reverse_each do |mod|
18
+ super(mod)
19
+ next unless defined?(@priority_initialized)
20
+ mod.instance_methods(false).each do |name|
21
+ set_priority(name)
22
+ end
23
+ end
24
+ end
25
+
26
+ def method_added(name)
27
+ set_priority(name) if defined?(@priority_initialized)
28
+ end
29
+
30
+ def priority(name, *tests)
31
+ unless private_methods.include?(priority_check_method_name(name))
32
+ raise ArgumentError, "unknown priority: #{name}"
33
+ end
34
+ if tests.empty?
35
+ @current_priority = name
36
+ else
37
+ tests.each do |test|
38
+ set_priority(test, name)
39
+ end
40
+ end
41
+ end
42
+
43
+ def need_to_run?(test_name)
44
+ normalized_test_name = normalize_test_name(test_name)
45
+ priority = @priority_table[normalized_test_name]
46
+ return true unless priority
47
+ __send__(priority_check_method_name(priority), test_name)
48
+ end
49
+
50
+ private
51
+ def priority_check_method_name(priority_name)
52
+ "run_priority_#{priority_name}?"
53
+ end
54
+
55
+ def normalize_test_name(test_name)
56
+ "test_#{test_name.to_s.sub(/^test_/, '')}"
57
+ end
58
+
59
+ def set_priority(name, priority=@current_priority)
60
+ @priority_table[normalize_test_name(name)] = priority
61
+ end
62
+
63
+ def run_priority_must?(test_name)
64
+ true
65
+ end
66
+
67
+ def run_priority_important?(test_name)
68
+ rand > 0.1
69
+ end
70
+
71
+ def run_priority_high?(test_name)
72
+ rand > 0.3
73
+ end
74
+
75
+ def run_priority_normal?(test_name)
76
+ rand > 0.5
77
+ end
78
+
79
+ def run_priority_low?(test_name)
80
+ rand > 0.75
81
+ end
82
+ end
83
+
84
+ def need_to_run?
85
+ !previous_test_success? or self.class.need_to_run?(@method_name)
86
+ end
87
+
88
+ alias_method :original_run, :run
89
+ def run(result, &block)
90
+ original_run(result, &block)
91
+ ensure
92
+ if passed?
93
+ FileUtils.rm_f(not_passed_file)
94
+ else
95
+ FileUtils.touch(not_passed_file)
96
+ end
97
+ end
98
+
99
+ private
100
+ def previous_test_success?
101
+ not File.exist?(not_passed_file)
102
+ end
103
+
104
+ def result_dir
105
+ dir = File.join(File.dirname($0), ".test-result",
106
+ self.class.name, @method_name.to_s)
107
+ dir = File.expand_path(dir)
108
+ FileUtils.mkdir_p(dir)
109
+ dir
110
+ end
111
+
112
+ def not_passed_file
113
+ File.join(result_dir, "not-passed")
114
+ end
115
+ end
116
+
117
+ class TestSuite
118
+ @@priority_mode = false
119
+
120
+ class << self
121
+ def priority_mode=(bool)
122
+ @@priority_mode = bool
123
+ end
124
+ end
125
+
126
+ alias_method :original_run, :run
127
+ def run(*args, &block)
128
+ priority_mode = @@priority_mode
129
+ if priority_mode
130
+ @original_tests = @tests
131
+ apply_priority
132
+ end
133
+ original_run(*args, &block)
134
+ ensure
135
+ @tests = @original_tests if priority_mode
136
+ end
137
+
138
+ def apply_priority
139
+ @tests = @tests.reject {|test| !test.need_to_run?}
140
+ end
141
+
142
+ def need_to_run?
143
+ apply_priority
144
+ !@tests.empty?
145
+ end
146
+ end
147
+
148
+ class AutoRunner
149
+ alias_method :original_options, :options
150
+ def options
151
+ opts = original_options
152
+ opts.on("--[no-]priority", "use priority mode") do |bool|
153
+ TestSuite.priority_mode = bool
154
+ end
155
+ opts
156
+ end
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,2 @@
1
+ require 'test-unit-ext/always-show-result'
2
+ require 'test-unit-ext/priority'
@@ -0,0 +1,69 @@
1
+ require 'asl-test-utils'
2
+
3
+ class AslGroupAddTest < Test::Unit::TestCase
4
+ include AslTestUtils
5
+
6
+ def setup
7
+ super
8
+ @command = File.join(@bin_dir, "asl-groupadd")
9
+ end
10
+
11
+ def test_run_as_normal_user
12
+ assert_equal([false, "", "need root authority.\n"],
13
+ run_command_as_normal_user("group-name"))
14
+ end
15
+
16
+ def test_exist_group
17
+ make_dummy_group do |group|
18
+ assert(@group_class.exists?(group.cn))
19
+ assert_equal([false, "", "group '#{group.cn}' already exists.\n"],
20
+ run_command(group.cn))
21
+ assert(@group_class.exists?(group.cn))
22
+ end
23
+ end
24
+
25
+ def test_add_group
26
+ ensure_delete_group("test-group") do |cn|
27
+ assert_asl_groupadd_successfully(cn)
28
+ end
29
+ end
30
+
31
+ def test_specify_gid
32
+ ensure_delete_group("test-group") do |cn|
33
+ gid_number = "11111"
34
+ assert_asl_groupadd_successfully(cn, "#{gid_number}\n",
35
+ "--print-gid-number",
36
+ "--gid", gid_number)
37
+ end
38
+ end
39
+
40
+ def test_print_gid_number
41
+ ensure_delete_group("test-group") do |cn|
42
+ pool_class = Class.new(ActiveSambaLdap::UnixIdPool)
43
+ pool_class.ldap_mapping
44
+ pool = pool_class.new(pool_class.configuration[:samba_domain])
45
+ next_gid = pool.find_available_gid_number(@group_class)
46
+ assert_asl_groupadd_successfully(cn, "#{next_gid}\n",
47
+ "--print-gid-number")
48
+ end
49
+ end
50
+
51
+ private
52
+ def assert_asl_groupadd_successfully(name, message=nil, *args)
53
+ _wrap_assertion do
54
+ assert(!@group_class.exists?(name))
55
+ args << name
56
+ assert_equal([true, "#{message}", ""], run_command(*args))
57
+ assert(@group_class.exists?(name))
58
+ end
59
+ end
60
+
61
+ def assert_asl_groupadd_failed(name, message, *args)
62
+ _wrap_assertion do
63
+ assert(!@group_class.exists?(name))
64
+ args << name
65
+ assert_equal([false, "", message], run_command(*args))
66
+ assert(!@group_class.exists?(name))
67
+ end
68
+ end
69
+ end