cirandas.net

ref: master

plugins/ldap/test/test_helper.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
require 'test_helper'
require_relative '../../../test/api/test_helper'

def load_ldap_config
  begin
    YAML.load_file(File.dirname(__FILE__) + '/../fixtures/ldap.yml')
  rescue Errno::ENOENT => e
    # There is no config file
    return nil
  end
end

def ldap_configured?
  ldap_config = load_ldap_config
  begin
    test_ldap = Net::LDAP.new(:host => ldap_config['server']['host'], :port => ldap_config['server']['port'])
    return test_ldap.bind
  rescue Exception => e
    #LDAP is not listening
    return nil
  end
end

LDAP_SERVER_ERROR_MESSAGE = "\nWARNING: LDAP test server is not configured properly. Please see the file fixtures/ldap.yml on ldap plugin\n\n"