class Gitlab::QA::Component::LDAP

def copy_fixtures

Returns:
  • (void) -
def copy_fixtures
  FileUtils.cp_r(FIXTURE_PATH, working_dir_tmp_fixture_path)
end

def instance

def instance
  raise 'Please provide a block!' unless block_given?
  super
end

def name

def name
  @name ||= "openldap-#{SecureRandom.hex(4)}"
end

def password

def password
  LDAP_PASSWORD
end

def prepare

def prepare
  copy_fixtures
  @volumes["#{working_dir_tmp_fixture_path}/ldap"] = BOOTSTRAP_LDIF
  super
end

def set_gitlab_credentials

def set_gitlab_credentials
  ::Gitlab::QA::Runtime::Env.ldap_username = username
  ::Gitlab::QA::Runtime::Env.ldap_password = password
end

def start

rubocop:disable Metrics/AbcSize
def start
  # copy-service needed for bootstraping LDAP user:
  # https://github.com/osixia/docker-openldap#seed-ldap-database-with-ldif
  docker.run(image: image, tag: tag, args: ['--copy-service']) do |command|
    command << '-d '
    command << "--name #{name}"
    command << "--net #{network}"
    command << "--hostname #{hostname}"
    @volumes.to_h.each do |to, from|
      command.volume(to, from, 'Z')
    end
    @environment.to_h.each do |key, value|
      command.env(key, value)
    end
    @network_aliases.to_a.each do |network_alias|
      command << "--network-alias #{network_alias}"
    end
  end
end

def teardown!

def teardown!
  FileUtils.rm_rf(working_dir_tmp_fixture_path)
  super
end

def tls=(status)

LDAP_TLS is true by default
def tls=(status)
  if status
    @environment['LDAP_TLS_CRT_FILENAME'] = "#{hostname}.crt"
    @environment['LDAP_TLS_KEY_FILENAME'] = "#{hostname}.key"
    @environment['LDAP_TLS_ENFORCE'] = 'true'
    @environment['LDAP_TLS_VERIFY_CLIENT'] = 'never'
  else
    @environment['LDAP_TLS'] = 'false'
  end
end

def username

def username
  LDAP_USER
end

def working_dir_tmp_fixture_path

Returns:
  • (String) -
def working_dir_tmp_fixture_path
  @local_fixture_path ||= Dir.mktmpdir('ldap', FileUtils.mkdir_p("#{Dir.pwd}/tmp"))
end