Commit b52f27a9 authored by Sanad Liaquat's avatar Sanad Liaquat

Add user to subgroup instead of sandbox. Some cleanup.

parent 1f5db25c
exit
post Runtime::API::Request.new(api_client, "/groups/#{group_path}/members").url, { user_id: parse_body(response).first[:id], access_level: '50' }.
group_path
user
parse_body(response).first[:id]
response
...@@ -51,6 +51,10 @@ module QA ...@@ -51,6 +51,10 @@ module QA
"/groups/#{CGI.escape("#{sandbox.path}/#{path}")}" "/groups/#{CGI.escape("#{sandbox.path}/#{path}")}"
end end
def api_members_path
"#{api_get_path}/members"
end
def api_post_path def api_post_path
'/groups' '/groups'
end end
......
...@@ -7,7 +7,7 @@ module QA ...@@ -7,7 +7,7 @@ module QA
# creating it if it doesn't yet exist. # creating it if it doesn't yet exist.
# #
class Sandbox < Base class Sandbox < Base
attr_accessor :path attr_reader :path
attribute :id attribute :id
......
...@@ -6,77 +6,109 @@ module QA ...@@ -6,77 +6,109 @@ module QA
include Support::Api include Support::Api
before(:all) do before(:all) do
users = [ create_admin_personal_access_token
{
name: 'ENG User 2',
username: 'enguser2',
email: 'enguser2@example.org',
provider: 'ldapmain',
extern_uid: 'uid=enguser2,ou=people,ou=global groups,dc=example,dc=org'
},
{
name: 'ENG User 3',
username: 'enguser3',
email: 'enguser3@example.org',
provider: 'ldapmain',
extern_uid: 'uid=enguser3,ou=people,ou=global groups,dc=example,dc=org'
},
{
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)
end end
it 'Has LDAP user synced using group cn method' do context 'using group cn method' do
Runtime::Browser.visit(:gitlab, Page::Main::Login) let(:ldap_users) do
[
{
name: 'ENG User 1',
username: 'enguser1',
email: 'enguser1@example.org',
provider: 'ldapmain',
extern_uid: 'uid=enguser1,ou=people,ou=global groups,dc=example,dc=org'
},
{
name: 'ENG User 2',
username: 'enguser2',
email: 'enguser2@example.org',
provider: 'ldapmain',
extern_uid: 'uid=enguser2,ou=people,ou=global groups,dc=example,dc=org'
},
{
name: 'ENG User 3',
username: 'enguser3',
email: 'enguser3@example.org',
provider: 'ldapmain',
extern_uid: 'uid=enguser3,ou=people,ou=global groups,dc=example,dc=org'
}
]
end
let(:owner_user) { 'enguser1' }
let(:sync_users) { ['ENG User 2', 'ENG User 3'] }
sigin_in_and_create_group_with_user_via_api(user: 'enguser1', group_name: 'Synched-engineering-group') before do
create_users_via_api(ldap_users)
group = create_group_and_add_user_via_api(owner_user, 'Synched-engineering-group')
signin_and_visit_group_as_user(owner_user, group)
EE::Page::Group::Menu.perform(&:go_to_ldap_sync_settings) EE::Page::Group::Menu.perform(&:go_to_ldap_sync_settings)
EE::Page::Group::Settings::LDAPSync.perform do |page| EE::Page::Group::Settings::LDAPSync.perform do |page|
page.set_sync_method('LDAP Group cn') page.set_sync_method('LDAP Group cn')
page.set_group_cn('Engineering') page.set_group_cn('Engineering')
page.click_add_sync_button page.click_add_sync_button
end end
EE::Page::Group::Menu.perform(&:go_to_members) EE::Page::Group::Menu.perform(&:go_to_members)
end
verify_users_synced(['ENG User 2', 'ENG User 3']) it 'has LDAP users synced' do
verify_users_synced(sync_users)
end
end end
it 'Has LDAP user synced using user filter method' do context 'user filter method' do
Runtime::Browser.visit(:gitlab, Page::Main::Login) let(:ldap_users) do
[
{
name: 'HR User 1',
username: 'hruser1',
email: 'hruser1@example.org',
provider: 'ldapmain',
extern_uid: 'uid=hruser1,ou=people,ou=global groups,dc=example,dc=org'
},
{
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'
}
]
end
let(:owner_user) { 'hruser1' }
let(:sync_users) { ['HR User 2', 'HR User 3'] }
sigin_in_and_create_group_with_user_via_api(user: 'hruser1', group_name: 'Synched-human-resources-group') before do
create_users_via_api(ldap_users)
group = create_group_and_add_user_via_api(owner_user, 'Synched-human-resources-group')
signin_and_visit_group_as_user(owner_user, group)
EE::Page::Group::Menu.perform(&:go_to_ldap_sync_settings) EE::Page::Group::Menu.perform(&:go_to_ldap_sync_settings)
EE::Page::Group::Settings::LDAPSync.perform do |page| EE::Page::Group::Settings::LDAPSync.perform do |page|
page.set_user_filter('(&(objectClass=person)(cn=HR*))') page.set_user_filter('(&(objectClass=person)(cn=HR*))')
page.click_add_sync_button page.click_add_sync_button
end end
EE::Page::Group::Menu.perform(&:go_to_members) EE::Page::Group::Menu.perform(&:go_to_members)
end
verify_users_synced(['HR User 2', 'HR User 3']) it 'has LDAP users synced' do
verify_users_synced(sync_users)
end
end end
def create_users_via_api(users) def create_users_via_api(users)
create_admin_personal_access_token
users.each do |user| users.each do |user|
Resource::User.fabricate_via_api! do |resource| Resource::User.fabricate_via_api! do |resource|
resource.username = user[:username] resource.username = user[:username]
...@@ -88,12 +120,10 @@ module QA ...@@ -88,12 +120,10 @@ module QA
end end
end end
def add_user_to_sandbox_group_via_api(user) def add_user_to_group_via_api(user, group)
sandbox_group_path = Resource::Sandbox.fabricate_via_api!.path api_client = Runtime::API::Client.new(:gitlab)
api_client = Runtime::API::Client.new(:gitlab, personal_access_token: Runtime::Env.personal_access_token)
response = get Runtime::API::Request.new(api_client, "/users?username=#{user}").url response = get Runtime::API::Request.new(api_client, "/users?username=#{user}").url
post Runtime::API::Request.new(api_client, group.api_members_path).url, { user_id: parse_body(response).first[:id], access_level: '50' }
post Runtime::API::Request.new(api_client, "/groups/#{sandbox_group_path}/members").url, { user_id: parse_body(response).first[:id], access_level: '50' }
end end
def create_admin_personal_access_token def create_admin_personal_access_token
...@@ -103,24 +133,23 @@ module QA ...@@ -103,24 +133,23 @@ module QA
Page::Main::Menu.perform(&:sign_out) Page::Main::Menu.perform(&:sign_out)
end end
def sigin_in_and_create_group_with_user_via_api(user: nil, group_name: nil) def create_group_and_add_user_via_api(user_name, group_name)
Runtime::Env.ldap_username = user group = Resource::Group.fabricate_via_api! do |resource|
Runtime::Env.ldap_password = 'password' resource.path = "#{group_name}-#{SecureRandom.hex(4)}"
Page::Main::Login.perform do |login_page|
login_page.sign_in_using_credentials
end end
Page::Main::Menu.perform do |menu| add_user_to_group_via_api(user_name, group)
expect(menu).to have_personal_area
end
add_user_to_sandbox_group_via_api(user) group
end
Runtime::Env.personal_access_token = Resource::PersonalAccessToken.fabricate!.access_token def signin_and_visit_group_as_user(user_name, group)
Runtime::Env.ldap_username = user_name
Runtime::Env.ldap_password = 'password'
group = Resource::Group.fabricate_via_api! do |resource| Runtime::Browser.visit(:gitlab, Page::Main::Login)
resource.path = "#{group_name}-#{SecureRandom.hex(4)}" Page::Main::Login.perform do |login_page|
login_page.sign_in_using_credentials
end end
group.visit! group.visit!
......
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