Skip to content

Instantly share code, notes, and snippets.

@DanCoughlin
Created July 27, 2012 18:32
Show Gist options
  • Save DanCoughlin/3189642 to your computer and use it in GitHub Desktop.
Save DanCoughlin/3189642 to your computer and use it in GitHub Desktop.
rspec tests for hydra-ldap
require 'spec_helper'require 'ladle'
describe 'Ldap service' do
before(:all) do
@ldap_server = Ladle::Server.new( :port => 3897,
:domain => "dc=example,dc=org", :allow_anonymous => true,
:verbose => true,
:ldif => 'default.ldif'
).start
end
after(:all) do
@ldap_server.stop if @ldap_server
end
describe "Querying for users and attribute values"
it "should return true dd945 exists" do
filter = Net::LDAP::Filter.eq('uid', 'dd945')
Hydra::LDAP.does_user_exist?(filter).should be_true
end
it "should return false abc123 does not exist" do
filter = Net::LDAP::Filter.eq('uid', 'abc123')
Hydra::LDAP.does_user_exist?(filter).should_not be_true
end
it "should return true dd945 is unique user" do
filter = Net::LDAP::Filter.eq('uid', 'dd945')
Hydra::LDAP.is_user_unique?(filter).should be_true
end
it "should return user values for dd945" do
filter = Net::LDAP::Filter.eq('uid', 'dd945')
Hydra::LDAP.get_user(filter, ['givenName']).first[:givenname] == 'Dorothy'
end
describe "Query groups for group info"
it "should find a group and map the result" do
group_code = 'Group1'
filter = Net::LDAP::Filter.construct("(cn=#{group_code})")
Hydra::LDAP.find_group(group_code, filter, ['cn']){ |result| result.first[:cn].first }.downcase.should == 'group1'
end
it "should have description, users, owners of a group" do
group_code = 'Group1'
filter = Net::LDAP::Filter.construct("(cn=#{group_code})")
Hydra::LDAP.title_of_group(group_code, filter){ |result| result.first[:description].first }.should == 'Test Group1'
Hydra::LDAP.users_for_group(group_code, filter, ['uniquemember']){ |result| result.first[:uniquemember].map{ |r| r.sub(/^uid=/, '').sub(/,ou=people,dc=examp
le,dc=org/, '') }}.should == ['zz882', 'yy423', 'ww369']
Hydra::LDAP.owner_for_group(group_code, filter, ['owner']) { |result| result.first[:owner].map{ |r| r.sub(/^uid=/, '').sub(/,ou=people,dc=example,dc=org/, '') }}.should == ['xx396']
end
describe "Managing Groups"
before do
attrs = {
:cn => 'TCG',
:objectclass => 'groupofuniquenames',
:description => 'Test Create Group',
:owner => 'uid=quentin',
:uniquemember => ['uid=kacey', 'uid=larry', 'uid=ursula']
}
Hydra::LDAP.create_group('justin1', attrs).should be_true
end
after do
Hydra::LDAP.delete_group('justin1').should be_true
end
it "should return the group" do
filter = Net::LDAP::Filter.construct("(owner=uid=xx396,ou=people,dc=example,dc=org)")
filter = Net::LDAP::Filter.construct("(owner=uid=quentin,ou=people,dc=example,dc=org)")
group_code = 'Group1'
f = Net::LDAP::Filter.construct("(cn=#{group_code})")
#Hydra::LDAP.groups_owned_by_user('quentin').should == ['justin1', 'justin2']
puts "title of group call"
Hydra::LDAP.title_of_group(group_code, f){ |result| puts result.inspect }
puts "groups owned by users?"
Hydra::LDAP.groups_owned_by_user(filter, ['owner', 'cn']){ |result| puts result.inspect } # .should == ['justin1', 'justin2']
end
end
# describe "#groups_owned_by_user" do
# before do
# Hydra::LDAP.create_group('justin2', 'Test Group', 'quentin', ['kacey', 'larry']).should be_true
# Hydra::LDAP.create_group('justin3', 'Test Group', 'theresa', ['kacey', 'larry']).should be_true
# end
# after do
# Hydra::LDAP.delete_group('justin2').should be_true
# Hydra::LDAP.delete_group('justin3').should be_true
# end
# it "should return the list" do
# Hydra::LDAP.groups_owned_by_user('quentin').should == ['justin1', 'justin2']
# end
# end
#
# describe "#adding_members" do
# it "should have users and owners of a group" do
# Hydra::LDAP.add_users_to_group('justin1', ['theresa', 'penelope']).should be_true
# end
# end
#
# describe "#removing_members" do
# it "should remove users from the group" do
# Hydra::LDAP.remove_users_from_group('justin1', ['kacey', 'larry']).should be_true
# Hydra::LDAP.users_for_group('justin1').should == ['ursula']
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment