ruby-activeldap 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +17 -0
- data/README +5 -5
- data/TODO +0 -3
- data/benchmark/bench-al.rb +3 -3
- data/lib/active_ldap.rb +6 -1
- data/lib/active_ldap/base.rb +28 -6
- data/lib/active_ldap/connection.rb +0 -1
- data/test/al-test-utils.rb +1 -0
- data/test/test_base.rb +32 -1
- data/test/test_find.rb +2 -0
- data/test/test_userls.rb +12 -7
- metadata +3 -4
- data/test/config.yaml +0 -8
data/CHANGES
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
0.8.1:
|
2
|
+
* used Dependencies.load_paths.
|
3
|
+
* check whether attribute name is available or not.
|
4
|
+
* added test for find(:first, :attribute => 'xxx', :value => 'yyy').
|
5
|
+
* supported ActiveSupport 1.4.0.
|
6
|
+
* make the dual licensing of ruby-activeldap clear in the README.
|
7
|
+
* followed edge Rails: don't use Reloadable::Subclasses if doesn't need.
|
8
|
+
* added examples/.
|
9
|
+
* removed debug code.
|
10
|
+
* normalized attribute name to support wrong attribute names in MUST/MAY.
|
11
|
+
* supported getting dn value by Base#[].
|
12
|
+
* test/test_userls.rb: followed userls changes.
|
13
|
+
* update the doc href.
|
14
|
+
* provide a dumb example of how to use the old association(return_objects) style API with the new awesome API.
|
15
|
+
* followed new API.
|
16
|
+
* removed a finished task: support Reloadable::Subclasses.
|
17
|
+
|
1
18
|
0.8.0:
|
2
19
|
* Makefile/gemspec system replaced with Rakefile + Hoe
|
3
20
|
* Bugfix: Allow base to be empty
|
data/README
CHANGED
@@ -16,7 +16,7 @@ difficulty.
|
|
16
16
|
For example and usage - read the rdoc in doc/ from lib/activeldap.rb.
|
17
17
|
It is also available on the web at:
|
18
18
|
|
19
|
-
http://
|
19
|
+
http://ruby-activeldap.rubyforge.org/
|
20
20
|
|
21
21
|
PREREQUISITES
|
22
22
|
|
@@ -43,10 +43,10 @@ INSTALL
|
|
43
43
|
|
44
44
|
LICENCE
|
45
45
|
|
46
|
-
This program is free software; you can redistribute it and/or modify
|
47
|
-
|
48
|
-
the Free Software Foundation; either version 2,
|
49
|
-
any later version.
|
46
|
+
This program is free software; you can redistribute it and/or modify it. It is
|
47
|
+
dual licensed under Ruby's license and under the terms of the GNU General
|
48
|
+
Public License as published by the Free Software Foundation; either version 2,
|
49
|
+
or (at your option) any later version.
|
50
50
|
|
51
51
|
Please see the file LICENSE for the terms of the licence.
|
52
52
|
|
data/TODO
CHANGED
@@ -8,9 +8,6 @@ http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000865
|
|
8
8
|
- handle all exception raised from Ruby/LDAP and wrap as
|
9
9
|
ActiveLdap exception. I think we need to develop an
|
10
10
|
application using ActiveLdap.
|
11
|
-
- support Reloadable::Subclasses. I think we need to
|
12
|
-
develop a Rails + ActiveLdap application to improve
|
13
|
-
Rails support.
|
14
11
|
- support Ruby/GetText.
|
15
12
|
- support Net::LDAP as LDAP backend after Net::LDAP
|
16
13
|
supports START_TLS. (I made a patch and submitted to the
|
data/benchmark/bench-al.rb
CHANGED
@@ -55,7 +55,7 @@ def populate_base
|
|
55
55
|
name, value = suffix.split(/=/, 2)
|
56
56
|
next unless name == "dc"
|
57
57
|
dc_class = Class.new(ActiveLdap::Base)
|
58
|
-
dc_class.ldap_mapping :
|
58
|
+
dc_class.ldap_mapping :dn_attribute => "dc",
|
59
59
|
:prefix => "",
|
60
60
|
:scope => :base,
|
61
61
|
:classes => ["top", "dcObject", "organization"]
|
@@ -73,7 +73,7 @@ end
|
|
73
73
|
|
74
74
|
def populate_users
|
75
75
|
ou_class = Class.new(ActiveLdap::Base)
|
76
|
-
ou_class.ldap_mapping :
|
76
|
+
ou_class.ldap_mapping :dn_attribute => "ou",
|
77
77
|
:prefix => "",
|
78
78
|
:classes => ["top", "organizationalUnit"]
|
79
79
|
ou_class.new(LDAP_PREFIX.split(/=/)[1]).save!
|
@@ -109,7 +109,7 @@ def main(argv)
|
|
109
109
|
do_populate = LDAP_USER && LDAP_PASSWORD
|
110
110
|
|
111
111
|
if do_populate
|
112
|
-
config[:
|
112
|
+
config[:bind_dn] = LDAP_USER
|
113
113
|
config[:password] = LDAP_PASSWORD
|
114
114
|
end
|
115
115
|
ActiveLdap::Base.establish_connection(config)
|
data/lib/active_ldap.rb
CHANGED
@@ -931,6 +931,11 @@ require_gem_if_need = Proc.new do |library_name, gem_name|
|
|
931
931
|
end
|
932
932
|
|
933
933
|
require_gem_if_need.call("active_support", "activesupport")
|
934
|
+
|
935
|
+
if Dependencies.respond_to?(:load_paths)
|
936
|
+
Dependencies.load_paths << File.expand_path(File.dirname(__FILE__))
|
937
|
+
end
|
938
|
+
|
934
939
|
require 'active_ldap/base'
|
935
940
|
require 'active_ldap/associations'
|
936
941
|
require 'active_ldap/configuration'
|
@@ -944,7 +949,7 @@ require 'active_ldap/validations'
|
|
944
949
|
require 'active_ldap/callbacks'
|
945
950
|
|
946
951
|
module ActiveLdap
|
947
|
-
VERSION = "0.8.
|
952
|
+
VERSION = "0.8.1"
|
948
953
|
end
|
949
954
|
|
950
955
|
ActiveLdap::Base.class_eval do
|
data/lib/active_ldap/base.rb
CHANGED
@@ -135,13 +135,25 @@ module ActiveLdap
|
|
135
135
|
class AdapterNotSpecified < Error
|
136
136
|
end
|
137
137
|
|
138
|
+
class UnknownAttribute < Error
|
139
|
+
attr_reader :name
|
140
|
+
def initialize(name)
|
141
|
+
@name = name
|
142
|
+
super("#{@name} is unknown attribute")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
138
146
|
# Base
|
139
147
|
#
|
140
148
|
# Base is the primary class which contains all of the core
|
141
149
|
# ActiveLdap functionality. It is meant to only ever be subclassed
|
142
150
|
# by extension classes.
|
143
151
|
class Base
|
144
|
-
|
152
|
+
if Reloadable.const_defined?(:Deprecated)
|
153
|
+
include Reloadable::Deprecated
|
154
|
+
else
|
155
|
+
include Reloadable::Subclasses
|
156
|
+
end
|
145
157
|
|
146
158
|
VALID_LDAP_MAPPING_OPTIONS = [:dn_attribute, :prefix, :classes, :scope]
|
147
159
|
|
@@ -916,7 +928,11 @@ module ActiveLdap
|
|
916
928
|
end
|
917
929
|
|
918
930
|
def [](name, force_array=false)
|
919
|
-
|
931
|
+
if name == "dn"
|
932
|
+
array_of(dn, force_array)
|
933
|
+
else
|
934
|
+
get_attribute(name, force_array)
|
935
|
+
end
|
920
936
|
end
|
921
937
|
|
922
938
|
def []=(name, value)
|
@@ -1033,14 +1049,20 @@ module ActiveLdap
|
|
1033
1049
|
@musts[objc] = attributes[:must]
|
1034
1050
|
@mays[objc] = attributes[:may]
|
1035
1051
|
end
|
1036
|
-
@must = @musts.values
|
1037
|
-
@may = @mays.values
|
1052
|
+
@must = normalize_attribute_names(@musts.values)
|
1053
|
+
@may = normalize_attribute_names(@mays.values)
|
1038
1054
|
(@must + @may).uniq.each do |attr|
|
1039
1055
|
# Update attr_method with appropriate
|
1040
1056
|
define_attribute_methods(attr)
|
1041
1057
|
end
|
1042
1058
|
end
|
1043
1059
|
|
1060
|
+
def normalize_attribute_names(names)
|
1061
|
+
names.flatten.uniq.collect do |may|
|
1062
|
+
schema.attribute_aliases(may).first
|
1063
|
+
end
|
1064
|
+
end
|
1065
|
+
|
1044
1066
|
alias_method :base_of_class, :base
|
1045
1067
|
def base
|
1046
1068
|
logger.debug {"stub: called base"}
|
@@ -1100,6 +1122,7 @@ module ActiveLdap
|
|
1100
1122
|
|
1101
1123
|
# Get the attr and clean up the input
|
1102
1124
|
attr = to_real_attribute_name(name)
|
1125
|
+
raise UnknownAttribute.new(name) if attr.nil?
|
1103
1126
|
|
1104
1127
|
if attr == dn_attribute and value.is_a?(String)
|
1105
1128
|
value = value.gsub(/,#{Regexp.escape(base_of_class)}$/, '')
|
@@ -1139,8 +1162,7 @@ module ActiveLdap
|
|
1139
1162
|
def define_attribute_methods(attr)
|
1140
1163
|
logger.debug {"stub: called define_attribute_methods(#{attr.inspect})"}
|
1141
1164
|
return if @attr_methods.has_key? attr
|
1142
|
-
|
1143
|
-
aliases.each do |ali|
|
1165
|
+
schema.attribute_aliases(attr).each do |ali|
|
1144
1166
|
logger.debug {"associating #{ali} --> #{attr}"}
|
1145
1167
|
@attr_methods[ali] = attr
|
1146
1168
|
logger.debug {"associating #{Inflector.underscore(ali)}" +
|
data/test/al-test-utils.rb
CHANGED
data/test/test_base.rb
CHANGED
@@ -4,6 +4,38 @@ class TestBase < Test::Unit::TestCase
|
|
4
4
|
include AlTestUtils
|
5
5
|
|
6
6
|
priority :must
|
7
|
+
def test_new_without_class
|
8
|
+
no_class_class = Class.new(ActiveLdap::Base)
|
9
|
+
no_class_class.ldap_mapping :dn_attribute => "dc", :prefix => "",
|
10
|
+
:classes => []
|
11
|
+
assert_raises(ActiveLdap::UnknownAttribute) do
|
12
|
+
no_class_class.new("xxx")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
priority :normal
|
17
|
+
def test_save_for_dNSDomain
|
18
|
+
domain_class = Class.new(ActiveLdap::Base)
|
19
|
+
domain_class.ldap_mapping :dn_attribute => "dc", :prefix => "",
|
20
|
+
:classes => ['top', 'dcObject', 'dNSDomain']
|
21
|
+
name = "ftp"
|
22
|
+
a_record = "192.168.1.1"
|
23
|
+
|
24
|
+
domain = domain_class.new('ftp')
|
25
|
+
domain.a_record = a_record
|
26
|
+
assert(domain.save)
|
27
|
+
assert_equal(a_record, domain.a_record)
|
28
|
+
assert_equal(a_record, domain_class.find(name).a_record)
|
29
|
+
ensure
|
30
|
+
domain_class.delete(name) if domain_class.exists?(name)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_dn_by_index_getter
|
34
|
+
make_temporary_user do |user,|
|
35
|
+
assert_equal(user.dn, user["dn"])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
7
39
|
def test_create_multiple
|
8
40
|
ensure_delete_user("temp-user1") do |uid1,|
|
9
41
|
ensure_delete_user("temp-user2") do |uid2,|
|
@@ -52,7 +84,6 @@ class TestBase < Test::Unit::TestCase
|
|
52
84
|
end
|
53
85
|
end
|
54
86
|
|
55
|
-
priority :normal
|
56
87
|
def test_reload_of_not_exists_entry
|
57
88
|
make_temporary_user do |user,|
|
58
89
|
assert_nothing_raised do
|
data/test/test_find.rb
CHANGED
@@ -15,6 +15,8 @@ class TestFind < Test::Unit::TestCase
|
|
15
15
|
make_temporary_user do |user, password|
|
16
16
|
assert_equal(user.uid, @user_class.find(:first).uid)
|
17
17
|
assert_equal(user.uid, @user_class.find(user.uid).uid)
|
18
|
+
options = {:attribute => "cn", :value => user.cn}
|
19
|
+
assert_equal(user.uid, @user_class.find(:first, options).uid)
|
18
20
|
assert_equal(user.to_ldif, @user_class.find(:first).to_ldif)
|
19
21
|
assert_equal([user.uid], @user_class.find(:all).collect {|u| u.uid})
|
20
22
|
|
data/test/test_userls.rb
CHANGED
@@ -23,14 +23,14 @@ class TestUserls < Test::Unit::TestCase
|
|
23
23
|
|
24
24
|
def test_list_user_no_group
|
25
25
|
make_temporary_user do |user, password|
|
26
|
-
assert_userls_successfully(user.uid, [])
|
26
|
+
assert_userls_successfully(user.uid, [], [])
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_list_user_have_primary_group
|
31
31
|
make_temporary_group do |group|
|
32
32
|
make_temporary_user(:gid_number => group.gid_number) do |user, password|
|
33
|
-
assert_userls_successfully(user.uid, [group])
|
33
|
+
assert_userls_successfully(user.uid, [group], [])
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -42,7 +42,7 @@ class TestUserls < Test::Unit::TestCase
|
|
42
42
|
make_temporary_user(options) do |user, password|
|
43
43
|
user.groups << group1
|
44
44
|
user.groups << group2
|
45
|
-
assert_userls_successfully(user.uid, [group1, group2])
|
45
|
+
assert_userls_successfully(user.uid, [], [group1, group2])
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -55,7 +55,7 @@ class TestUserls < Test::Unit::TestCase
|
|
55
55
|
make_temporary_group do |group3|
|
56
56
|
user.groups << group2
|
57
57
|
user.groups << group3
|
58
|
-
assert_userls_successfully(user.uid, [group1, group2, group3])
|
58
|
+
assert_userls_successfully(user.uid, [group1], [group2, group3])
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -63,13 +63,18 @@ class TestUserls < Test::Unit::TestCase
|
|
63
63
|
end
|
64
64
|
|
65
65
|
private
|
66
|
-
def assert_userls_successfully(name, groups, *args, &block)
|
66
|
+
def assert_userls_successfully(name, primary_groups, groups, *args, &block)
|
67
67
|
_wrap_assertion do
|
68
68
|
assert(@user_class.exists?(name))
|
69
69
|
args.concat([name])
|
70
70
|
user = @user_class.find(name)
|
71
|
-
|
72
|
-
|
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"
|
73
78
|
assert_equal([true, result], run_command(*args, &block))
|
74
79
|
assert(@user_class.exists?(name))
|
75
80
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby-activeldap
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.8.
|
7
|
-
date:
|
6
|
+
version: 0.8.1
|
7
|
+
date: 2007-01-28 00:00:00 +00:00
|
8
8
|
summary: Ruby/ActiveLdap is a object-oriented API to LDAP
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -92,8 +92,8 @@ test_files:
|
|
92
92
|
- test/TODO
|
93
93
|
- test/config.yaml.sample
|
94
94
|
- test/test_reflection.rb
|
95
|
-
- test/test_connection_per_class.rb
|
96
95
|
- test/test_callback.rb
|
96
|
+
- test/test_connection_per_class.rb
|
97
97
|
- test/test_connection.rb
|
98
98
|
- test/test_schema.rb
|
99
99
|
- test/test_userdel.rb
|
@@ -102,7 +102,6 @@ test_files:
|
|
102
102
|
- test/test_base.rb
|
103
103
|
- test/test_userls.rb
|
104
104
|
- test/test_lpasswd.rb
|
105
|
-
- test/config.yaml
|
106
105
|
rdoc_options: []
|
107
106
|
|
108
107
|
extra_rdoc_files: []
|