Skip to content

Commit 3f02551

Browse files
committed
Merge pull request github#51 from github/limit-attributes
Pass through search options for GitHub::Ldap::Domain#user?
2 parents e14a910 + e132db4 commit 3f02551

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/github/ldap/domain.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,15 @@ def valid_login?(login, password)
110110
# Check if a user exists based in the `uid`.
111111
#
112112
# login: is the user's login
113+
# search_options: Net::LDAP#search compatible options to pass through
113114
#
114115
# Returns the user if the login matches any `uid`.
115116
# Returns nil if there are no matches.
116-
def user?(login)
117-
search(filter: login_filter(@uid, login), size: 1).first
117+
def user?(login, search_options = {})
118+
options = search_options.merge \
119+
filter: login_filter(@uid, login),
120+
size: 1
121+
search(options).first
118122
end
119123

120124
# Check if a user can be bound with a password.

test/domain_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ def test_user_returns_every_attribute
126126
assert_equal ['user1@github.com'], user[:mail]
127127
end
128128

129+
def test_user_returns_subset_of_attributes
130+
assert entry = @domain.user?('user1', :attributes => [:cn])
131+
assert_equal [:dn, :cn], entry.attribute_names
132+
end
133+
129134
def test_auth_binds
130135
assert user = @domain.user?('user1')
131136
assert @domain.auth(user, 'passworD1'), 'Expected user to bind'

0 commit comments

Comments
 (0)