Commit 480e284e authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch 'qa-nightly-129-fix-group-saml-sso-spec' into 'master'

Ensure feature flags are set properly

Closes gitlab-org/quality/nightly#129

See merge request gitlab-org/gitlab-ee!16437
parents a4dbeeb0 3a76b0fd
......@@ -18,6 +18,11 @@ module QA
set_feature(key, false)
end
def enabled?(key)
feature = JSON.parse(get_features).find { |flag| flag["name"] == key }
feature && feature["state"] == "on"
end
private
def api_client
......@@ -31,6 +36,12 @@ module QA
raise SetFeatureError, "Setting feature flag #{key} to #{value} failed with `#{response}`."
end
end
def get_features
request = Runtime::API::Request.new(api_client, "/features")
response = get(request.url)
response.body
end
end
end
end
......@@ -60,11 +60,14 @@ module QA
expect(page).to have_content("Test SAML SSO")
end
# Failure issue: https://gitlab.com/gitlab-org/quality/nightly/issues/129
context 'Enforced SSO', :quarantine do
context 'Enforced SSO' do
before do
Runtime::Feature.enable("enforced_sso")
Runtime::Feature.enable("enforced_sso_requires_session")
%w[enforced_sso enforced_sso_requires_session].each do |flag|
QA::Support::Retrier.retry_until(exit_on_failure: true) do
Runtime::Feature.enable(flag)
Runtime::Feature.enabled?(flag)
end
end
end
it 'user clones and pushes to project within a group using Git HTTP' do
......
......@@ -24,7 +24,7 @@ module QA
end
end
def retry_until(max_attempts: 3, reload_page: nil, sleep_interval: 0)
def retry_until(max_attempts: 3, reload_page: nil, sleep_interval: 0, exit_on_failure: false)
QA::Runtime::Logger.debug("with retry_until: max_attempts #{max_attempts}; sleep_interval #{sleep_interval}; reload_page:#{reload_page}")
attempts = 0
......@@ -40,6 +40,11 @@ module QA
attempts += 1
end
if exit_on_failure
QA::Runtime::Logger.debug("Raising exception after #{max_attempts} attempts")
raise
end
false
end
end
......
......@@ -3,7 +3,8 @@
describe QA::Runtime::Feature do
let(:api_client) { double('QA::Runtime::API::Client') }
let(:request) { Struct.new(:url).new('http://api') }
let(:response) { Struct.new(:code).new(201) }
let(:response_post) { Struct.new(:code).new(201) }
let(:response_get) { Struct.new(:code, :body).new(200, '[{ "name": "a-flag", "state": "on" }]') }
before do
allow(described_class).to receive(:api_client).and_return(api_client)
......@@ -18,7 +19,7 @@ describe QA::Runtime::Feature do
expect(described_class)
.to receive(:post)
.with(request.url, { value: true })
.and_return(response)
.and_return(response_post)
subject.enable('a-flag')
end
......@@ -33,9 +34,23 @@ describe QA::Runtime::Feature do
expect(described_class)
.to receive(:post)
.with(request.url, { value: false })
.and_return(response)
.and_return(response_post)
subject.disable('a-flag')
end
end
describe '.enabled?' do
it 'returns a feature flag state' do
expect(QA::Runtime::API::Request)
.to receive(:new)
.with(api_client, "/features")
.and_return(request)
expect(described_class)
.to receive(:get)
.and_return(response_get)
expect(subject.enabled?('a-flag')).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