Sha256: 85d6f8fc0d3e170bb7986265380023add3d8488bd9d015474429d397602674fb

Contents?: true

Size: 1.67 KB

Versions: 5

Compression:

Stored size: 1.67 KB

Contents

require 'al-test-utils'

class TestBind < Test::Unit::TestCase
  include AlTestUtils::Config

  def setup
    super
  end

  def teardown
    ActiveLdap::Base.clear_active_connections!
    super
  end

  def test_anonymous
    assert(!ActiveLdap::Base.connected?)
    assert_nothing_raised do
      config = ActiveLdap::Base.configurations[LDAP_ENV].symbolize_keys
      config = ActiveLdap::Base.prepare_configuration(config)
      config.delete(:bind_dn)
      config[:allow_anonymous] = true
      connect(config)
    end
    assert(ActiveLdap::Base.connected?,
           "Checking is the connection was established.")
  end

  def test_bind
    assert(!ActiveLdap::Base.connected?)
    config = ActiveLdap::Base.configurations[LDAP_ENV].symbolize_keys
    config = ActiveLdap::Base.prepare_configuration(config)
    if config[:bind_dn].nil?
      puts "pass this test for no user configuration"
      return
    end
    assert_nothing_raised do
      config[:allow_anonymous] = false
      connect(config)
    end
    assert(ActiveLdap::Base.connected?,
           "Checking is the connection was established.")
    assert(ActiveLdap::Base.connection.bound?)
  end

  def test_failed_bind
    assert(!ActiveLdap::Base.connected?)
    assert_raises(ActiveLdap::AuthenticationError) do
      config = ActiveLdap::Base.configurations[LDAP_ENV].symbolize_keys
      config = ActiveLdap::Base.prepare_configuration(config)
      config.delete(:bind_dn)
      config[:allow_anonymous] = false
      connect(config)
    end
    assert(!ActiveLdap::Base.connection.bound?)
  end

  private
  def connect(config)
    ActiveLdap::Base.establish_connection(config)
    ActiveLdap::Base.connection.connect
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activeldap-1.0.0 test/test_bind.rb
activeldap-0.10.0 test/test_bind.rb
activeldap-0.9.0 test/test_bind.rb
activeldap-1.0.2 test/test_bind.rb
activeldap-1.0.1 test/test_bind.rb