diff options
Diffstat (limited to 'qa/qa/resource/personal_access_token.rb')
-rw-r--r-- | qa/qa/resource/personal_access_token.rb | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/qa/qa/resource/personal_access_token.rb b/qa/qa/resource/personal_access_token.rb index 6b2301ba916..59ae8f4de7a 100644 --- a/qa/qa/resource/personal_access_token.rb +++ b/qa/qa/resource/personal_access_token.rb @@ -4,17 +4,59 @@ require 'date' module QA module Resource - ## - # Create a personal access token that can be used by the api - # class PersonalAccessToken < Base attr_accessor :name - attribute :access_token do + # The user for which the personal access token is to be created + # This *could* be different than the api_client.user or the api_user provided by the QA::Resource::ApiFabricator module + attr_writer :user + + attribute :token do Page::Profile::PersonalAccessTokens.perform(&:created_access_token) end + # Only Admins can create PAT via the API. + # If Runtime::Env.admin_personal_access_token is provided, fabricate via the API, + # else, fabricate via the browser. + def fabricate_via_api! + if Runtime::Env.admin_personal_access_token && !@user.nil? + self.api_client = Runtime::API::Client.as_admin + + super + else + fabricate! + end + end + + # When a user is not provided, use default user + def user + @user || Resource::User.default + end + + def api_post_path + "/users/#{user.api_resource[:id]}/personal_access_tokens" + end + + def api_get_path + '/personal_access_tokens' + end + + def api_post_body + { + name: name || 'api-test-token', + scopes: ["api"] + } + end + + def resource_web_url(resource) + super + rescue ResourceURLMissingError + # this particular resource does not expose a web_url property + end + def fabricate! + Flow::Login.sign_in_unless_signed_in(as: user) + Page::Main::Menu.perform(&:click_edit_profile_link) Page::Profile::Menu.perform(&:click_access_tokens) @@ -22,7 +64,7 @@ module QA token_page.fill_token_name(name || 'api-test-token') token_page.check_api # Expire in 2 days just in case the token is created just before midnight - token_page.fill_expiry_date(Date.today + 2) + token_page.fill_expiry_date(Time.now.utc.to_date + 2) token_page.click_create_token_button end end |