lib/fakeldap.rb in fakeldap-0.0.0 vs lib/fakeldap.rb in fakeldap-0.0.1

- old
+ new

@@ -14,10 +14,19 @@ def valid_credentials?(user, pass) @users.has_key?(user) && @users[user] == pass end + def find_users(basedn, filter) + basedn_regex = /#{Regexp.escape(basedn)}$/ + filter_regex = /^#{filter[1]}=#{filter[3]}$/ + + @users.keys.select { |dn| + dn =~ basedn_regex && dn.split(",").grep(filter_regex).any? + } + end + def default_options { :operation_class => ::FakeLDAP::Operation, :operation_args => [self] } @@ -37,9 +46,20 @@ end unless @server.valid_credentials?(dn, password) raise LDAP::ResultError::InvalidCredentials, "Invalid credentials" + end + end + + def search(basedn, scope, deref, filter, attrs=nil) + unless filter.first == :eq + raise LDAP::ResultError::UnwillingToPerform, + "Only equality matches are supported" + end + + @server.find_users(basedn, filter).each do |dn| + send_SearchResultEntry(dn, {}) end end end end