Skip to content

Instantly share code, notes, and snippets.

@krobertson
Created January 10, 2009 01:34
Show Gist options
  • Save krobertson/45343 to your computer and use it in GitHub Desktop.
Save krobertson/45343 to your computer and use it in GitHub Desktop.
fakeldap - fake data generator for LDAP
#
# Ugly little script I used when I needed to generate an LDAP DB with 100k sample users
#
require 'rubygems'
require 'faker'
require 'active_ldap'
ActiveLdap::Base.establish_connection(
:host => '10.0.0.8',
:port => 389,
:base => 'dc=csldaptest,dc=local',
:logger => Logger.new('ldap.log'),
:bind_dn => 'cn=Manager,dc=csldaptest,dc=local',
:password_block => Proc.new { 'secret' },
:allow_anonymous => false,
:try_sasl => false
)
class Person < ActiveLdap::Base
ldap_mapping :classes => ['organizationalPerson'], :dn_attribute => 'cn', :prefix => ''
end
puts "Finding out how many people already exist... this will be slow if alot"
people = Person.find(:all, '*').size
puts "Done, #{people} currently exist"
def process_person
p = Person.new
p.sn = Faker::Name.last_name
p.cn = "#{Faker::Name.first_name} #{p.sn}"
p.title = Faker::Lorem.words(2)
p.street = Faker::Address.street_address
p.postalAddress = Faker::Address.city
p.st = Faker::Address.us_state_abbr
p.postalCode = Faker::Address.zip_code
p.mail = "#{p.cn.downcase.gsub(' ', '_')}@#{Faker::Internet.domain_name}"
p.telephoneNumber = Faker::PhoneNumber.phone_number
begin
success = p.save
success
rescue
false
end
end
while(people < 100000)
if process_person
people += 1
puts "success, created ##{people}"
else
puts "oops, failed"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment