Commit 2424df1f authored by James Lopez's avatar James Lopez

add more specs, fixed some errors

parent 25059dd3
...@@ -230,12 +230,20 @@ class Group < Namespace ...@@ -230,12 +230,20 @@ class Group < Namespace
ldap_group_links.first.try(:cn) ldap_group_links.first.try(:cn)
end end
def ldap_filter
ldap_group_links.first.try(:filter)
end
def ldap_access def ldap_access
ldap_group_links.first.try(:group_access) ldap_group_links.first.try(:group_access)
end end
def ldap_cn_or_filter_present?
ldap_cn.present? || ldap_filter.present?
end
def ldap_synced? def ldap_synced?
Gitlab.config.ldap.enabled && ldap_cn.present? Gitlab.config.ldap.enabled && ldap_cn_or_filter_present?
end end
def post_create_hook def post_create_hook
......
...@@ -8,7 +8,7 @@ class LdapGroupLink < ActiveRecord::Base ...@@ -8,7 +8,7 @@ class LdapGroupLink < ActiveRecord::Base
validates :cn, uniqueness: { scope: [:group_id, :provider] }, unless: :filter validates :cn, uniqueness: { scope: [:group_id, :provider] }, unless: :filter
validates :filter, :group_access, :group_id, presence: true, unless: :cn validates :filter, :group_access, :group_id, presence: true, unless: :cn
validates :filter, uniqueness: { scope: [:group_id, :provider] }, unless: :cn validates :filter, uniqueness: { scope: [:group_id, :provider] }, unless: :cn
validates :filter, ldap_filter: true, if: :filter validates :filter, ldap_filter: true, unless: :cn
validates :group_access, inclusion: { in: Gitlab::Access.all_values } validates :group_access, inclusion: { in: Gitlab::Access.all_values }
validates :provider, presence: true validates :provider, presence: true
......
...@@ -27,20 +27,34 @@ FactoryGirl.define do ...@@ -27,20 +27,34 @@ FactoryGirl.define do
end end
end end
factory :group_with_ldap_group_link do factory :group_with_ldap do
transient do transient do
cn 'group1' cn 'group1'
group_access Gitlab::Access::GUEST group_access Gitlab::Access::GUEST
provider 'ldapmain' provider 'ldapmain'
end end
after(:create) do |group, evaluator| factory :group_with_ldap_group_link do
group.ldap_group_links << create( after(:create) do |group, evaluator|
:ldap_group_link, group.ldap_group_links << create(
cn: evaluator.cn, :ldap_group_link,
group_access: evaluator.group_access, cn: evaluator.cn,
provider: evaluator.provider group_access: evaluator.group_access,
) provider: evaluator.provider
)
end
end
factory :group_with_ldap_group_filter_link do
after(:create) do |group, evaluator|
group.ldap_group_links << create(
:ldap_group_link,
filter: '(a=b)',
cn: nil,
group_access: evaluator.group_access,
provider: evaluator.provider
)
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment