Commit c7fd9558 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'sh-add-deploy-token-qa' into 'master'

Add GitLab QA spec for adding a deploy token

See merge request gitlab-org/gitlab-ce!22207
parents 0d3cc866 bf456881
......@@ -6,24 +6,24 @@
.form-group
= f.label :name, class: 'label-bold'
= f.text_field :name, class: 'form-control', required: true
= f.text_field :name, class: 'form-control qa-deploy-token-name', required: true
.form-group
= f.label :expires_at, class: 'label-bold'
= f.text_field :expires_at, class: 'datepicker form-control', value: f.object.expires_at
= f.text_field :expires_at, class: 'datepicker form-control qa-deploy-token-expires-at', value: f.object.expires_at
.form-group
= f.label :scopes, class: 'label-bold'
%fieldset.form-group.form-check
= f.check_box :read_repository, class: 'form-check-input'
= f.check_box :read_repository, class: 'form-check-input qa-deploy-token-read-repository'
= label_tag ("deploy_token_read_repository"), 'read_repository', class: 'label-bold form-check-label'
.text-secondary= s_('DeployTokens|Allows read-only access to the repository')
- if container_registry_enabled?(project)
%fieldset.form-group.form-check
= f.check_box :read_registry, class: 'form-check-input'
= f.check_box :read_registry, class: 'form-check-input qa-deploy-token-read-registry'
= label_tag ("deploy_token_read_registry"), 'read_registry', class: 'label-bold form-check-label'
.text-secondary= s_('DeployTokens|Allows read-only access to the registry images')
.prepend-top-default
= f.submit s_('DeployTokens|Create deploy token'), class: 'btn btn-success'
= f.submit s_('DeployTokens|Create deploy token'), class: 'btn btn-success qa-create-deploy-token'
- expanded = expand_deploy_tokens_section?(@new_deploy_token)
%section.settings.no-animate#js-deploy-tokens{ class: ('expanded' if expanded) }
%section.qa-deploy-tokens-settings.settings.no-animate#js-deploy-tokens{ class: ('expanded' if expanded) }
.settings-header
%h4= s_('DeployTokens|Deploy Tokens')
%button.btn.js-settings-toggle.qa-expand-deploy-keys{ type: 'button' }
......
.created-deploy-token-container.info-well
.qa-created-deploy-token-section.created-deploy-token-container.info-well
.well-segment
%h5.prepend-top-0
= s_('DeployTokens|Your New Deploy Token')
.form-group
.input-group
= text_field_tag 'deploy-token-user', deploy_token.username, readonly: true, class: 'deploy-token-field form-control js-select-on-focus'
= text_field_tag 'deploy-token-user', deploy_token.username, readonly: true, class: 'deploy-token-field form-control js-select-on-focus qa-deploy-token-user'
.input-group-append
= clipboard_button(text: deploy_token.username, title: s_('DeployTokens|Copy username to clipboard'), placement: 'left')
%span.deploy-token-help-block.prepend-top-5.text-success= s_("DeployTokens|Use this username as a login.")
.form-group
.input-group
= text_field_tag 'deploy-token', deploy_token.token, readonly: true, class: 'deploy-token-field form-control js-select-on-focus'
= text_field_tag 'deploy-token', deploy_token.token, readonly: true, class: 'deploy-token-field form-control js-select-on-focus qa-deploy-token'
.input-group-append
= clipboard_button(text: deploy_token.token, title: s_('DeployTokens|Copy deploy token to clipboard'), placement: 'left')
%span.deploy-token-help-block.prepend-top-5.text-danger= s_("DeployTokens|Use this token as a password. Make sure you save it - you won't be able to access it again.")
......@@ -49,6 +49,7 @@ module QA
autoload :ProjectImportedFromGithub, 'qa/factory/resource/project_imported_from_github'
autoload :MergeRequestFromFork, 'qa/factory/resource/merge_request_from_fork'
autoload :DeployKey, 'qa/factory/resource/deploy_key'
autoload :DeployToken, 'qa/factory/resource/deploy_token'
autoload :Branch, 'qa/factory/resource/branch'
autoload :SecretVariable, 'qa/factory/resource/secret_variable'
autoload :Runner, 'qa/factory/resource/runner'
......@@ -177,6 +178,7 @@ module QA
autoload :Repository, 'qa/page/project/settings/repository'
autoload :CICD, 'qa/page/project/settings/ci_cd'
autoload :DeployKeys, 'qa/page/project/settings/deploy_keys'
autoload :DeployTokens, 'qa/page/project/settings/deploy_tokens'
autoload :ProtectedBranches, 'qa/page/project/settings/protected_branches'
autoload :SecretVariables, 'qa/page/project/settings/secret_variables'
autoload :Runners, 'qa/page/project/settings/runners'
......
module QA
module Factory
module Resource
class DeployToken < Factory::Base
attr_accessor :name, :expires_at
product :username do |resource|
Page::Project::Settings::Repository.act do
expand_deploy_tokens do |token|
token.token_username
end
end
end
product :password do |password|
Page::Project::Settings::Repository.act do
expand_deploy_tokens do |token|
token.token_password
end
end
end
dependency Factory::Resource::Project, as: :project do |project|
project.name = 'project-to-deploy'
project.description = 'project for adding deploy token test'
end
def fabricate!
project.visit!
Page::Project::Menu.act do
click_repository_settings
end
Page::Project::Settings::Repository.perform do |setting|
setting.expand_deploy_tokens do |page|
page.fill_token_name(name)
page.fill_token_expires_at(expires_at)
page.fill_scopes(read_repository: true, read_registry: false)
page.add_token
end
end
end
end
end
end
end
module QA
module Page
module Project
module Settings
class DeployTokens < Page::Base
view 'app/views/projects/deploy_tokens/_form.html.haml' do
element :deploy_token_name
element :deploy_token_expires_at
element :deploy_token_read_repository
element :deploy_token_read_registry
element :create_deploy_token
end
view 'app/views/projects/deploy_tokens/_new_deploy_token.html.haml' do
element :created_deploy_token_section
element :deploy_token_user
element :deploy_token
end
def fill_token_name(name)
fill_element :deploy_token_name, name
end
def fill_token_expires_at(expires_at)
fill_element :deploy_token_expires_at, expires_at.to_s + "\n"
end
def fill_scopes(read_repository:, read_registry:)
check_element :deploy_token_read_repository if read_repository
check_element :deploy_token_read_registry if read_registry
end
def add_token
click_element :create_deploy_token
end
def token_username
within_new_project_deploy_token do
find_element(:deploy_token_user).value
end
end
def token_password
within_new_project_deploy_token do
find_element(:deploy_token).value
end
end
private
def within_new_project_deploy_token
wait(reload: false) do
has_css?(element_selector_css(:created_deploy_token_section))
end
within_element(:created_deploy_token_section) do
yield
end
end
end
end
end
end
end
......@@ -24,6 +24,12 @@ module QA
ProtectedBranches.perform(&block)
end
end
def expand_deploy_tokens(&block)
expand_section(:deploy_tokens_settings) do
DeployTokens.perform(&block)
end
end
end
end
end
......
# frozen_string_literal: true
module QA
context :release do
describe 'Deploy token creation' do
it 'user adds a deploy token' do
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.act { sign_in_using_credentials }
deploy_token_name = 'deploy token name'
deploy_token_expires_at = Date.today + 7 # 1 Week from now
deploy_token = Factory::Resource::DeployToken.fabricate! do |resource|
resource.name = deploy_token_name
resource.expires_at = deploy_token_expires_at
end
expect(deploy_token.username.length).to be > 0
expect(deploy_token.password.length).to be > 0
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