<commit_before>require_relative 'test_helper'

if !INTEGRATION
  puts "Skipping integration tests..."
else
  class TestLDAPIntegration < Test::Unit::TestCase
    def setup
      @service = MockInstrumentationService.new
      @ldap = Net::LDAP.new \
        host:           'localhost',
        port:           389,
        admin_user:     'uid=admin,dc=rubyldap,dc=com',
        admin_password: '<PASSWORD>',
        search_domains: %w(dc=rubyldap,dc=com),
        uid:            'uid',
        instrumentation_service: @service
    end

    def test_bind_success
      assert @ldap.bind(method: :simple, username: "uid=user1,ou=People,dc=rubyldap,dc=com", password: "<PASSWORD>"), @ldap.get_operation_result.inspect
    end

    def test_bind_success_anonymous
      assert @ldap.bind(method: :simple, username: "uid=user1,ou=People,dc=rubyldap,dc=com", password: ""), @ldap.get_operation_result.inspect
    end

    def test_bind_fail
      refute @ldap.bind(method: :simple, username: "uid=user1,ou=People,dc=rubyldap,dc=com", password: "<PASSWORD>"), @ldap.get_operation_result.inspect
    end
  end
end<commit_msg>Expect anonymous auth to fail<commit_after>require_relative 'test_helper'

if !INTEGRATION
  puts "Skipping integration tests..."
else
  class TestLDAPIntegration < Test::Unit::TestCase
    def setup
      @service = MockInstrumentationService.new
      @ldap = Net::LDAP.new \
        host:           'localhost',
        port:           389,
        admin_user:     'uid=admin,dc=rubyldap,dc=com',
        admin_password: '<PASSWORD>',
        search_domains: %w(dc=rubyldap,dc=com),
        uid:            'uid',
        instrumentation_service: @service
    end

    def test_bind_success
      assert @ldap.bind(method: :simple, username: "uid=user1,ou=People,dc=rubyldap,dc=com", password: "<PASSWORD>"), @ldap.get_operation_result.inspect
    end

    def test_bind_anonymous_fail
      refute @ldap.bind(method: :simple, username: "uid=user1,ou=People,dc=rubyldap,dc=com", password: ""), @ldap.get_operation_result.inspect

      result = @ldap.get_operation_result
      assert_equal 53, result.code
      assert_equal "Unwilling to perform", result.message
      assert_equal "unauthenticated bind (DN with no password) disallowed",
        result.error_message
      assert_equal "", result.matched_dn
    end

    def test_bind_fail
      refute @ldap.bind(method: :simple, username: "uid=user1,ou=People,dc=rubyldap,dc=com", password: "<PASSWORD>"), @ldap.get_operation_result.inspect
    end
  end
end
{'fraction_non_alphanumeric': 0.11706740244383129, 'fraction_numerical': 0.005518328734726055, 'mean_word_length': 3.4526315789473685, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1970665', 'n_tokens_mistral': 841, 'n_tokens_neox': 824, 'n_words': 158}