ActiveSambaLdap 0.0.7
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.
- data/NEWS.en +40 -0
- data/NEWS.ja +44 -0
- data/README.en +366 -0
- data/README.ja +361 -0
- data/Rakefile +168 -0
- data/bin/asl-groupadd +73 -0
- data/bin/asl-groupadd.help +1 -0
- data/bin/asl-groupdel +61 -0
- data/bin/asl-groupdel.help +1 -0
- data/bin/asl-groupmod +137 -0
- data/bin/asl-groupmod.help +1 -0
- data/bin/asl-groupshow +33 -0
- data/bin/asl-groupshow.help +1 -0
- data/bin/asl-passwd +90 -0
- data/bin/asl-passwd.help +1 -0
- data/bin/asl-populate +101 -0
- data/bin/asl-populate.help +1 -0
- data/bin/asl-purge +26 -0
- data/bin/asl-purge.help +1 -0
- data/bin/asl-samba-computeradd +96 -0
- data/bin/asl-samba-computeradd.help +1 -0
- data/bin/asl-samba-groupadd +57 -0
- data/bin/asl-samba-groupadd.help +1 -0
- data/bin/asl-samba-groupdel +55 -0
- data/bin/asl-samba-groupdel.help +1 -0
- data/bin/asl-samba-groupmod +99 -0
- data/bin/asl-samba-groupmod.help +1 -0
- data/bin/asl-samba-useradd +100 -0
- data/bin/asl-samba-useradd.help +1 -0
- data/bin/asl-samba-userdel +49 -0
- data/bin/asl-samba-userdel.help +1 -0
- data/bin/asl-samba-usermod +94 -0
- data/bin/asl-samba-usermod.help +1 -0
- data/bin/asl-useradd +264 -0
- data/bin/asl-useradd.help +1 -0
- data/bin/asl-userdel +84 -0
- data/bin/asl-userdel.help +1 -0
- data/bin/asl-usermod +335 -0
- data/bin/asl-usermod.help +1 -0
- data/bin/asl-usershow +33 -0
- data/bin/asl-usershow.help +1 -0
- data/lib/active_samba_ldap.rb +42 -0
- data/lib/active_samba_ldap/account_entry.rb +208 -0
- data/lib/active_samba_ldap/base.rb +137 -0
- data/lib/active_samba_ldap/command.rb +100 -0
- data/lib/active_samba_ldap/computer.rb +24 -0
- data/lib/active_samba_ldap/computer_account_entry.rb +34 -0
- data/lib/active_samba_ldap/configuration.rb +333 -0
- data/lib/active_samba_ldap/dc.rb +19 -0
- data/lib/active_samba_ldap/entry.rb +81 -0
- data/lib/active_samba_ldap/get_text_support.rb +12 -0
- data/lib/active_samba_ldap/group.rb +17 -0
- data/lib/active_samba_ldap/group_entry.rb +187 -0
- data/lib/active_samba_ldap/idmap.rb +19 -0
- data/lib/active_samba_ldap/ou.rb +20 -0
- data/lib/active_samba_ldap/populate.rb +257 -0
- data/lib/active_samba_ldap/reloadable.rb +15 -0
- data/lib/active_samba_ldap/samba_account_entry.rb +225 -0
- data/lib/active_samba_ldap/samba_entry.rb +26 -0
- data/lib/active_samba_ldap/samba_group_entry.rb +143 -0
- data/lib/active_samba_ldap/unix_id_pool.rb +43 -0
- data/lib/active_samba_ldap/user.rb +44 -0
- data/lib/active_samba_ldap/user_account_entry.rb +30 -0
- data/lib/active_samba_ldap/version.rb +3 -0
- data/lib/samba/encrypt.rb +86 -0
- data/misc/rd2html.rb +42 -0
- data/po/ja/active-samba-ldap.po +465 -0
- data/rails/README +30 -0
- data/rails/init.rb +33 -0
- data/rails_generators/scaffold_active_samba_ldap/scaffold_active_samba_ldap_generator.rb +27 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/computer.rb +3 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/dc.rb +3 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/group.rb +3 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/idmap.rb +3 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/ldap.yml +24 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/ou.rb +3 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/samba_controller.rb +12 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/samba_helper.rb +2 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/samba_index.rhtml +17 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/samba_populate.rhtml +15 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/samba_purge.rhtml +10 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/unix_id_pool.rb +3 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/user.rb +3 -0
- data/setup.rb +1585 -0
- data/test-unit/History.txt +107 -0
- data/test-unit/README.txt +52 -0
- data/test-unit/Rakefile +40 -0
- data/test-unit/TODO +5 -0
- data/test-unit/bin/testrb +5 -0
- data/test-unit/lib/test/unit.rb +342 -0
- data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
- data/test-unit/lib/test/unit/assertions.rb +1149 -0
- data/test-unit/lib/test/unit/attribute.rb +125 -0
- data/test-unit/lib/test/unit/autorunner.rb +329 -0
- data/test-unit/lib/test/unit/collector.rb +43 -0
- data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
- data/test-unit/lib/test/unit/collector/dir.rb +108 -0
- data/test-unit/lib/test/unit/collector/load.rb +135 -0
- data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
- data/test-unit/lib/test/unit/color-scheme.rb +86 -0
- data/test-unit/lib/test/unit/color.rb +96 -0
- data/test-unit/lib/test/unit/diff.rb +538 -0
- data/test-unit/lib/test/unit/error.rb +124 -0
- data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
- data/test-unit/lib/test/unit/failure.rb +110 -0
- data/test-unit/lib/test/unit/fixture.rb +176 -0
- data/test-unit/lib/test/unit/notification.rb +125 -0
- data/test-unit/lib/test/unit/omission.rb +143 -0
- data/test-unit/lib/test/unit/pending.rb +146 -0
- data/test-unit/lib/test/unit/priority.rb +181 -0
- data/test-unit/lib/test/unit/runner/console.rb +52 -0
- data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
- data/test-unit/lib/test/unit/testcase.rb +425 -0
- data/test-unit/lib/test/unit/testresult.rb +89 -0
- data/test-unit/lib/test/unit/testsuite.rb +110 -0
- data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +223 -0
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
- data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
- data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
- data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
- data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
- data/test-unit/lib/test/unit/util/observable.rb +90 -0
- data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
- data/test-unit/lib/test/unit/version.rb +7 -0
- data/test-unit/sample/adder.rb +13 -0
- data/test-unit/sample/subtracter.rb +12 -0
- data/test-unit/sample/tc_adder.rb +18 -0
- data/test-unit/sample/tc_subtracter.rb +18 -0
- data/test-unit/sample/test_user.rb +22 -0
- data/test-unit/sample/ts_examples.rb +7 -0
- data/test-unit/test/collector/test-descendant.rb +135 -0
- data/test-unit/test/collector/test-load.rb +333 -0
- data/test-unit/test/collector/test_dir.rb +406 -0
- data/test-unit/test/collector/test_objectspace.rb +98 -0
- data/test-unit/test/run-test.rb +13 -0
- data/test-unit/test/test-attribute.rb +86 -0
- data/test-unit/test/test-color-scheme.rb +56 -0
- data/test-unit/test/test-color.rb +47 -0
- data/test-unit/test/test-diff.rb +477 -0
- data/test-unit/test/test-emacs-runner.rb +60 -0
- data/test-unit/test/test-fixture.rb +287 -0
- data/test-unit/test/test-notification.rb +33 -0
- data/test-unit/test/test-omission.rb +81 -0
- data/test-unit/test/test-pending.rb +70 -0
- data/test-unit/test/test-priority.rb +119 -0
- data/test-unit/test/test-testcase.rb +507 -0
- data/test-unit/test/test_assertions.rb +1082 -0
- data/test-unit/test/test_error.rb +26 -0
- data/test-unit/test/test_failure.rb +33 -0
- data/test-unit/test/test_testresult.rb +113 -0
- data/test-unit/test/test_testsuite.rb +129 -0
- data/test-unit/test/testunit-test-util.rb +14 -0
- data/test-unit/test/ui/test_testrunmediator.rb +20 -0
- data/test-unit/test/util/test-method-owner-finder.rb +38 -0
- data/test-unit/test/util/test_backtracefilter.rb +41 -0
- data/test-unit/test/util/test_observable.rb +102 -0
- data/test-unit/test/util/test_procwrapper.rb +36 -0
- data/test/asl-test-utils.rb +276 -0
- data/test/command.rb +67 -0
- data/test/config.yaml.sample +17 -0
- data/test/run-test.rb +20 -0
- data/test/test_asl_groupadd.rb +69 -0
- data/test/test_asl_groupdel.rb +88 -0
- data/test/test_asl_groupmod.rb +259 -0
- data/test/test_asl_groupshow.rb +21 -0
- data/test/test_asl_passwd.rb +126 -0
- data/test/test_asl_populate.rb +92 -0
- data/test/test_asl_purge.rb +21 -0
- data/test/test_asl_useradd.rb +712 -0
- data/test/test_asl_userdel.rb +75 -0
- data/test/test_asl_usermod.rb +549 -0
- data/test/test_asl_usershow.rb +27 -0
- data/test/test_entry.rb +21 -0
- data/test/test_group.rb +21 -0
- data/test/test_password.rb +51 -0
- data/test/test_samba_encrypt.rb +35 -0
- data/test/test_user_home_directory.rb +43 -0
- metadata +314 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
# Author:: Nathaniel Talbott.
|
2
|
+
# Copyright:: Copyright (c) 2000-2002 Nathaniel Talbott. All rights reserved.
|
3
|
+
# License:: Ruby license.
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'test/unit/util/procwrapper'
|
7
|
+
|
8
|
+
module Test
|
9
|
+
module Unit
|
10
|
+
module Util
|
11
|
+
class TC_ProcWrapper < TestCase
|
12
|
+
def munge_proc(&a_proc)
|
13
|
+
return a_proc
|
14
|
+
end
|
15
|
+
def setup
|
16
|
+
@original = proc {}
|
17
|
+
@munged = munge_proc(&@original)
|
18
|
+
@wrapped_original = ProcWrapper.new(@original)
|
19
|
+
@wrapped_munged = ProcWrapper.new(@munged)
|
20
|
+
end
|
21
|
+
def test_wrapping
|
22
|
+
assert_same(@original, @wrapped_original.to_proc, "The wrapper should return what was wrapped")
|
23
|
+
end
|
24
|
+
def test_hashing
|
25
|
+
|
26
|
+
assert_equal(@wrapped_original.hash, @wrapped_munged.hash, "The original and munged should have the same hash when wrapped")
|
27
|
+
assert_equal(@wrapped_original, @wrapped_munged, "The wrappers should be equivalent")
|
28
|
+
|
29
|
+
a_hash = {@wrapped_original => @original}
|
30
|
+
assert(a_hash[@wrapped_original], "Should be able to access the wrapper in the hash")
|
31
|
+
assert_equal(a_hash[@wrapped_original], @original, "Should be able to access the wrapper in the hash")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,276 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
require 'rbconfig'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'tmpdir'
|
6
|
+
|
7
|
+
require File.join(File.dirname(__FILE__), "command")
|
8
|
+
|
9
|
+
require 'active_samba_ldap'
|
10
|
+
|
11
|
+
module AslTestUtils
|
12
|
+
def self.included(base)
|
13
|
+
base.class_eval do
|
14
|
+
include ActiveSambaLdap::GetTextSupport
|
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.setup_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.setup_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::User)
|
89
|
+
@user_class.ldap_mapping
|
90
|
+
@computer_class = Class.new(ActiveSambaLdap::Computer)
|
91
|
+
@computer_class.ldap_mapping
|
92
|
+
@group_class = Class.new(ActiveSambaLdap::Group)
|
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] || (1000000 + @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] || (1000000 + @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] || (2000000 + @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,67 @@
|
|
1
|
+
require "thread"
|
2
|
+
require "socket"
|
3
|
+
require "shellwords"
|
4
|
+
require "timeout"
|
5
|
+
|
6
|
+
module Command
|
7
|
+
class Error < StandardError
|
8
|
+
attr_reader :command, :result
|
9
|
+
def initialize(command, result)
|
10
|
+
@command = command
|
11
|
+
@result = result
|
12
|
+
super("#{command}: #{result}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module_function
|
17
|
+
def detach_io
|
18
|
+
require 'fcntl'
|
19
|
+
[TCPSocket, ::File].each do |c|
|
20
|
+
ObjectSpace.each_object(c) do |io|
|
21
|
+
begin
|
22
|
+
unless io.closed?
|
23
|
+
io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
|
24
|
+
end
|
25
|
+
rescue SystemCallError,IOError => e
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def run(cmd, *args)
|
32
|
+
raise ArgumentError, "command isn't specified" if cmd.nil?
|
33
|
+
if args.any? {|x| x.nil?}
|
34
|
+
raise ArgumentError, "args has nil: #{args.inspect}"
|
35
|
+
end
|
36
|
+
in_r, in_w = IO.pipe
|
37
|
+
out_r, out_w = IO.pipe
|
38
|
+
err_r, err_w = IO.pipe
|
39
|
+
pid = exit_status = nil
|
40
|
+
Thread.exclusive do
|
41
|
+
verbose = $VERBOSE
|
42
|
+
# ruby(>=1.8)'s fork terminates other threads with warning messages
|
43
|
+
$VERBOSE = nil
|
44
|
+
pid = fork do
|
45
|
+
$VERBOSE = verbose
|
46
|
+
detach_io
|
47
|
+
$stdin.reopen(in_r)
|
48
|
+
in_r.close
|
49
|
+
$stdout.reopen(out_w)
|
50
|
+
$stderr.reopen(err_w)
|
51
|
+
out_w.close
|
52
|
+
err_w.close
|
53
|
+
exec(cmd, *args.collect {|arg| arg.to_s})
|
54
|
+
exit!(-1)
|
55
|
+
end
|
56
|
+
$VERBOSE = verbose
|
57
|
+
end
|
58
|
+
yield(out_r, in_w) if block_given?
|
59
|
+
in_r.close unless in_r.closed?
|
60
|
+
out_w.close unless out_w.closed?
|
61
|
+
err_w.close unless err_w.closed?
|
62
|
+
Timeout.timeout(5) do
|
63
|
+
pid, status = Process.waitpid2(pid)
|
64
|
+
[status.exited? && status.exitstatus.zero?, out_r.read, err_r.read]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
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,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$VERBOSE = true
|
4
|
+
|
5
|
+
$KCODE = 'u'
|
6
|
+
|
7
|
+
top_dir = File.join(File.dirname(__FILE__), "..")
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift(File.join(top_dir, "test-unit", "lib"))
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
# $LOAD_PATH.unshift(File.join(top_dir, "..", "ldap", "lib"))
|
13
|
+
# $LOAD_PATH.unshift(File.join(top_dir, "..", "ldap"))
|
14
|
+
$LOAD_PATH.unshift(File.join(top_dir, "..", "activeldap", "lib"))
|
15
|
+
$LOAD_PATH.unshift(File.join(top_dir, "lib"))
|
16
|
+
$LOAD_PATH.unshift(File.join(top_dir, "test"))
|
17
|
+
|
18
|
+
ARGV.unshift("--priority")
|
19
|
+
|
20
|
+
exit Test::Unit::AutoRunner.run(true)
|
@@ -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 already exists: %s") % group.cn + "\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
|