Commit 9657d7a9 authored by Grzegorz Bizon's avatar Grzegorz Bizon
Browse files

Merge branch 'qa-add-more-key-tests' into 'master'

Add more QA SSH key tests

Closes gitlab-qa#183

See merge request gitlab-org/gitlab-ce!17662
......@@ -17,14 +17,14 @@
.ci-variable-row-body
%input.js-ci-variable-input-id{ type: "hidden", name: id_input_name, value: id }
%input.js-ci-variable-input-destroy{ type: "hidden", name: destroy_input_name }
%input.js-ci-variable-input-key.ci-variable-body-item.form-control{ type: "text",
%input.js-ci-variable-input-key.ci-variable-body-item.qa-ci-variable-input-key.form-control{ type: "text",
name: key_input_name,
value: key,
placeholder: s_('CiVariables|Input variable key') }
.ci-variable-body-item
.form-control.js-secret-value-placeholder{ class: ('hide' unless id) }
.form-control.js-secret-value-placeholder.qa-ci-variable-input-value{ class: ('hide' unless id) }
= '*' * 20
%textarea.js-ci-variable-input-value.js-secret-value.form-control{ class: ('hide' if id),
%textarea.js-ci-variable-input-value.js-secret-value.qa-ci-variable-input-value.form-control{ class: ('hide' if id),
rows: 1,
name: value_input_name,
placeholder: s_('CiVariables|Input variable value') }
......
FROM ruby:2.4
FROM ruby:2.4-stretch
LABEL maintainer "Grzegorz Bizon <grzegorz@gitlab.com>"
ENV DEBIAN_FRONTEND noninteractive
......
......@@ -6,5 +6,4 @@ gem 'capybara-screenshot', '~> 1.0.18'
gem 'rake', '~> 12.3.0'
gem 'rspec', '~> 3.7'
gem 'selenium-webdriver', '~> 3.8.0'
gem 'net-ssh', require: false
gem 'airborne', '~> 0.2.13'
......@@ -46,7 +46,6 @@ GEM
mini_mime (1.0.0)
mini_portile2 (2.3.0)
minitest (5.11.1)
net-ssh (4.1.0)
netrc (0.11.0)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
......@@ -98,7 +97,6 @@ DEPENDENCIES
airborne (~> 0.2.13)
capybara (~> 2.16.1)
capybara-screenshot (~> 1.0.18)
net-ssh
pry-byebug (~> 3.5.1)
rake (~> 12.3.0)
rspec (~> 3.7)
......
......@@ -11,9 +11,15 @@ module Runtime
autoload :Scenario, 'qa/runtime/scenario'
autoload :Browser, 'qa/runtime/browser'
autoload :Env, 'qa/runtime/env'
autoload :RSAKey, 'qa/runtime/rsa_key'
autoload :Address, 'qa/runtime/address'
autoload :API, 'qa/runtime/api'
module Key
autoload :Base, 'qa/runtime/key/base'
autoload :RSA, 'qa/runtime/key/rsa'
autoload :ECDSA, 'qa/runtime/key/ecdsa'
autoload :ED25519, 'qa/runtime/key/ed25519'
end
end
##
......
......@@ -2,7 +2,8 @@ module QA
module Factory
module Repository
class Push < Factory::Base
attr_writer :file_name, :file_content, :commit_message, :branch_name, :new_branch
attr_accessor :file_name, :file_content, :commit_message,
:branch_name, :new_branch, :remote_branch
dependency Factory::Resource::Project, as: :project do |project|
project.name = 'project-with-code'
......@@ -17,23 +18,32 @@ def initialize
@new_branch = true
end
def remote_branch
@remote_branch ||= branch_name
end
def fabricate!
project.visit!
Git::Repository.perform do |repository|
repository.location = Page::Project::Show.act do
repository.uri = Page::Project::Show.act do
choose_repository_clone_http
repository_location
repository_location.uri
end
repository.use_default_credentials
repository.clone
repository.configure_identity('GitLab QA', 'root@gitlab.com')
repository.checkout(@branch_name) unless @new_branch
repository.add_file(@file_name, @file_content)
repository.commit(@commit_message)
repository.push_changes(@branch_name)
if new_branch
repository.checkout_new_branch(branch_name)
else
repository.checkout(branch_name)
end
repository.add_file(file_name, file_content)
repository.commit(commit_message)
repository.push_changes("#{branch_name}:#{remote_branch}")
end
end
end
......
......@@ -39,7 +39,9 @@ def fabricate!
resource.project = project
resource.file_name = 'README.md'
resource.commit_message = 'Add readme'
resource.branch_name = "master:#{@branch_name}"
resource.branch_name = 'master'
resource.new_branch = false
resource.remote_branch = @branch_name
end
Page::Project::Show.act { wait_for_push }
......
......@@ -4,15 +4,15 @@ module Resource
class DeployKey < Factory::Base
attr_accessor :title, :key
product :title do
product :fingerprint do |resource|
Page::Project::Settings::Repository.act do
expand_deploy_keys(&:key_title)
end
end
expand_deploy_keys do |key|
key_offset = key.key_titles.index do |title|
title.text == resource.title
end
product :fingerprint do
Page::Project::Settings::Repository.act do
expand_deploy_keys(&:key_fingerprint)
key.key_fingerprints[key_offset].text
end
end
end
......
......@@ -24,12 +24,14 @@ class MergeRequest < Factory::Base
dependency Factory::Repository::Push, as: :target do |push, factory|
factory.project.visit!
push.project = factory.project
push.branch_name = "master:#{factory.target_branch}"
push.branch_name = 'master'
push.remote_branch = factory.target_branch
end
dependency Factory::Repository::Push, as: :source do |push, factory|
push.project = factory.project
push.branch_name = "#{factory.target_branch}:#{factory.source_branch}"
push.branch_name = factory.target_branch
push.remote_branch = factory.source_branch
push.file_name = "added_file.txt"
push.file_content = "File Added"
end
......
......@@ -17,6 +17,13 @@ def name=(name)
Page::Project::Show.act { project_name }
end
product :repository_ssh_location do
Page::Project::Show.act do
choose_repository_clone_ssh
repository_location
end
end
def fabricate!
group.visit!
......
......@@ -16,8 +16,7 @@ def fabricate!
Page::Project::Settings::CICD.perform do |setting|
setting.expand_secret_variables do |page|
page.fill_variable_key(key)
page.fill_variable_value(value)
page.fill_variable(key, value)
page.save_variables
end
......
......@@ -14,7 +14,7 @@ class Location
def initialize(git_uri)
@git_uri = git_uri
@uri =
if git_uri.start_with?('ssh://')
if git_uri =~ %r{\A(?:ssh|http|https)://}
URI.parse(git_uri)
else
*rest, path = git_uri.split(':')
......
......@@ -15,8 +15,7 @@ def self.perform(*args)
end
end
def location=(address)
@location = address
def uri=(address)
@uri = URI(address)
end
......@@ -43,6 +42,10 @@ def checkout(branch_name)
`git checkout "#{branch_name}"`
end
def checkout_new_branch(branch_name)
`git checkout -b "#{branch_name}"`
end
def shallow_clone
clone('--depth 1')
end
......
......@@ -64,6 +64,10 @@ def find_element(name)
find(element_selector_css(name))
end
def all_elements(name)
all(element_selector_css(name))
end
def click_element(name)
find_element(name).click
end
......
......@@ -42,6 +42,18 @@ def key_fingerprint
end
end
def key_titles
within_project_deploy_keys do
all_elements(:key_title)
end
end
def key_fingerprints
within_project_deploy_keys do
all_elements(:key_fingerprint)
end
end
private
def within_project_deploy_keys
......
......@@ -7,10 +7,8 @@ class SecretVariables < Page::Base
view 'app/views/ci/variables/_variable_row.html.haml' do
element :variable_row, '.ci-variable-row-body'
element :variable_key, '.js-ci-variable-input-key'
element :variable_value, '.js-ci-variable-input-value'
element :key_placeholder, 'Input variable key'
element :value_placeholder, 'Input variable value'
element :variable_key, '.qa-ci-variable-input-key'
element :variable_value, '.qa-ci-variable-input-value'
end
view 'app/views/ci/variables/_index.html.haml' do
......@@ -18,12 +16,14 @@ class SecretVariables < Page::Base
element :reveal_values, '.js-secret-value-reveal-button'
end
def fill_variable_key(key)
fill_in('Input variable key', with: key, match: :first)
end
def fill_variable(key, value)
keys = all_elements(:ci_variable_input_key)
index = keys.size - 1
def fill_variable_value(value)
fill_in('Input variable value', with: value, match: :first)
# After we fill the key, JS would generate another field so
# we need to use the same index to find the corresponding one.
keys[index].set(key)
all_elements(:ci_variable_input_value)[index].set(value)
end
def save_variables
......@@ -36,7 +36,7 @@ def reveal_variables
def variable_value(key)
within('.ci-variable-row-body', text: key) do
find('.js-ci-variable-input-value').value
find('.qa-ci-variable-input-value').value
end
end
end
......
......@@ -38,11 +38,7 @@ def choose_repository_clone_ssh
end
def repository_location
find('#project_clone').value
end
def repository_location_uri
Git::Location.new(repository_location)
Git::Location.new(find('#project_clone').value)
end
def project_name
......@@ -91,7 +87,7 @@ def choose_repository_clone(kind, detect_text)
end
# Ensure git clone textbox was updated
repository_location.include?(detect_text)
repository_location.git_uri.include?(detect_text)
end
end
end
......
module QA
module Runtime
module Key
class Base
attr_reader :name, :bits, :private_key, :public_key, :fingerprint
def initialize(name, bits)
@name = name
@bits = bits
Dir.mktmpdir do |dir|
path = "#{dir}/id_#{name}"
ssh_keygen(name, bits, path)
populate_key_data(path)
end
end
private
def ssh_keygen(name, bits, path)
cmd = %W[ssh-keygen -t #{name} -b #{bits} -f #{path} -N] << ''
Service::Shellout.shell(cmd)
end
def populate_key_data(path)
@private_key = File.binread(path)
@public_key = File.binread("#{path}.pub")
@fingerprint =
`ssh-keygen -l -E md5 -f #{path} | cut -d' ' -f2 | cut -d: -f2-`.chomp
end
end
end
end
end
module QA
module Runtime
module Key
class ECDSA < Base
def initialize(bits = 521)
super('ecdsa', bits)
end
end
end
end
end
module QA
module Runtime
module Key
class ED25519 < Base
def initialize
super('ed25519', 256)
end
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