Commit d0321e4a authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch 'ml-set-access-token-expiry' into 'master'

Set Personal Access Token expiry in E2E tests

See merge request gitlab-org/gitlab!28872
parents cb9ac5a6 72bde273
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
.row .row
.form-group.col-md-6 .form-group.col-md-6
= f.label :name, _('Name'), class: 'label-bold' = f.label :name, _('Name'), class: 'label-bold'
= f.text_field :name, class: "form-control qa-personal-access-token-name-field", required: true = f.text_field :name, class: "form-control", required: true, data: { qa_selector: 'personal_access_token_name_field' }
.row .row
.form-group.col-md-6 .form-group.col-md-6
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
= render_if_exists 'personal_access_tokens/callout_max_personal_access_token_lifetime' = render_if_exists 'personal_access_tokens/callout_max_personal_access_token_lifetime'
= f.text_field :expires_at, class: "datepicker form-control", placeholder: 'YYYY-MM-DD' = f.text_field :expires_at, class: "datepicker form-control", placeholder: 'YYYY-MM-DD', data: { qa_selector: 'expiry_date_field' }
.form-group .form-group
= f.label :scopes, _('Scopes'), class: 'label-bold' = f.label :scopes, _('Scopes'), class: 'label-bold'
= render 'shared/tokens/scopes_form', prefix: 'personal_access_token', token: token, scopes: scopes = render 'shared/tokens/scopes_form', prefix: 'personal_access_token', token: token, scopes: scopes
.prepend-top-default .prepend-top-default
= f.submit _('Create %{type} token') % { type: type }, class: "btn btn-success qa-create-token-button" = f.submit _('Create %{type} token') % { type: type }, class: "btn btn-success", data: { qa_selector: 'create_token_button' }
# frozen_string_literal: true # frozen_string_literal: true
require 'date'
module QA module QA
module Page module Page
module Profile module Profile
class PersonalAccessTokens < Page::Base class PersonalAccessTokens < Page::Base
view 'app/views/shared/_personal_access_tokens_form.html.haml' do view 'app/views/shared/_personal_access_tokens_form.html.haml' do
element :expiry_date_field
element :personal_access_token_name_field element :personal_access_token_name_field
element :create_token_button element :create_token_button
end end
...@@ -36,6 +39,13 @@ module QA ...@@ -36,6 +39,13 @@ module QA
find_element(:created_personal_access_token, wait: 30).value find_element(:created_personal_access_token, wait: 30).value
end end
def fill_expiry_date(date)
date = date.to_s if date.is_a?(Date)
Date.strptime(date, '%Y-%m-%d') rescue ArgumentError raise "Expiry date must be in YYYY-MM-DD format"
fill_element(:expiry_date_field, date)
end
def has_token_row_for_name?(token_name) def has_token_row_for_name?(token_name)
page.has_css?('tr', text: token_name, wait: 1.0) page.has_css?('tr', text: token_name, wait: 1.0)
end end
......
# frozen_string_literal: true # frozen_string_literal: true
require 'date'
module QA module QA
module Resource module Resource
## ##
...@@ -19,6 +21,8 @@ module QA ...@@ -19,6 +21,8 @@ module QA
Page::Profile::PersonalAccessTokens.perform do |token_page| Page::Profile::PersonalAccessTokens.perform do |token_page|
token_page.fill_token_name(name || 'api-test-token') token_page.fill_token_name(name || 'api-test-token')
token_page.check_api 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.click_create_token_button token_page.click_create_token_button
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