This commit is contained in:
Matt Todd 2014-08-20 08:59:04 -07:00
Родитель 70fd45416b
Коммит 7bf8fd3d25
2 изменённых файлов: 30 добавлений и 21 удалений

Просмотреть файл

@ -20,26 +20,31 @@ module GitHub
# Filter to check group membership. # Filter to check group membership.
# #
# entry: finds groups this Net::LDAP::Entry is a member of (optional) # entry: finds groups this Net::LDAP::Entry is a member of (optional)
# uid_attr: specifies the memberUid attribute to match with (optional)
# #
# Returns a Net::LDAP::Filter. # Returns a Net::LDAP::Filter.
def member_filter(entry = nil, uid_attr = @ldap.uid) def member_filter(entry = nil)
if entry if entry
filter = MEMBERSHIP_NAMES.
MEMBERSHIP_NAMES. map {|n| Net::LDAP::Filter.eq(n, entry.dn) }. map {|n| Net::LDAP::Filter.eq(n, entry.dn) }.reduce(:|)
reduce(:|)
if !entry[uid_attr].empty?
filter |=
entry[uid_attr].map { |uid| Net::LDAP::Filter.eq("memberUid", uid) }.
reduce(:|)
end
filter
else else
(MEMBERSHIP_NAMES + %w(memberUid)). MEMBERSHIP_NAMES.
map {|n| Net::LDAP::Filter.pres(n)}.reduce(:|) map {|n| Net::LDAP::Filter.pres(n) }. reduce(:|)
end
end
# Filter to check group membership for posixGroups.
#
# Used by Domain#membership when posix_support_enabled? is true.
#
# entry: finds groups this Net::LDAP::Entry is a member of
# uid_attr: specifies the memberUid attribute to match with
#
# Returns a Net::LDAP::Filter or nil if no entry has no UID set.
def posix_member_filter(entry, uid_attr)
if !entry[uid_attr].empty?
entry[uid_attr].map { |uid| Net::LDAP::Filter.eq("memberUid", uid) }.
reduce(:|)
end end
end end

Просмотреть файл

@ -24,18 +24,22 @@ class FilterTest < Minitest::Test
end end
def test_member_present def test_member_present
assert_equal "(|(|(member=*)(uniqueMember=*))(memberUid=*))", @subject.member_filter.to_s assert_equal "(|(member=*)(uniqueMember=*))", @subject.member_filter.to_s
end end
def test_member_equal def test_member_equal
assert_equal "(|(|(member=#{@me})(uniqueMember=#{@me}))(memberUid=#{@uid}))", assert_equal "(|(member=#{@me})(uniqueMember=#{@me}))",
@subject.member_filter(@entry).to_s @subject.member_filter(@entry).to_s
end end
def test_member_without_uid def test_posix_member_without_uid
@entry.uid = nil @entry.uid = nil
assert_equal "(|(member=#{@me})(uniqueMember=#{@me}))", assert_nil @subject.posix_member_filter(@entry, @ldap.uid)
@subject.member_filter(@entry).to_s end
def test_posix_member_equal
assert_equal "(memberUid=#{@uid})",
@subject.posix_member_filter(@entry, @ldap.uid).to_s
end end
def test_groups_reduced def test_groups_reduced