ruby-activeldap 0.8.3 → 0.8.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +431 -0
- data/COPYING +340 -0
- data/LICENSE +58 -0
- data/README +104 -0
- data/Rakefile +165 -0
- data/TODO +22 -0
- data/benchmark/bench-al.rb +202 -0
- data/benchmark/config.yaml.sample +5 -0
- data/data/locale/en/LC_MESSAGES/active-ldap.mo +0 -0
- data/data/locale/ja/LC_MESSAGES/active-ldap.mo +0 -0
- data/examples/al-admin/README +182 -0
- data/examples/al-admin/Rakefile +10 -0
- data/examples/al-admin/app/controllers/account_controller.rb +50 -0
- data/examples/al-admin/app/controllers/application.rb +15 -0
- data/examples/al-admin/app/controllers/directory_controller.rb +22 -0
- data/examples/al-admin/app/controllers/users_controller.rb +38 -0
- data/examples/al-admin/app/controllers/welcome_controller.rb +4 -0
- data/examples/al-admin/app/helpers/account_helper.rb +2 -0
- data/examples/al-admin/app/helpers/application_helper.rb +6 -0
- data/examples/al-admin/app/helpers/directory_helper.rb +2 -0
- data/examples/al-admin/app/helpers/users_helper.rb +13 -0
- data/examples/al-admin/app/helpers/welcome_helper.rb +2 -0
- data/examples/al-admin/app/models/entry.rb +19 -0
- data/examples/al-admin/app/models/ldap_user.rb +49 -0
- data/examples/al-admin/app/models/user.rb +91 -0
- data/examples/al-admin/app/views/account/login.rhtml +12 -0
- data/examples/al-admin/app/views/account/sign_up.rhtml +22 -0
- data/examples/al-admin/app/views/directory/index.rhtml +5 -0
- data/examples/al-admin/app/views/directory/populate.rhtml +2 -0
- data/examples/al-admin/app/views/layouts/application.rhtml +41 -0
- data/examples/al-admin/app/views/users/_attribute_information.rhtml +22 -0
- data/examples/al-admin/app/views/users/_entry.rhtml +12 -0
- data/examples/al-admin/app/views/users/_form.rhtml +29 -0
- data/examples/al-admin/app/views/users/_object_class_information.rhtml +23 -0
- data/examples/al-admin/app/views/users/edit.rhtml +10 -0
- data/examples/al-admin/app/views/users/index.rhtml +9 -0
- data/examples/al-admin/app/views/users/show.rhtml +3 -0
- data/examples/al-admin/app/views/welcome/index.rhtml +16 -0
- data/examples/al-admin/config/boot.rb +45 -0
- data/examples/al-admin/config/database.yml.example +19 -0
- data/examples/al-admin/config/environment.rb +68 -0
- data/examples/al-admin/config/environments/development.rb +21 -0
- data/examples/al-admin/config/environments/production.rb +18 -0
- data/examples/al-admin/config/environments/test.rb +19 -0
- data/examples/al-admin/config/ldap.yml.example +21 -0
- data/examples/al-admin/config/routes.rb +26 -0
- data/examples/al-admin/db/migrate/001_create_users.rb +16 -0
- data/examples/al-admin/lib/accept_http_rails_relative_url_root.rb +9 -0
- data/examples/al-admin/lib/authenticated_system.rb +131 -0
- data/examples/al-admin/lib/authenticated_test_helper.rb +113 -0
- data/examples/al-admin/lib/tasks/gettext.rake +35 -0
- data/examples/al-admin/po/en/al-admin.po +190 -0
- data/examples/al-admin/po/ja/al-admin.po +190 -0
- data/examples/al-admin/po/nl/al-admin.po +202 -0
- data/examples/al-admin/public/.htaccess +40 -0
- data/examples/al-admin/public/404.html +30 -0
- data/examples/al-admin/public/500.html +30 -0
- data/examples/al-admin/public/dispatch.cgi +10 -0
- data/examples/al-admin/public/dispatch.fcgi +24 -0
- data/examples/al-admin/public/dispatch.rb +10 -0
- data/examples/al-admin/public/favicon.ico +0 -0
- data/examples/al-admin/public/images/rails.png +0 -0
- data/examples/al-admin/public/javascripts/application.js +2 -0
- data/examples/al-admin/public/javascripts/controls.js +833 -0
- data/examples/al-admin/public/javascripts/dragdrop.js +942 -0
- data/examples/al-admin/public/javascripts/effects.js +1088 -0
- data/examples/al-admin/public/javascripts/prototype.js +2515 -0
- data/examples/al-admin/public/robots.txt +1 -0
- data/examples/al-admin/public/stylesheets/rails.css +35 -0
- data/examples/al-admin/public/stylesheets/screen.css +52 -0
- data/examples/al-admin/script/about +3 -0
- data/examples/al-admin/script/breakpointer +3 -0
- data/examples/al-admin/script/console +3 -0
- data/examples/al-admin/script/destroy +3 -0
- data/examples/al-admin/script/generate +3 -0
- data/examples/al-admin/script/performance/benchmarker +3 -0
- data/examples/al-admin/script/performance/profiler +3 -0
- data/examples/al-admin/script/plugin +3 -0
- data/examples/al-admin/script/process/inspector +3 -0
- data/examples/al-admin/script/process/reaper +3 -0
- data/examples/al-admin/script/process/spawner +3 -0
- data/examples/al-admin/script/runner +3 -0
- data/examples/al-admin/script/server +3 -0
- data/examples/al-admin/test/fixtures/users.yml +9 -0
- data/examples/al-admin/test/functional/account_controller_test.rb +24 -0
- data/examples/al-admin/test/functional/directory_controller_test.rb +18 -0
- data/examples/al-admin/test/functional/users_controller_test.rb +18 -0
- data/examples/al-admin/test/functional/welcome_controller_test.rb +18 -0
- data/examples/al-admin/test/run-test.sh +3 -0
- data/examples/al-admin/test/test_helper.rb +28 -0
- data/examples/al-admin/test/unit/user_test.rb +13 -0
- data/examples/al-admin/vendor/plugins/exception_notification/README +111 -0
- data/examples/al-admin/vendor/plugins/exception_notification/init.rb +1 -0
- data/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifiable.rb +99 -0
- data/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier.rb +67 -0
- data/examples/al-admin/vendor/plugins/exception_notification/lib/exception_notifier_helper.rb +77 -0
- data/examples/al-admin/vendor/plugins/exception_notification/test/exception_notifier_helper_test.rb +61 -0
- data/examples/al-admin/vendor/plugins/exception_notification/test/test_helper.rb +7 -0
- data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_backtrace.rhtml +1 -0
- data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_environment.rhtml +7 -0
- data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_inspect_model.rhtml +16 -0
- data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_request.rhtml +3 -0
- data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_session.rhtml +2 -0
- data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/_title.rhtml +3 -0
- data/examples/al-admin/vendor/plugins/exception_notification/views/exception_notifier/exception_notification.rhtml +6 -0
- data/examples/config.yaml.example +5 -0
- data/examples/example.der +0 -0
- data/examples/example.jpg +0 -0
- data/examples/groupadd +41 -0
- data/examples/groupdel +35 -0
- data/examples/groupls +49 -0
- data/examples/groupmod +42 -0
- data/examples/lpasswd +55 -0
- data/examples/objects/group.rb +13 -0
- data/examples/objects/ou.rb +4 -0
- data/examples/objects/user.rb +20 -0
- data/examples/ouadd +38 -0
- data/examples/useradd +45 -0
- data/examples/useradd-binary +50 -0
- data/examples/userdel +34 -0
- data/examples/userls +50 -0
- data/examples/usermod +42 -0
- data/examples/usermod-binary-add +47 -0
- data/examples/usermod-binary-add-time +51 -0
- data/examples/usermod-binary-del +48 -0
- data/examples/usermod-lang-add +43 -0
- data/lib/active_ldap.rb +978 -0
- data/lib/active_ldap/adapter/base.rb +512 -0
- data/lib/active_ldap/adapter/ldap.rb +233 -0
- data/lib/active_ldap/adapter/ldap_ext.rb +69 -0
- data/lib/active_ldap/adapter/net_ldap.rb +290 -0
- data/lib/active_ldap/adapter/net_ldap_ext.rb +29 -0
- data/lib/active_ldap/association/belongs_to.rb +47 -0
- data/lib/active_ldap/association/belongs_to_many.rb +42 -0
- data/lib/active_ldap/association/collection.rb +83 -0
- data/lib/active_ldap/association/has_many.rb +31 -0
- data/lib/active_ldap/association/has_many_utils.rb +35 -0
- data/lib/active_ldap/association/has_many_wrap.rb +46 -0
- data/lib/active_ldap/association/proxy.rb +102 -0
- data/lib/active_ldap/associations.rb +172 -0
- data/lib/active_ldap/attributes.rb +211 -0
- data/lib/active_ldap/base.rb +1256 -0
- data/lib/active_ldap/callbacks.rb +19 -0
- data/lib/active_ldap/command.rb +48 -0
- data/lib/active_ldap/configuration.rb +114 -0
- data/lib/active_ldap/connection.rb +234 -0
- data/lib/active_ldap/distinguished_name.rb +250 -0
- data/lib/active_ldap/escape.rb +12 -0
- data/lib/active_ldap/get_text/parser.rb +142 -0
- data/lib/active_ldap/get_text_fallback.rb +53 -0
- data/lib/active_ldap/get_text_support.rb +12 -0
- data/lib/active_ldap/helper.rb +23 -0
- data/lib/active_ldap/ldap_error.rb +74 -0
- data/lib/active_ldap/object_class.rb +93 -0
- data/lib/active_ldap/operations.rb +419 -0
- data/lib/active_ldap/populate.rb +44 -0
- data/lib/active_ldap/schema.rb +427 -0
- data/lib/active_ldap/timeout.rb +75 -0
- data/lib/active_ldap/timeout_stub.rb +17 -0
- data/lib/active_ldap/user_password.rb +93 -0
- data/lib/active_ldap/validations.rb +112 -0
- data/po/en/active-ldap.po +3011 -0
- data/po/ja/active-ldap.po +3044 -0
- data/rails/plugin/active_ldap/README +54 -0
- data/rails/plugin/active_ldap/generators/scaffold_al/scaffold_al_generator.rb +7 -0
- data/rails/plugin/active_ldap/generators/scaffold_al/templates/ldap.yml +21 -0
- data/rails/plugin/active_ldap/init.rb +19 -0
- data/test/al-test-utils.rb +362 -0
- data/test/command.rb +62 -0
- data/test/config.yaml.sample +6 -0
- data/test/run-test.rb +31 -0
- data/test/test-unit-ext.rb +4 -0
- data/test/test-unit-ext/always-show-result.rb +28 -0
- data/test/test-unit-ext/backtrace-filter.rb +17 -0
- data/test/test-unit-ext/long-display-for-emacs.rb +25 -0
- data/test/test-unit-ext/priority.rb +163 -0
- metadata +211 -4
@@ -0,0 +1,54 @@
|
|
1
|
+
= ActiveLdap plugin for Ruby on Rails
|
2
|
+
|
3
|
+
== Setup
|
4
|
+
|
5
|
+
You need to write RAILS_ROOT/config/ldap.yml like the following:
|
6
|
+
|
7
|
+
development:
|
8
|
+
host: 127.0.0.1
|
9
|
+
port: 389
|
10
|
+
base: dc=devel,dc=local,dc=net
|
11
|
+
bind_dn: cn=admin,dc=local,dc=net
|
12
|
+
password: secret
|
13
|
+
|
14
|
+
test:
|
15
|
+
host: 127.0.0.1
|
16
|
+
port: 389
|
17
|
+
base: dc=test,dc=local,dc=net
|
18
|
+
bind_dn: cn=admin,dc=local,dc=net
|
19
|
+
password: secret
|
20
|
+
|
21
|
+
production:
|
22
|
+
host: 127.0.0.1
|
23
|
+
port: 389
|
24
|
+
base: dc=production,dc=local,dc=net
|
25
|
+
bind_dn: cn=admin,dc=local,dc=net
|
26
|
+
password: secret
|
27
|
+
|
28
|
+
== Model
|
29
|
+
|
30
|
+
Here is some examples.
|
31
|
+
|
32
|
+
app/model/member.rb:
|
33
|
+
class Member < ActiveLdap::Base
|
34
|
+
ldap_mapping :dn_attribute => 'uid',
|
35
|
+
:classes => ['person', 'posixAccount']
|
36
|
+
belongs_to :primary_group, :class => "Group",
|
37
|
+
:foreign_key => "gidNumber", :primary_key => "gidNumber"
|
38
|
+
belongs_to :groups, :many => 'memberUid'
|
39
|
+
end
|
40
|
+
|
41
|
+
app/model/group.rb:
|
42
|
+
class Group < ActiveLdap::Base
|
43
|
+
ldap_mapping :dn_attribute => "cn", :classes => ['posixGroup']
|
44
|
+
has_many :members, :wrap => "memberUid"
|
45
|
+
has_many :primary_members,
|
46
|
+
:foreign_key => 'gidNumber',
|
47
|
+
:primary_key => 'gidNumber'
|
48
|
+
end
|
49
|
+
|
50
|
+
app/model/ou.rb:
|
51
|
+
class Ou < ActiveLdap::Base
|
52
|
+
ldap_mapping :prefix => "",
|
53
|
+
:classes => ["top", "organizationalUnit"]
|
54
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
development:
|
2
|
+
host: 127.0.0.1
|
3
|
+
port: 389
|
4
|
+
base: dc=devel,dc=local,dc=net
|
5
|
+
bind_dn: cn=admin,dc=local,dc=net
|
6
|
+
password: secret
|
7
|
+
|
8
|
+
test:
|
9
|
+
host: 127.0.0.1
|
10
|
+
port: 389
|
11
|
+
base: dc=test,dc=local,dc=net
|
12
|
+
bind_dn: cn=admin,dc=local,dc=net
|
13
|
+
password: secret
|
14
|
+
|
15
|
+
production:
|
16
|
+
host: 127.0.0.1
|
17
|
+
port: 389
|
18
|
+
method: :tls
|
19
|
+
base: dc=production,dc=local,dc=net
|
20
|
+
bind_dn: cn=admin,dc=local,dc=net
|
21
|
+
password: secret
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_library_or_gem 'active_ldap'
|
2
|
+
ActiveLdap::Base.logger ||= RAILS_DEFAULT_LOGGER
|
3
|
+
ldap_configuration_file = File.join(RAILS_ROOT, 'config', 'ldap.yml')
|
4
|
+
if File.exist?(ldap_configuration_file)
|
5
|
+
configurations = YAML::load(ERB.new(IO.read(ldap_configuration_file)).result)
|
6
|
+
ActiveLdap::Base.configurations = configurations
|
7
|
+
ActiveLdap::Base.establish_connection
|
8
|
+
else
|
9
|
+
ActiveLdap::Base.class_eval do
|
10
|
+
format = _("You should run 'script/generator scaffold_al' to make %s.")
|
11
|
+
logger.error(format % ldap_configuration_file)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if ActiveLdap.const_defined?(:Helper)
|
16
|
+
class ActionView::Base
|
17
|
+
include ActiveLdap::Helper
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,362 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test-unit-ext'
|
3
|
+
|
4
|
+
require 'erb'
|
5
|
+
require 'yaml'
|
6
|
+
require 'socket'
|
7
|
+
require 'openssl'
|
8
|
+
require 'rbconfig'
|
9
|
+
require 'tempfile'
|
10
|
+
|
11
|
+
require 'active_ldap'
|
12
|
+
|
13
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "command")
|
14
|
+
|
15
|
+
LDAP_ENV = "test" unless defined?(LDAP_ENV)
|
16
|
+
|
17
|
+
module AlTestUtils
|
18
|
+
def self.included(base)
|
19
|
+
base.class_eval do
|
20
|
+
include ActiveLdap::GetTextSupport
|
21
|
+
include Config
|
22
|
+
include Connection
|
23
|
+
include Populate
|
24
|
+
include TemporaryEntry
|
25
|
+
include CommandSupport
|
26
|
+
include MockLogger
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module Config
|
31
|
+
def setup
|
32
|
+
super
|
33
|
+
@base_dir = File.expand_path(File.dirname(__FILE__))
|
34
|
+
@top_dir = File.expand_path(File.join(@base_dir, ".."))
|
35
|
+
@example_dir = File.join(@top_dir, "examples")
|
36
|
+
@config_file = File.join(File.dirname(__FILE__), "config.yaml")
|
37
|
+
ActiveLdap::Base.configurations = read_config
|
38
|
+
end
|
39
|
+
|
40
|
+
def teardown
|
41
|
+
super
|
42
|
+
end
|
43
|
+
|
44
|
+
def current_configuration
|
45
|
+
ActiveLdap::Base.configurations[LDAP_ENV]
|
46
|
+
end
|
47
|
+
|
48
|
+
def read_config
|
49
|
+
unless File.exist?(@config_file)
|
50
|
+
raise "config file for testing doesn't exist: #{@config_file}"
|
51
|
+
end
|
52
|
+
config = YAML.load(ERB.new(File.read(@config_file)).result)
|
53
|
+
config.each do |key, value|
|
54
|
+
adapter = ENV["ACTIVE_LDAP_TEST_ADAPTER"]
|
55
|
+
value[:adapter] = adapter if adapter
|
56
|
+
end
|
57
|
+
config
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
module Connection
|
62
|
+
def setup
|
63
|
+
super
|
64
|
+
ActiveLdap::Base.establish_connection
|
65
|
+
end
|
66
|
+
|
67
|
+
def teardown
|
68
|
+
ActiveLdap::Base.remove_active_connections!
|
69
|
+
super
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
module Populate
|
74
|
+
def setup
|
75
|
+
@dumped_data = nil
|
76
|
+
super
|
77
|
+
begin
|
78
|
+
@dumped_data = ActiveLdap::Base.dump(:scope => :sub)
|
79
|
+
rescue ActiveLdap::ConnectionError
|
80
|
+
end
|
81
|
+
ActiveLdap::Base.delete_all(nil, :scope => :sub)
|
82
|
+
populate
|
83
|
+
end
|
84
|
+
|
85
|
+
def teardown
|
86
|
+
if @dumped_data
|
87
|
+
ActiveLdap::Base.establish_connection
|
88
|
+
ActiveLdap::Base.delete_all(nil, :scope => :sub)
|
89
|
+
ActiveLdap::Base.load(@dumped_data)
|
90
|
+
end
|
91
|
+
super
|
92
|
+
end
|
93
|
+
|
94
|
+
def populate
|
95
|
+
populate_base
|
96
|
+
populate_ou
|
97
|
+
populate_user_class
|
98
|
+
populate_group_class
|
99
|
+
populate_associations
|
100
|
+
end
|
101
|
+
|
102
|
+
def populate_base
|
103
|
+
ActiveLdap::Populate.ensure_base
|
104
|
+
end
|
105
|
+
|
106
|
+
def ou_class(prefix="")
|
107
|
+
ou_class = Class.new(ActiveLdap::Base)
|
108
|
+
ou_class.ldap_mapping :dn_attribute => "ou",
|
109
|
+
:prefix => prefix,
|
110
|
+
:classes => ["top", "organizationalUnit"]
|
111
|
+
ou_class
|
112
|
+
end
|
113
|
+
|
114
|
+
def populate_ou
|
115
|
+
%w(Users Groups).each do |name|
|
116
|
+
make_ou(name)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def make_ou(name)
|
121
|
+
ActiveLdap::Populate.ensure_ou(name)
|
122
|
+
end
|
123
|
+
|
124
|
+
def populate_user_class
|
125
|
+
@user_class = Class.new(ActiveLdap::Base)
|
126
|
+
@user_class_classes = ["posixAccount", "person"]
|
127
|
+
@user_class.ldap_mapping :dn_attribute => "uid",
|
128
|
+
:prefix => "ou=Users",
|
129
|
+
:scope => :sub,
|
130
|
+
:classes => @user_class_classes
|
131
|
+
end
|
132
|
+
|
133
|
+
def populate_group_class
|
134
|
+
@group_class = Class.new(ActiveLdap::Base)
|
135
|
+
@group_class.ldap_mapping :prefix => "ou=Groups",
|
136
|
+
:scope => :sub,
|
137
|
+
:classes => ["posixGroup"]
|
138
|
+
end
|
139
|
+
|
140
|
+
def populate_associations
|
141
|
+
@user_class.belongs_to :groups, :many => "memberUid"
|
142
|
+
@user_class.belongs_to :primary_group,
|
143
|
+
:foreign_key => "gidNumber",
|
144
|
+
:primary_key => "gidNumber"
|
145
|
+
@group_class.has_many :members, :wrap => "memberUid"
|
146
|
+
@group_class.has_many :primary_members,
|
147
|
+
:foreign_key => "gidNumber",
|
148
|
+
:primary_key => "gidNumber"
|
149
|
+
@user_class.set_associated_class(:groups, @group_class)
|
150
|
+
@user_class.set_associated_class(:primary_group, @group_class)
|
151
|
+
@group_class.set_associated_class(:members, @user_class)
|
152
|
+
@group_class.set_associated_class(:primary_members, @user_class)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
module TemporaryEntry
|
157
|
+
@@certificate = nil
|
158
|
+
def setup
|
159
|
+
super
|
160
|
+
@user_index = 0
|
161
|
+
@group_index = 0
|
162
|
+
end
|
163
|
+
|
164
|
+
def make_temporary_user(config={})
|
165
|
+
@user_index += 1
|
166
|
+
uid = config[:uid] || "temp-user#{@user_index}"
|
167
|
+
ensure_delete_user(uid) do
|
168
|
+
password = config[:password] || "password#{@user_index}"
|
169
|
+
uid_number = config[:uid_number] || default_uid
|
170
|
+
gid_number = config[:gid_number] || default_gid
|
171
|
+
home_directory = config[:home_directory] || "/nonexistent"
|
172
|
+
_wrap_assertion do
|
173
|
+
assert(!@user_class.exists?(uid))
|
174
|
+
assert_raise(ActiveLdap::EntryNotFound) do
|
175
|
+
@user_class.find(uid).dn
|
176
|
+
end
|
177
|
+
user = @user_class.new(uid)
|
178
|
+
assert(user.new_entry?)
|
179
|
+
user.cn = user.uid
|
180
|
+
user.sn = user.uid
|
181
|
+
user.uid_number = uid_number
|
182
|
+
user.gid_number = gid_number
|
183
|
+
user.home_directory = home_directory
|
184
|
+
user.user_password = ActiveLdap::UserPassword.ssha(password)
|
185
|
+
unless config[:simple]
|
186
|
+
user.add_class('shadowAccount', 'inetOrgPerson',
|
187
|
+
'organizationalPerson')
|
188
|
+
user.user_certificate = certificate
|
189
|
+
user.jpeg_photo = jpeg_photo
|
190
|
+
end
|
191
|
+
user.save
|
192
|
+
assert(!user.new_entry?)
|
193
|
+
yield(@user_class.find(user.uid), password)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
def make_temporary_group(config={})
|
199
|
+
@group_index += 1
|
200
|
+
cn = config[:cn] || "temp-group#{@group_index}"
|
201
|
+
ensure_delete_group(cn) do
|
202
|
+
gid_number = config[:gid_number] || default_gid
|
203
|
+
_wrap_assertion do
|
204
|
+
assert(!@group_class.exists?(cn))
|
205
|
+
assert_raise(ActiveLdap::EntryNotFound) do
|
206
|
+
@group_class.find(cn)
|
207
|
+
end
|
208
|
+
group = @group_class.new(cn)
|
209
|
+
assert(group.new_entry?)
|
210
|
+
group.gid_number = gid_number
|
211
|
+
assert(group.save)
|
212
|
+
assert(!group.new_entry?)
|
213
|
+
yield(@group_class.find(group.cn))
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
def ensure_delete_user(uid)
|
219
|
+
yield(uid)
|
220
|
+
ensure
|
221
|
+
if @user_class.exists?(uid)
|
222
|
+
@user_class.find(uid).remove_connection
|
223
|
+
@user_class.delete(uid)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
def ensure_delete_group(cn)
|
228
|
+
yield(cn)
|
229
|
+
ensure
|
230
|
+
@group_class.delete(cn) if @group_class.exists?(cn)
|
231
|
+
end
|
232
|
+
|
233
|
+
def default_uid
|
234
|
+
"10000#{@user_index}"
|
235
|
+
end
|
236
|
+
|
237
|
+
def default_gid
|
238
|
+
"10000#{@group_index}"
|
239
|
+
end
|
240
|
+
|
241
|
+
def certificate_path
|
242
|
+
File.join(@example_dir, 'example.der')
|
243
|
+
end
|
244
|
+
|
245
|
+
def certificate
|
246
|
+
return @@certificate if @@certificate
|
247
|
+
if File.exists?(certificate_path)
|
248
|
+
@@certificate = File.read(certificate_path)
|
249
|
+
return @@certificate
|
250
|
+
end
|
251
|
+
|
252
|
+
rsa = OpenSSL::PKey::RSA.new(512)
|
253
|
+
comment = "Generated by Ruby/OpenSSL"
|
254
|
+
|
255
|
+
cert = OpenSSL::X509::Certificate.new
|
256
|
+
cert.version = 3
|
257
|
+
cert.serial = 0
|
258
|
+
subject = [["OU", "test"],
|
259
|
+
["CN", Socket.gethostname]]
|
260
|
+
name = OpenSSL::X509::Name.new(subject)
|
261
|
+
cert.subject = name
|
262
|
+
cert.issuer = name
|
263
|
+
cert.not_before = Time.now
|
264
|
+
cert.not_after = Time.now + (365*24*60*60)
|
265
|
+
cert.public_key = rsa.public_key
|
266
|
+
|
267
|
+
ef = OpenSSL::X509::ExtensionFactory.new(nil, cert)
|
268
|
+
ef.issuer_certificate = cert
|
269
|
+
cert.extensions = [
|
270
|
+
ef.create_extension("basicConstraints","CA:FALSE"),
|
271
|
+
ef.create_extension("keyUsage", "keyEncipherment"),
|
272
|
+
ef.create_extension("subjectKeyIdentifier", "hash"),
|
273
|
+
ef.create_extension("extendedKeyUsage", "serverAuth"),
|
274
|
+
ef.create_extension("nsComment", comment),
|
275
|
+
]
|
276
|
+
aki = ef.create_extension("authorityKeyIdentifier",
|
277
|
+
"keyid:always,issuer:always")
|
278
|
+
cert.add_extension(aki)
|
279
|
+
cert.sign(rsa, OpenSSL::Digest::SHA1.new)
|
280
|
+
|
281
|
+
@@certificate = cert.to_der
|
282
|
+
@@certificate
|
283
|
+
end
|
284
|
+
|
285
|
+
def jpeg_photo_path
|
286
|
+
File.join(@example_dir, 'example.jpg')
|
287
|
+
end
|
288
|
+
|
289
|
+
def jpeg_photo
|
290
|
+
File.read(jpeg_photo_path)
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
module CommandSupport
|
295
|
+
def setup
|
296
|
+
super
|
297
|
+
@fakeroot = "fakeroot"
|
298
|
+
@ruby = File.join(::Config::CONFIG["bindir"],
|
299
|
+
::Config::CONFIG["RUBY_INSTALL_NAME"])
|
300
|
+
@top_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
301
|
+
@examples_dir = File.join(@top_dir, "examples")
|
302
|
+
@lib_dir = File.join(@top_dir, "lib")
|
303
|
+
@ruby_args = [
|
304
|
+
"-I", @examples_dir,
|
305
|
+
"-I", @lib_dir,
|
306
|
+
]
|
307
|
+
end
|
308
|
+
|
309
|
+
def run_command(*args, &block)
|
310
|
+
file = Tempfile.new("al-command-support")
|
311
|
+
file.open
|
312
|
+
file.puts(ActiveLdap::Base.configurations["test"].to_yaml)
|
313
|
+
file.close
|
314
|
+
run_ruby(*[@command, "--config", file.path, *args], &block)
|
315
|
+
end
|
316
|
+
|
317
|
+
def run_ruby(*ruby_args, &block)
|
318
|
+
args = [@ruby, *@ruby_args]
|
319
|
+
args.concat(ruby_args)
|
320
|
+
Command.run(*args, &block)
|
321
|
+
end
|
322
|
+
|
323
|
+
def run_ruby_with_fakeroot(*ruby_args, &block)
|
324
|
+
args = [@fakeroot, @ruby, *@ruby_args]
|
325
|
+
args.concat(ruby_args)
|
326
|
+
Command.run(*args, &block)
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
module MockLogger
|
331
|
+
def make_mock_logger
|
332
|
+
logger = Object.new
|
333
|
+
class << logger
|
334
|
+
def messages(type)
|
335
|
+
@messages ||= {}
|
336
|
+
@messages[type] ||= []
|
337
|
+
@messages[type]
|
338
|
+
end
|
339
|
+
|
340
|
+
def info(content=nil)
|
341
|
+
messages(:info) << (block_given? ? yield : content)
|
342
|
+
end
|
343
|
+
def warn(content=nil)
|
344
|
+
messages(:warn) << (block_given? ? yield : content)
|
345
|
+
end
|
346
|
+
def error(content=nil)
|
347
|
+
messages(:error) << (block_given? ? yield : content)
|
348
|
+
end
|
349
|
+
end
|
350
|
+
logger
|
351
|
+
end
|
352
|
+
|
353
|
+
def with_mock_logger
|
354
|
+
original_logger = ActiveLdap::Base.logger
|
355
|
+
mock_logger = make_mock_logger
|
356
|
+
ActiveLdap::Base.logger = mock_logger
|
357
|
+
yield(mock_logger)
|
358
|
+
ensure
|
359
|
+
ActiveLdap::Base.logger = original_logger
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|