Class: FakeLDAP::Server

Inherits:
LDAP::Server
  • Object
show all
Defined in:
lib/fakeldap.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



6
7
8
9
# File 'lib/fakeldap.rb', line 6

def initialize(options={})
  @users = {}
  super(default_options.merge(options))
end

Instance Method Details

#add_user(user, pass) ⇒ Object



11
12
13
# File 'lib/fakeldap.rb', line 11

def add_user(user, pass)
  @users[user] = pass
end

#default_optionsObject



28
29
30
31
32
33
# File 'lib/fakeldap.rb', line 28

def default_options
  {
    :operation_class => ::FakeLDAP::Operation,
    :operation_args  => [self]
  }
end

#find_users(basedn, filter) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/fakeldap.rb', line 19

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

#valid_credentials?(user, pass) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/fakeldap.rb', line 15

def valid_credentials?(user, pass)
  @users.has_key?(user) && @users[user] == pass
end