Commit 4fad0ace authored by Sanad Liaquat's avatar Sanad Liaquat

Use RestClient with verify_ssl: false in api_fabricator

parent 4b2569cb
# frozen_string_literal: true
require 'airborne'
require 'active_support/core_ext/object/deep_dup'
require 'capybara/dsl'
module QA
module Resource
module ApiFabricator
include Airborne
include Capybara::DSL
HTTP_STATUS_OK = 200
......@@ -56,8 +54,10 @@ module QA
end
def api_get_from(get_path)
url = Runtime::API::Request.new(api_client, get_path).url
response = get(url)
response = RestClient::Request.execute(
method: :get,
url: Runtime::API::Request.new(api_client, get_path).url,
verify_ssl: false)
unless response.code == HTTP_STATUS_OK
raise ResourceNotFoundError, "Resource at #{url} could not be found (#{response.code}): `#{response}`."
......@@ -67,9 +67,11 @@ module QA
end
def api_post
response = post(
Runtime::API::Request.new(api_client, api_post_path).url,
api_post_body)
response = RestClient::Request.execute(
method: :post,
url: Runtime::API::Request.new(api_client, api_post_path).url,
payload: api_post_body,
verify_ssl: false)
unless response.code == HTTP_STATUS_CREATED
raise ResourceFabricationFailedError, "Fabrication of #{self.class.name} using the API failed (#{response.code}) with `#{response}`."
......
......@@ -2,6 +2,7 @@
require 'forwardable'
require 'capybara/dsl'
require 'active_support/core_ext/array/extract_options'
module QA
module Resource
......
# frozen_string_literal: true
module QA
context 'Manage' do
context 'Manage', :orchestrated, :ldap_tls, :ldap_no_tls do
it 'Has LDAP user synced using group cn method' do
users = [
{
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'
}
]
create_users_via_api(users)
Runtime::Browser.visit(:gitlab, Page::Main::Login)
create_sandbox_group_with_user(user: 'enguser1', group_name: 'Synched-engineering-group')
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)
verify_users_synched(['ENG User 2', 'ENG User 3'])
it 'Has LDAP user synced using group cn method' do
users = [
{
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'
}
]
create_users_via_api(users)
Runtime::Browser.visit(:gitlab, Page::Main::Login)
create_sandbox_group_with_user(user: 'enguser1', group_name: 'Synched-engineering-group')
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
it 'Has LDAP user synced using user filter method' do
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_sandbox_group_with_user(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
EE::Page::Group::Menu.perform(&:go_to_members)
EE::Page::Group::Menu.perform(&:go_to_members)
verify_users_synched(['ENG User 2', 'ENG User 3'])
end
verify_users_synched(['HR User 2', 'HR User 3'])
it 'Has LDAP user synced using user filter method' do
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_sandbox_group_with_user(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
def create_users_via_api(users)
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
EE::Page::Group::Menu.perform(&:go_to_members)
verify_users_synched(['HR User 2', 'HR User 3'])
end
def create_users_via_api(users)
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
def create_sandbox_group_with_user(user: nil, group_name: nil)
Page::Main::Login.perform do |login_page|
login_page.sign_in_using_ldap_credentials(username: user, password: 'password')
end
def create_sandbox_group_with_user(user: nil, group_name: nil)
Page::Main::Login.perform do |login_page|
login_page.sign_in_using_ldap_credentials(username: user, password: 'password')
end
Page::Main::Menu.perform do |menu|
expect(menu).to have_personal_area
end
Page::Main::Menu.perform do |menu|
expect(menu).to have_personal_area
end
Resource::Sandbox.fabricate_via_browser_ui! do |resource|
resource.path = "#{group_name}-#{SecureRandom.hex(4)}"
end
Resource::Sandbox.fabricate_via_browser_ui! do |resource|
resource.path = "#{group_name}-#{SecureRandom.hex(4)}"
end
end
def verify_users_synched(expected_users)
EE::Page::Group::Members.perform do |page|
page.click_sync_now
users_synchronised = page.with_retry(reload: true) do
expected_users.map { |user| page.has_content?(user) }.reduce(true) { |a, b| a && b }
end
expect(users_synchronised).to be_truthy
def verify_users_synched(expected_users)
EE::Page::Group::Members.perform do |page|
page.click_sync_now
users_synchronised = page.with_retry(reload: true) do
expected_users.map { |user| page.has_content?(user) }.reduce(true) { |a, b| a && b }
end
expect(users_synchronised).to be_truthy
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