class Soar::Registry::Identity::Test::OrchestrationProvider::Staff::Uuid

Public Class Methods

new() click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 15
def initialize
  Faker::UniqueGenerator.clear
  @identity_directory_config = YAML.load_file("config/#{ENV['STAFF_DIRECTORY_CONFIG_FILE']}")
  firstname = Faker::Name.first_name
  lastname = Faker::Name.last_name
  @identity = {
    "dn" => "cn=#{firstname} #{lastname},#{@identity_directory_config['config']['base']}",
    "attributes" => {
      "cn" => "#{firstname} #{lastname}",
      "givenName" => firstname,
      "mail" => "#{firstname.downcase}.#{lastname.downcase}@hetzner.co.za",
      "objectclass" => ["inetOrgPerson", "top"],
      "sn" => lastname
    }
  }

  @identity_uuid = SecureRandom.uuid
  
end

Public Instance Methods

get_identity_attributes() click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 99
def get_identity_attributes
  begin
    @result = @idr.get_attributes(@identity_uuid)
  rescue SoarIdm::IdentityError => e
    @error = e
  end
end
get_role_attributes() click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 107
def get_role_attributes
  @result = @idr.get_attributes(@identity_uuid, @roles.nil? ? Faker::Company.unique.profession : @roles[0]['role'])
end
get_roles() click to toggle source

when

# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 95
def get_roles
  @result = @idr.get_roles(@identity_uuid) 
end
given_identity() click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 49
def given_identity
  wait_for_database do
    @identity_directory.provider.delete(@identity['dn'])
    @identity_directory.put(@identity)
    @identity_uuid = @identity_directory.search('mail', @identity['attributes']['mail'])[0]['entryuuid']
  end
end
given_identity_directory() click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 42
def given_identity_directory
  @identity_directory =  Soar::Registry::Directory.new(
    Soar::Registry::Directory::Provider::Ldap.new(@identity_directory_config['config'].map{ |k, v| [k.to_sym, v]}.to_h)
  )

end
given_identity_registry() click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 76
def given_identity_registry
  identity_provider = Soar::Registry::Identity::Provider::Staff::Uuid.new({
    identity_directory: Soar::Registry::Identity::Directory.new({
      directory: @identity_directory,
      fetch_index: 'entryuuid',
      search_index: 'mail'
    }),
    role_directory: Soar::Registry::Identity::Directory.new({
      directory: @roles_directory,
      fetch_index: ['identity_uuid', 'identity_role'],
      search_index: 'identity_uuid'
    })
  })

  @idr = Soar::Registry::Identity.new(identity_provider)
end
given_role_with_attributes() click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 65
def given_role_with_attributes
  @roles = generate_roles()
  @roles[0]['attributes'] = {
    Faker::Hacker.noun => Faker::Hacker.verb
  }
  wait_for_database do
    create_roles_database(@roles_directory_config, @roles_directory)
    populate_roles_database(@roles_directory, @roles, @identity_uuid)
  end
end
given_roles() click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 57
def given_roles
  @roles = generate_roles()
  wait_for_database do
    create_roles_database(@roles_directory_config, @roles_directory)
    populate_roles_database(@roles_directory, @roles, @identity_uuid)
  end
end
given_roles_directory() click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 35
def given_roles_directory
  @roles_directory_config = YAML.load_file("config/#{ENV['ROLES_DIRECTORY_CONFIG_FILE']}")
  @roles_directory = Soar::Registry::Directory.new(
    Soar::Registry::Directory::Provider::DynamoDb.new(@roles_directory_config['config'].map { |k, v| [k.to_sym, v]}.to_h )
  )
end
identity_attributes?() click to toggle source

then

# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 113
def identity_attributes?
  roles = {}
  @roles.each do |entry| 
    roles[entry['role']] = {}
  end if not @roles.nil?
  @result == {
    "identity_uuid" => @identity_uuid,
    "firstname" => @identity['attributes']['givenName'],
    "lastname" => @identity['attributes']['sn'],
    "email" => @identity['attributes']['mail'],
    "roles" => roles
  }
end
identity_error?() click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 156
def identity_error?
  @error.is_a?(SoarIdm::IdentityError)
end
nil?() click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 134
def nil?
  @result == nil
end
no_roles?() click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 152
def no_roles?
  @result == []
end
role_with_attributes?() click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 127
def role_with_attributes?
  role_with_attributes = {
    @roles[0]['role'] => Hashie.stringify_keys(@roles[0]['attributes'])
  }
  @result == role_with_attributes
end
role_with_empty_attributes?() click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 138
def role_with_empty_attributes?
  @result == {
    @roles[0]['role'] => {}
  }
end
roles?() click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 144
def roles?

  roles = @roles.map do |entry| 
    entry['role']
  end
  @result.sort == roles.sort
end

Private Instance Methods

create_roles_database(directory_config, directory) click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 162
def create_roles_database(directory_config, directory)
  directory.provider.recreate_table({
    name: directory_config['config']['table']['name'],
    structure: JSON.parse(File.read("lib/soar/registry/identity/test/fixtures/roles_table.json"))
  })
end
generate_roles() click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 181
def generate_roles()
  roles = [{
    'role' => Faker::Company.unique.profession
  }, {
    'role' => Faker::Company.unique.profession
  }, {
    'role' => Faker::Company.unique.profession
  }, {
    'role' => Faker::Company.unique.profession
  }]
  roles[0]['source'] = "#{Soar::Authentication::IdentityUuidTranslator::Provider::Staff::PREFIX}#{@identity_uuid}"
  return roles
end
populate_roles_database(roles_directory, roles, identity_uuid) click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 169
def populate_roles_database(roles_directory, roles, identity_uuid)
    roles.each do |role|
      entry = {
        "identity_uuid" => identity_uuid,
        "identity_role" => role['role']
      }
      entry['identity_source'] = role['source'] if role.key?('source')
      entry['identity_role_attributes'] = role['attributes'] if role.key?('attributes')
      roles_directory.put(entry)
    end
end
wait_for_database() { || ... } click to toggle source
# File lib/soar/registry/identity/test/orchestration_provider/staff/uuid.rb, line 195
def wait_for_database
  return 10.times do |i|
    begin
      break yield
    rescue Soar::Registry::Directory::Error::NetworkingError, Net::LDAP::Error => e
      sleep(10)
    end
  end
end