test/ldap_test.rb in github-ldap-1.0.1 vs test/ldap_test.rb in github-ldap-1.0.2
- old
+ new
@@ -33,38 +33,31 @@
assert !@ldap.valid_login?('bar', 'foo'),
"Login `bar` expected to be invalid with password `foo`"
end
def test_groups_in_server
- options = @options.merge(:user_groups => %w(Enterprise People))
- assert_equal 2, GitHub::Ldap.new(options).groups.size
+ assert_equal 2, @ldap.groups(%w(Enterprise People)).size
end
def test_user_in_group
- options = @options.merge(:user_groups => %w(Enterprise People))
- ldap = GitHub::Ldap.new(options)
- user = ldap.valid_login?('calavera', 'secret')
+ user = @ldap.valid_login?('calavera', 'secret')
- assert ldap.groups_contain_user?(user.dn),
+ assert @ldap.is_member?(user.dn, %w(Enterprise People)),
"Expected `Enterprise` or `Poeple` to include the member `#{user.dn}`"
end
def test_user_not_in_different_group
- options = @options.merge(:user_groups => %w(People))
- ldap = GitHub::Ldap.new(options)
- user = ldap.valid_login?('calavera', 'secret')
+ user = @ldap.valid_login?('calavera', 'secret')
- assert !ldap.groups_contain_user?(user.dn),
+ assert !@ldap.is_member?(user.dn, %w(People)),
"Expected `Poeple` not to include the member `#{user.dn}`"
end
def test_user_without_group
- options = @options.merge(:user_groups => %w(People))
- ldap = GitHub::Ldap.new(options)
- user = ldap.valid_login?('ldaptest', 'secret')
+ user = @ldap.valid_login?('ldaptest', 'secret')
- assert !ldap.groups_contain_user?(user.dn),
+ assert !@ldap.is_member?(user.dn, %w(People)),
"Expected `Poeple` not to include the member `#{user.dn}`"
end
def test_authenticate_doesnt_return_invalid_users
user = @ldap.authenticate!('calavera', 'secret')
@@ -75,22 +68,17 @@
assert !@ldap.authenticate!('calavera', 'foo'),
"Expected `authenticate!` to not return an invalid user"
end
def test_authenticate_check_valid_user_and_groups
- options = @options.merge(:user_groups => %w(Enterprise People))
- ldap = GitHub::Ldap.new(options)
- user = ldap.authenticate!('calavera', 'secret')
+ user = @ldap.authenticate!('calavera', 'secret', %w(Enterprise People))
assert_equal 'uid=calavera,dc=github,dc=com', user.dn
end
def test_authenticate_doesnt_return_valid_users_in_different_groups
- options = @options.merge(:user_groups => %w(People))
- ldap = GitHub::Ldap.new(options)
-
- assert !ldap.authenticate!('calavera', 'secret'),
+ assert !@ldap.authenticate!('calavera', 'secret', %w(People)),
"Expected `authenticate!` to not return an user"
end
def test_simple_tls
assert_equal :simple_tls, @ldap.check_encryption(:ssl)
@@ -98,7 +86,19 @@
end
def test_start_tls
assert_equal :start_tls, @ldap.check_encryption(:tls)
assert_equal :start_tls, @ldap.check_encryption(:start_tls)
+ end
+
+ def test_membership_empty_for_non_members
+ assert @ldap.membership('uid=calavera,dc=github,dc=com', %w(People)).empty?,
+ "Expected `calavera` not to be a member of `People`."
+ end
+
+ def test_membership_groups_for_members
+ groups = @ldap.membership('uid=calavera,dc=github,dc=com', %w(Enterprise People))
+
+ assert_equal 1, groups.size
+ assert_equal 'cn=Enterprise,ou=Group,dc=github,dc=com', groups.first.dn
end
end