Skip to content

Commit 80cf8dc

Browse files
committed
Merge pull request #37 from github/member_filter-without-uid
Handle member_filter for entry without a UID set
2 parents 29f817e + ba19f3f commit 80cf8dc

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

github-ldap.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Gem::Specification.new do |spec|
44
spec.name = "github-ldap"
5-
spec.version = "1.3.0"
5+
spec.version = "1.3.1"
66
spec.authors = ["David Calavera"]
77
spec.email = ["david.calavera@gmail.com"]
88
spec.description = %q{Ldap authentication for humans}

lib/github/ldap/filter.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,17 @@ def group_filter(group_names)
2626
# Returns a Net::LDAP::Filter.
2727
def member_filter(entry = nil, uid_attr = @ldap.uid)
2828
if entry
29-
MEMBERSHIP_NAMES.map {|n| Net::LDAP::Filter.eq(n, entry.dn) }.
30-
reduce(:|) |
31-
entry[uid_attr]. map { |uid| Net::LDAP::Filter.eq("memberUid", uid) }.
32-
reduce(:|)
29+
filter =
30+
MEMBERSHIP_NAMES. map {|n| Net::LDAP::Filter.eq(n, entry.dn) }.
31+
reduce(:|)
32+
33+
if !entry[uid_attr].empty?
34+
filter |=
35+
entry[uid_attr].map { |uid| Net::LDAP::Filter.eq("memberUid", uid) }.
36+
reduce(:|)
37+
end
38+
39+
filter
3340
else
3441
(MEMBERSHIP_NAMES + %w(memberUid)).
3542
map {|n| Net::LDAP::Filter.pres(n)}.reduce(:|)

test/filter_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ def test_member_equal
3232
@subject.member_filter(@entry).to_s
3333
end
3434

35+
def test_member_without_uid
36+
@entry.uid = nil
37+
assert_equal "(|(member=#{@me})(uniqueMember=#{@me}))",
38+
@subject.member_filter(@entry).to_s
39+
end
40+
3541
def test_groups_reduced
3642
assert_equal "(|(cn=Enterprise)(cn=People))",
3743
@subject.group_filter(%w(Enterprise People)).to_s

0 commit comments

Comments
 (0)