diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-06 18:06:23 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-06 18:06:23 +0300 |
commit | 5277f8e69e935eabd3bf8c5e7833471b5bfad1d9 (patch) | |
tree | 405b231961d09fa399e7c4311235ee67a5da6727 /qa | |
parent | 4dcee85bb2384604153165f1296fb86d609c71cc (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'qa')
-rw-r--r-- | qa/qa/resource/user.rb | 4 | ||||
-rw-r--r-- | qa/qa/runtime/feature.rb | 18 |
2 files changed, 21 insertions, 1 deletions
diff --git a/qa/qa/resource/user.rb b/qa/qa/resource/user.rb index 095233b54f0..57663afeef5 100644 --- a/qa/qa/resource/user.rb +++ b/qa/qa/resource/user.rb @@ -17,6 +17,10 @@ module QA @unique_id = SecureRandom.hex(8) end + def admin? + api_resource&.dig(:is_admin) || false + end + def username @username || "qa-user-#{unique_id}" end diff --git a/qa/qa/runtime/feature.rb b/qa/qa/runtime/feature.rb index b74f343ba7b..75cb9eded55 100644 --- a/qa/qa/runtime/feature.rb +++ b/qa/qa/runtime/feature.rb @@ -7,6 +7,7 @@ module QA extend Support::Api SetFeatureError = Class.new(RuntimeError) + AuthorizationError = Class.new(RuntimeError) def enable(key) QA::Runtime::Logger.info("Enabling feature: #{key}") @@ -26,7 +27,22 @@ module QA private def api_client - @api_client ||= Runtime::API::Client.new(:gitlab) + @api_client ||= begin + if Runtime::Env.admin_personal_access_token + Runtime::API::Client.new(:gitlab, personal_access_token: Runtime::Env.admin_personal_access_token) + else + user = Resource::User.fabricate_via_api! do |user| + user.username = Runtime::User.admin_username + user.password = Runtime::User.admin_password + end + + unless user.admin? + raise AuthorizationError, "Administrator access is required to enable/disable feature flags. User '#{user.username}' is not an administrator." + end + + Runtime::API::Client.new(:gitlab, user: user) + end + end end def set_feature(key, value) |