Commit d4d279c5 authored by Sanad Liaquat's avatar Sanad Liaquat

Retry the test setup on exception

Also capture screenshot on failure in before(:all) before raising
excpetion and add some logs.
parent 7c126e8e
...@@ -31,11 +31,15 @@ module QA ...@@ -31,11 +31,15 @@ module QA
end end
def has_enforced_sso_button? def has_enforced_sso_button?
has_element?(:enforced_sso_toggle_button, wait: 1.0) has_button = has_element?(:enforced_sso_toggle_button, wait: 5)
QA::Runtime::Logger.debug "has_enforced_sso_button?: #{has_button}"
has_button
end end
def enforce_sso_enabled? def enforce_sso_enabled?
has_enforced_sso_button? && find_element(:enforced_sso_toggle_button)[:class].include?('is-checked') enabled = has_enforced_sso_button? && find_element(:enforced_sso_toggle_button).find('input', visible: :all)[:value] == 'true'
QA::Runtime::Logger.debug "enforce_sso_enabled?: #{enabled}"
enabled
end end
def enforce_sso def enforce_sso
...@@ -49,11 +53,11 @@ module QA ...@@ -49,11 +53,11 @@ module QA
end end
def has_group_managed_accounts_button? def has_group_managed_accounts_button?
has_element?(:group_managed_accounts_toggle_button, wait: 1.0) has_element?(:group_managed_accounts_toggle_button, wait: 5)
end end
def group_managed_accounts_enabled? def group_managed_accounts_enabled?
enforce_sso_enabled? && has_group_managed_accounts_button? && find_element(:group_managed_accounts_toggle_button)[:class].include?('is-checked') enforce_sso_enabled? && has_group_managed_accounts_button? && find_element(:group_managed_accounts_toggle_button).find('input', visible: :all)[:value] == 'true'
end end
def enable_group_managed_accounts def enable_group_managed_accounts
......
...@@ -38,7 +38,9 @@ module QA ...@@ -38,7 +38,9 @@ module QA
def visit_saml_sso_settings(group, direct: false) def visit_saml_sso_settings(group, direct: false)
if direct if direct
page.visit "#{group.web_url}/-/saml" url = "#{group.web_url}/-/saml"
Runtime::Logger.debug("Visiting url \"#{url}\" directly")
page.visit url
else else
group.visit! group.visit!
......
...@@ -48,6 +48,12 @@ module QA ...@@ -48,6 +48,12 @@ module QA
feature && feature["state"] == "on" feature && feature["state"] == "on"
end end
def get_features
request = Runtime::API::Request.new(api_client, "/features")
response = get(request.url)
response.body
end
private private
def api_client def api_client
...@@ -76,12 +82,6 @@ module QA ...@@ -76,12 +82,6 @@ module QA
raise SetFeatureError, "Setting feature flag #{key} to #{value} failed with `#{response}`." raise SetFeatureError, "Setting feature flag #{key} to #{value} failed with `#{response}`."
end end
end end
def get_features
request = Runtime::API::Request.new(api_client, "/features")
response = get(request.url)
response.body
end
end end
end end
end end
# frozen_string_literal: true # frozen_string_literal: true
module QA module QA
context 'Manage', :group_saml, :orchestrated, :requires_admin do context 'Manage', :group_saml, :orchestrated do
describe 'Group SAML SSO - Enforced SSO' do describe 'Group SAML SSO - Enforced SSO' do
include Support::Api include Support::Api
before(:all) do before(:all) do
@group = Resource::Sandbox.fabricate_via_api! do |sandbox_group| Support::Retrier.retry_on_exception do
sandbox_group.path = "saml_sso_group_#{SecureRandom.hex(8)}" Flow::Saml.remove_saml_idp_service(@saml_idp_service) if @saml_idp_service
end
@group = Resource::Sandbox.fabricate_via_api! do |sandbox_group|
sandbox_group.path = "saml_sso_group_#{SecureRandom.hex(8)}"
end
@developer_user = Resource::User.fabricate_via_api! @developer_user = Resource::User.fabricate_via_api!
@group.add_member(@developer_user) @group.add_member(@developer_user)
@saml_idp_service = Flow::Saml.run_saml_idp_service(@group.path) @saml_idp_service = Flow::Saml.run_saml_idp_service(@group.path)
@managed_group_url = setup_and_enable_enforce_sso @managed_group_url = setup_and_enable_enforce_sso
end
end end
before do before do
...@@ -143,18 +147,11 @@ module QA ...@@ -143,18 +147,11 @@ module QA
Support::Retrier.retry_on_exception do Support::Retrier.retry_on_exception do
Flow::Saml.visit_saml_sso_settings(@group) Flow::Saml.visit_saml_sso_settings(@group)
ensure_enforced_sso_button_shown
managed_group_url = EE::Page::Group::Settings::SamlSSO.perform do |saml_sso| managed_group_url = EE::Page::Group::Settings::SamlSSO.perform do |saml_sso|
# Once the feature flags are enabled, it takes some time for the toggle buttons to show on the UI.
# This issue does not happen manually. Only happens with the test as they are too fast.
Support::Retrier.retry_until(sleep_interval: 1, raise_on_failure: true) do
condition_met = saml_sso.has_enforced_sso_button?
page.refresh unless condition_met
condition_met
end
saml_sso.enforce_sso saml_sso.enforce_sso
saml_sso.set_id_provider_sso_url(@saml_idp_service.idp_sso_url) saml_sso.set_id_provider_sso_url(@saml_idp_service.idp_sso_url)
saml_sso.set_cert_fingerprint(@saml_idp_service.idp_certificate_fingerprint) saml_sso.set_cert_fingerprint(@saml_idp_service.idp_certificate_fingerprint)
...@@ -164,10 +161,29 @@ module QA ...@@ -164,10 +161,29 @@ module QA
end end
Flow::Saml.visit_saml_sso_settings(@group, direct: true) Flow::Saml.visit_saml_sso_settings(@group, direct: true)
raise "Enforced SSO not setup correctly" unless EE::Page::Group::Settings::SamlSSO.perform(&:enforce_sso_enabled?) ensure_enforced_sso_button_shown
unless EE::Page::Group::Settings::SamlSSO.perform(&:enforce_sso_enabled?)
QA::Runtime::Logger.debug "Enforced SSO not setup correctly. About to raise failure."
QA::Runtime::Logger.debug Capybara::Screenshot.screenshot_and_save_page
QA::Runtime::Logger.debug Runtime::Feature.get_features
raise "Enforced SSO not setup correctly"
end
managed_group_url managed_group_url
end end
end end
def ensure_enforced_sso_button_shown
# Sometimes, the toggle button for SAML SSO does not appear and only appears after a refresh
# This issue can only be reproduced manually if you are too quick to go to the group setting page
# after enabling the feature flags.
Support::Retrier.retry_until(sleep_interval: 1, raise_on_failure: true) do
condition_met = EE::Page::Group::Settings::SamlSSO.perform(&:has_enforced_sso_button?)
page.refresh unless condition_met
condition_met
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