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