Commit 394746ff authored by Sanad Liaquat's avatar Sanad Liaquat

Some refactoring done

parent d85adbac
...@@ -2,115 +2,114 @@ ...@@ -2,115 +2,114 @@
module QA module QA
context 'Manage', :orchestrated, :ldap_tls, :ldap_no_tls do context 'Manage', :orchestrated, :ldap_tls, :ldap_no_tls do
it 'Has LDAP user synced using group cn method' do describe 'LDAP Group sync' do
users = [ before(:all) do
{ users = [
name: 'ENG User 2', {
username: 'enguser2', name: 'ENG User 2',
email: 'enguser2@example.org', username: 'enguser2',
provider: 'ldapmain', email: 'enguser2@example.org',
extern_uid: 'uid=enguser2,ou=people,ou=global groups,dc=example,dc=org' provider: 'ldapmain',
}, extern_uid: 'uid=enguser2,ou=people,ou=global groups,dc=example,dc=org'
{ },
name: 'ENG User 3', {
username: 'enguser3', name: 'ENG User 3',
email: 'enguser3@example.org', username: 'enguser3',
provider: 'ldapmain', email: 'enguser3@example.org',
extern_uid: 'uid=enguser3,ou=people,ou=global groups,dc=example,dc=org' provider: 'ldapmain',
} extern_uid: 'uid=enguser3,ou=people,ou=global groups,dc=example,dc=org'
] },
{
create_users_via_api(users) name: 'HR User 2',
username: 'hruser2',
Runtime::Browser.visit(:gitlab, Page::Main::Login) email: 'hruser2@example.org',
create_group_with_user_via_api(user: 'enguser1', group_name: 'Synched-engineering-group') provider: 'ldapmain',
extern_uid: 'uid=hruser2,ou=people,ou=global groups,dc=example,dc=org'
EE::Page::Group::Menu.perform(&:go_to_ldap_sync_settings) },
{
EE::Page::Group::Settings::LDAPSync.perform do |page| name: 'HR User 3',
page.set_sync_method('LDAP Group cn') username: 'hruser3',
page.set_group_cn('Engineering') email: 'hruser3@example.org',
page.click_add_sync_button provider: 'ldapmain',
extern_uid: 'uid=hruser3,ou=people,ou=global groups,dc=example,dc=org'
}
]
create_users_via_api(users)
end end
EE::Page::Group::Menu.perform(&:go_to_members) it 'Has LDAP user synced using group cn method' do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
verify_users_synched(['ENG User 2', 'ENG User 3']) create_group_with_user_via_api(user: 'enguser1', group_name: 'Synched-engineering-group')
end
EE::Page::Group::Menu.perform(&:go_to_ldap_sync_settings)
EE::Page::Group::Settings::LDAPSync.perform do |page|
page.set_sync_method('LDAP Group cn')
page.set_group_cn('Engineering')
page.click_add_sync_button
end
EE::Page::Group::Menu.perform(&:go_to_members)
it 'Has LDAP user synced using user filter method' do verify_users_synched(['ENG User 2', 'ENG User 3'])
users = [
{
name: 'HR User 2',
username: 'hruser2',
email: 'hruser2@example.org',
provider: 'ldapmain',
extern_uid: 'uid=hruser2,ou=people,ou=global groups,dc=example,dc=org'
},
{
name: 'HR User 3',
username: 'hruser3',
email: 'hruser3@example.org',
provider: 'ldapmain',
extern_uid: 'uid=hruser3,ou=people,ou=global groups,dc=example,dc=org'
}
]
create_users_via_api(users)
Runtime::Browser.visit(:gitlab, Page::Main::Login)
create_group_with_user_via_api(user: 'hruser1', group_name: 'Synched-human-resources-group')
EE::Page::Group::Menu.perform(&:go_to_ldap_sync_settings)
EE::Page::Group::Settings::LDAPSync.perform do |page|
page.set_user_filter('(&(objectClass=person)(cn=HR*))')
page.click_add_sync_button
end end
EE::Page::Group::Menu.perform(&:go_to_members) it 'Has LDAP user synced using user filter method' do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
verify_users_synched(['HR User 2', 'HR User 3']) create_group_with_user_via_api(user: 'hruser1', group_name: 'Synched-human-resources-group')
end
EE::Page::Group::Menu.perform(&:go_to_ldap_sync_settings)
def create_users_via_api(users) EE::Page::Group::Settings::LDAPSync.perform do |page|
users.each do |user| page.set_user_filter('(&(objectClass=person)(cn=HR*))')
Resource::User.fabricate_via_api! do |resource| page.click_add_sync_button
resource.username = user[:username]
resource.name = user[:name]
resource.email = user[:email]
resource.extern_uid = user[:extern_uid]
resource.provider = user[:provider]
end end
end
end
def create_group_with_user_via_api(user: nil, group_name: nil) EE::Page::Group::Menu.perform(&:go_to_members)
Page::Main::Login.perform do |login_page|
login_page.sign_in_using_ldap_credentials(username: user, password: 'password') verify_users_synched(['HR User 2', 'HR User 3'])
end end
Page::Main::Menu.perform do |menu| def create_users_via_api(users)
expect(menu).to have_personal_area users.each do |user|
Resource::User.fabricate_via_api! do |resource|
resource.username = user[:username]
resource.name = user[:name]
resource.email = user[:email]
resource.extern_uid = user[:extern_uid]
resource.provider = user[:provider]
end
end
end end
Runtime::Env.personal_access_token = Resource::PersonalAccessToken.fabricate!.access_token def create_group_with_user_via_api(user: nil, group_name: nil)
Page::Main::Login.perform do |login_page|
login_page.sign_in_using_ldap_credentials(username: user, password: 'password')
end
group = Resource::Sandbox.fabricate_via_api! do |resource| Page::Main::Menu.perform do |menu|
resource.path = "#{group_name}-#{SecureRandom.hex(4)}" expect(menu).to have_personal_area
end end
group.visit! Runtime::Env.personal_access_token = Resource::PersonalAccessToken.fabricate!.access_token
end
group = Resource::Sandbox.fabricate_via_api! do |resource|
resource.path = "#{group_name}-#{SecureRandom.hex(4)}"
end
group.visit!
end
def verify_users_synched(expected_users) def verify_users_synched(expected_users)
EE::Page::Group::Members.perform do |page| EE::Page::Group::Members.perform do |page|
page.click_sync_now page.click_sync_now
users_synchronised = page.with_retry(reload: true) do users_synchronised = page.with_retry(reload: true) do
expected_users.map { |user| page.has_content?(user) }.reduce(true) { |a, b| a && b } expected_users.map { |user| page.has_content?(user) }.reduce(true) { |a, b| a && b }
end
expect(users_synchronised).to be_truthy
end end
expect(users_synchronised).to be_truthy
end 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