summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qa/qa.rb4
-rw-r--r--qa/qa/factory/resource/pipeline.rb8
-rw-r--r--qa/qa/factory/resource/runner.rb17
-rw-r--r--qa/qa/page/project/job/show.rb11
-rw-r--r--qa/qa/page/project/pipeline/index.rb6
-rw-r--r--qa/qa/page/project/pipeline/show.rb10
-rw-r--r--qa/qa/page/project/show.rb29
-rw-r--r--qa/qa/runtime/rsa_key.rb2
-rw-r--r--qa/qa/service/runner.rb26
-rw-r--r--qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb83
10 files changed, 181 insertions, 15 deletions
diff --git a/qa/qa.rb b/qa/qa.rb
index 8630e2a522c..b5536a449f1 100644
--- a/qa/qa.rb
+++ b/qa/qa.rb
@@ -116,6 +116,10 @@ module QA
autoload :Show, 'qa/page/project/pipeline/show'
end
+ module Job
+ autoload :Show, 'qa/page/project/job/show'
+ end
+
module Settings
autoload :Common, 'qa/page/project/settings/common'
autoload :Advanced, 'qa/page/project/settings/advanced'
diff --git a/qa/qa/factory/resource/pipeline.rb b/qa/qa/factory/resource/pipeline.rb
new file mode 100644
index 00000000000..d3f1586ec5e
--- /dev/null
+++ b/qa/qa/factory/resource/pipeline.rb
@@ -0,0 +1,8 @@
+module QA
+ module Factory
+ module Resource
+ class Pipeline < Factory::Base
+ end
+ end
+ end
+end
diff --git a/qa/qa/factory/resource/runner.rb b/qa/qa/factory/resource/runner.rb
index 5f37f8ac2e9..da0f4b8f520 100644
--- a/qa/qa/factory/resource/runner.rb
+++ b/qa/qa/factory/resource/runner.rb
@@ -4,7 +4,7 @@ module QA
module Factory
module Resource
class Runner < Factory::Base
- attr_writer :name, :tags
+ attr_writer :name, :tags, :image, :executor, :docker_image
dependency Factory::Resource::Project, as: :project do |project|
project.name = 'project-with-ci-cd'
@@ -19,6 +19,18 @@ module QA
@tags || %w[qa e2e]
end
+ def image
+ @image || 'gitlab/gitlab-runner:alpine'
+ end
+
+ def executor
+ @executor || 'shell'
+ end
+
+ def docker_image
+ @docker_image || 'ubuntu/16.04'
+ end
+
def fabricate!
project.visit!
@@ -31,6 +43,9 @@ module QA
runner.token = runners.registration_token
runner.address = runners.coordinator_address
runner.tags = tags
+ runner.image = image
+ runner.executor = executor
+ runner.docker_image = docker_image
runner.register!
end
end
diff --git a/qa/qa/page/project/job/show.rb b/qa/qa/page/project/job/show.rb
new file mode 100644
index 00000000000..9be14812736
--- /dev/null
+++ b/qa/qa/page/project/job/show.rb
@@ -0,0 +1,11 @@
+module QA::Page
+ module Project::Job
+ class Show < QA::Page::Base
+ def output
+ css = '.js-build-output'
+ wait { has_css?(css) }
+ find(css).text
+ end
+ end
+ end
+end
diff --git a/qa/qa/page/project/pipeline/index.rb b/qa/qa/page/project/pipeline/index.rb
index 32c108393b9..9dd65aea217 100644
--- a/qa/qa/page/project/pipeline/index.rb
+++ b/qa/qa/page/project/pipeline/index.rb
@@ -8,6 +8,12 @@ module QA::Page
def go_to_latest_pipeline
first('.js-pipeline-url-link').click
end
+
+ def wait_for_latest_pipeline
+ wait do
+ first('.js-pipeline-url-link')
+ end
+ end
end
end
end
diff --git a/qa/qa/page/project/pipeline/show.rb b/qa/qa/page/project/pipeline/show.rb
index 0835173f1cd..80f8924e42c 100644
--- a/qa/qa/page/project/pipeline/show.rb
+++ b/qa/qa/page/project/pipeline/show.rb
@@ -30,6 +30,16 @@ module QA::Page
end
end
end
+
+ def go_to_first_job
+ css = '.js-pipeline-graph-job-link'
+
+ wait do
+ has_css?(css)
+ end
+
+ first(css).click
+ end
end
end
end
diff --git a/qa/qa/page/project/show.rb b/qa/qa/page/project/show.rb
index 553d35f9579..e8b26900460 100644
--- a/qa/qa/page/project/show.rb
+++ b/qa/qa/page/project/show.rb
@@ -23,16 +23,11 @@ module QA
end
def choose_repository_clone_http
- wait(reload: false) do
- click_element :clone_dropdown
-
- page.within('.clone-options-dropdown') do
- click_link('HTTP')
- end
+ choose_repository_clone('HTTP')
+ end
- # Ensure git clone textbox was updated to http URI
- page.has_css?('.git-clone-holder input#project_clone[value*="http"]')
- end
+ def choose_repository_clone_ssh
+ choose_repository_clone('SSH')
end
def repository_location
@@ -57,6 +52,22 @@ module QA
click_link 'New issue'
end
+
+ private
+
+ def choose_repository_clone(kind)
+ wait(reload: false) do
+ click_element :clone_dropdown
+
+ page.within('.clone-options-dropdown') do
+ click_link(kind)
+ end
+
+ # Ensure git clone textbox was updated to http URI
+ page.has_css?(
+ %Q{.git-clone-holder input#project_clone[value*="#{kind}"]})
+ end
+ end
end
end
end
diff --git a/qa/qa/runtime/rsa_key.rb b/qa/qa/runtime/rsa_key.rb
index d456062bce7..fcd7dcc4f02 100644
--- a/qa/qa/runtime/rsa_key.rb
+++ b/qa/qa/runtime/rsa_key.rb
@@ -7,7 +7,7 @@ module QA
extend Forwardable
attr_reader :key
- def_delegators :@key, :fingerprint
+ def_delegators :@key, :fingerprint, :to_pem
def initialize(bits = 4096)
@key = OpenSSL::PKey::RSA.new(bits)
diff --git a/qa/qa/service/runner.rb b/qa/qa/service/runner.rb
index d0ee33c69f2..f08507c8a4c 100644
--- a/qa/qa/service/runner.rb
+++ b/qa/qa/service/runner.rb
@@ -6,13 +6,15 @@ module QA
include Scenario::Actable
include Service::Shellout
- attr_accessor :token, :address, :tags, :image
+ attr_accessor :token, :address, :tags, :image, :executor, :docker_image
def initialize(name)
- @image = 'gitlab/gitlab-runner:alpine'
@name = name || "qa-runner-#{SecureRandom.hex(4)}"
@network = Runtime::Scenario.attributes[:network] || 'test'
@tags = %w[qa test]
+ @image = 'gitlab/gitlab-runner:alpine'
+ @executor = 'shell'
+ @docker_image = 'ubuntu/16.04'
end
def pull
@@ -26,16 +28,32 @@ module QA
-e CI_SERVER_URL=#{@address}
-e REGISTER_NON_INTERACTIVE=true
-e REGISTRATION_TOKEN=#{@token}
- -e RUNNER_EXECUTOR=shell
+ -e RUNNER_EXECUTOR=#{@executor}
+ -e DOCKER_IMAGE=#{@docker_image}
-e RUNNER_TAG_LIST=#{@tags.join(',')}
-e RUNNER_NAME=#{@name}
- #{@image} -c 'gitlab-runner register && gitlab-runner run'
+ #{@image} -c '#{docker_commands}'
CMD
end
def remove!
shell "docker rm -f #{@name}"
end
+
+ private
+
+ def docker_commands
+ commands = [
+ 'gitlab-runner register',
+ 'gitlab-runner run'
+ ]
+
+ if @executor == 'docker'
+ commands.unshift('apt-get install -y docker-ce')
+ end
+
+ commands.join(' && ')
+ end
end
end
end
diff --git a/qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb b/qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb
new file mode 100644
index 00000000000..a0761aab97d
--- /dev/null
+++ b/qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb
@@ -0,0 +1,83 @@
+module QA
+ feature 'pull codes with a deploy key', :core, :docker do
+ let(:runner_name) { "qa-runner-#{Time.now.to_i}" }
+
+ after do
+ Service::Runner.new(runner_name).remove!
+ end
+
+ scenario 'user pushes .gitlab-ci.yml to the repository' do
+ Runtime::Browser.visit(:gitlab, Page::Main::Login)
+ Page::Main::Login.act { sign_in_using_credentials }
+
+ project = Factory::Resource::Project.fabricate! do |resource|
+ resource.name = 'cicd-pull-with-deploy-key'
+ end
+
+ Factory::Resource::Runner.fabricate! do |runner|
+ runner.project = project
+ runner.name = runner_name
+ runner.tags = %w[qa docker]
+ runner.executor = 'shell'
+ runner.image = 'gitlab/gitlab-runner:ubuntu'
+ end
+
+ key = Runtime::RSAKey.new
+
+ Factory::Resource::DeployKey.fabricate! do |resource|
+ resource.project = project
+ resource.title = 'deploy key title'
+ resource.key = key.public_key
+ end
+
+ Factory::Resource::SecretVariable.fabricate! do |resource|
+ resource.project = project
+ resource.key = 'DEPLOY_KEY'
+ resource.value = key.to_pem
+ end
+
+ project.visit!
+
+ repository_url = Page::Project::Show.act do
+ choose_repository_clone_ssh
+ repository_location
+ end
+
+ gitlab_ci =
+ <<~YAML
+ cat-config:
+ script:
+ - eval $(ssh-agent -s)
+ - echo "$DEPLOY_KEY" | tr -d '\\r' | ssh-add - > /dev/null
+ - git clone #{repository_url}
+ - cat #{project.name}/.gitlab-ci.yml
+ tags:
+ - qa
+ - docker
+ YAML
+
+ Factory::Repository::Push.fabricate! do |push|
+ push.project = project
+ push.file_name = '.gitlab-ci.yml'
+ push.commit_message = 'Add .gitlab-ci.yml'
+ push.file_content = gitlab_ci
+ end
+
+ Page::Project::Show.act { wait_for_push }
+ Page::Menu::Side.act { click_ci_cd_pipelines }
+
+ Page::Project::Pipeline::Index.act do
+ wait_for_latest_pipeline
+ go_to_latest_pipeline
+ end
+
+ Page::Project::Pipeline::Show.act do
+ go_to_first_job
+ end
+
+ Page::Project::Job::Show.perform do |job|
+ expect(job.output).to include(gitlab_ci.tr("\n", ' '))
+ end
+ end
+ end
+end