From 1264e2b6e8ce53f578255e9296875947845431bf Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 2 Feb 2018 00:35:33 +0800 Subject: WIP --- qa/qa.rb | 4 ++ qa/qa/factory/resource/pipeline.rb | 8 +++ qa/qa/factory/resource/runner.rb | 17 ++++- qa/qa/page/project/job/show.rb | 11 +++ qa/qa/page/project/pipeline/index.rb | 6 ++ qa/qa/page/project/pipeline/show.rb | 10 +++ qa/qa/page/project/show.rb | 29 +++++--- qa/qa/runtime/rsa_key.rb | 2 +- qa/qa/service/runner.rb | 26 +++++-- .../features/cicd/pull_with_deploy_key_spec.rb | 83 ++++++++++++++++++++++ 10 files changed, 181 insertions(+), 15 deletions(-) create mode 100644 qa/qa/factory/resource/pipeline.rb create mode 100644 qa/qa/page/project/job/show.rb create mode 100644 qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb 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 -- cgit v1.2.1 From 578a98fb447b2c98763c09b51d38d50c895ec925 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 9 Feb 2018 20:58:26 +0800 Subject: Save host-verification test against SHA1 checksum --- qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 index a0761aab97d..91ade2649ac 100644 --- a/qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb +++ b/qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb @@ -1,3 +1,5 @@ +require 'digest/sha1' + module QA feature 'pull codes with a deploy key', :core, :docker do let(:runner_name) { "qa-runner-#{Time.now.to_i}" } @@ -43,19 +45,25 @@ module QA repository_location end + repository_uri = URI.parse(repository_url) + gitlab_ci = <<~YAML cat-config: script: + - mkdir -p ~/.ssh + - ssh-keyscan -p #{repository_uri.port} #{repository_uri.host} >> ~/.ssh/known_hosts - eval $(ssh-agent -s) - - echo "$DEPLOY_KEY" | tr -d '\\r' | ssh-add - > /dev/null + - echo "$DEPLOY_KEY" | ssh-add - - git clone #{repository_url} - - cat #{project.name}/.gitlab-ci.yml + - sha1sum #{project.name}/.gitlab-ci.yml tags: - qa - docker YAML + sha1sum = Digest::SHA1.hexdigest(gitlab_ci) + Factory::Repository::Push.fabricate! do |push| push.project = project push.file_name = '.gitlab-ci.yml' @@ -76,7 +84,7 @@ module QA end Page::Project::Job::Show.perform do |job| - expect(job.output).to include(gitlab_ci.tr("\n", ' ')) + expect(job.output).to include(sha1sum) end end end -- cgit v1.2.1 From 75984534f80b97d2bc7f05c24ce3e0cadb5b85a3 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 9 Feb 2018 22:25:08 +0800 Subject: Cleanup codes and address feedback --- qa/qa/factory/resource/pipeline.rb | 8 -------- qa/qa/page/project/job/show.rb | 10 +++++++++- qa/qa/page/project/pipeline/index.rb | 11 ++++++----- qa/qa/page/project/pipeline/show.rb | 3 ++- qa/qa/page/project/show.rb | 2 +- qa/qa/service/runner.rb | 4 ---- qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb | 15 ++++----------- 7 files changed, 22 insertions(+), 31 deletions(-) delete mode 100644 qa/qa/factory/resource/pipeline.rb diff --git a/qa/qa/factory/resource/pipeline.rb b/qa/qa/factory/resource/pipeline.rb deleted file mode 100644 index d3f1586ec5e..00000000000 --- a/qa/qa/factory/resource/pipeline.rb +++ /dev/null @@ -1,8 +0,0 @@ -module QA - module Factory - module Resource - class Pipeline < Factory::Base - end - end - end -end diff --git a/qa/qa/page/project/job/show.rb b/qa/qa/page/project/job/show.rb index 9be14812736..21bda74efb2 100644 --- a/qa/qa/page/project/job/show.rb +++ b/qa/qa/page/project/job/show.rb @@ -1,9 +1,17 @@ module QA::Page module Project::Job class Show < QA::Page::Base + view 'app/views/projects/jobs/show.html.haml' do + element :build_output, '.js-build-output' + end + def output css = '.js-build-output' - wait { has_css?(css) } + + wait(reload: false) do + has_css?(css) + end + find(css).text end end diff --git a/qa/qa/page/project/pipeline/index.rb b/qa/qa/page/project/pipeline/index.rb index 9dd65aea217..466010935b1 100644 --- a/qa/qa/page/project/pipeline/index.rb +++ b/qa/qa/page/project/pipeline/index.rb @@ -6,13 +6,14 @@ module QA::Page end def go_to_latest_pipeline - first('.js-pipeline-url-link').click - end + css = '.js-pipeline-url-link' + link = nil - def wait_for_latest_pipeline - wait do - first('.js-pipeline-url-link') + wait(reload: false) do + link = first(css) end + + link.click end end end diff --git a/qa/qa/page/project/pipeline/show.rb b/qa/qa/page/project/pipeline/show.rb index 80f8924e42c..b183552d46c 100644 --- a/qa/qa/page/project/pipeline/show.rb +++ b/qa/qa/page/project/pipeline/show.rb @@ -11,6 +11,7 @@ module QA::Page view 'app/assets/javascripts/pipelines/components/graph/job_component.vue' do element :job_component, /class.*ci-job-component.*/ + element :job_link, /class.*js-pipeline-graph-job-link.*/ end view 'app/assets/javascripts/vue_shared/components/ci_icon.vue' do @@ -34,7 +35,7 @@ module QA::Page def go_to_first_job css = '.js-pipeline-graph-job-link' - wait do + wait(reload: false) do has_css?(css) end diff --git a/qa/qa/page/project/show.rb b/qa/qa/page/project/show.rb index 1f1fede2149..93fcfe6d5e5 100644 --- a/qa/qa/page/project/show.rb +++ b/qa/qa/page/project/show.rb @@ -62,7 +62,7 @@ module QA click_link(kind) end - # Ensure git clone textbox was updated to http URI + # Ensure git clone textbox was updated repository_location.include?(detect_text) end end diff --git a/qa/qa/service/runner.rb b/qa/qa/service/runner.rb index f08507c8a4c..1362d1b1410 100644 --- a/qa/qa/service/runner.rb +++ b/qa/qa/service/runner.rb @@ -48,10 +48,6 @@ module QA 'gitlab-runner run' ] - if @executor == 'docker' - commands.unshift('apt-get install -y docker-ce') - end - commands.join(' && ') 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 index 91ade2649ac..39c600aee87 100644 --- a/qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb +++ b/qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb @@ -8,7 +8,7 @@ module QA Service::Runner.new(runner_name).remove! end - scenario 'user pushes .gitlab-ci.yml to the repository' do + scenario 'user setup a deploy key and use it to pull from CI job' do Runtime::Browser.visit(:gitlab, Page::Main::Login) Page::Main::Login.act { sign_in_using_credentials } @@ -52,7 +52,7 @@ module QA cat-config: script: - mkdir -p ~/.ssh - - ssh-keyscan -p #{repository_uri.port} #{repository_uri.host} >> ~/.ssh/known_hosts + - ssh-keyscan -p #{repository_uri.port || 22} #{repository_uri.host} >> ~/.ssh/known_hosts - eval $(ssh-agent -s) - echo "$DEPLOY_KEY" | ssh-add - - git clone #{repository_url} @@ -73,15 +73,8 @@ module QA 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::Pipeline::Index.act { go_to_latest_pipeline } + Page::Project::Pipeline::Show.act { go_to_first_job } Page::Project::Job::Show.perform do |job| expect(job.output).to include(sha1sum) -- cgit v1.2.1 From bc2739a52ff9a5366d3d668ef0ee07e91974c540 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Mon, 12 Feb 2018 16:43:32 +0800 Subject: Adopt Git style URI --- qa/qa/git/repository.rb | 14 ++++++ .../features/cicd/pull_with_deploy_key_spec.rb | 2 +- qa/spec/git/repository_spec.rb | 52 ++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 qa/spec/git/repository_spec.rb diff --git a/qa/qa/git/repository.rb b/qa/qa/git/repository.rb index 8f999511d58..606fc66b4d5 100644 --- a/qa/qa/git/repository.rb +++ b/qa/qa/git/repository.rb @@ -1,3 +1,4 @@ +require 'cgi' require 'uri' module QA @@ -5,6 +6,19 @@ module QA class Repository include Scenario::Actable + # See: config/initializers/1_settings.rb + # Settings#build_gitlab_shell_ssh_path_prefix + def self.parse_uri(git_uri) + if git_uri.start_with?('ssh://') + URI.parse(git_uri) + else + *rest, path = git_uri.split(':') + # Host cannot have : so we'll need to escape it + user_host = rest.join('%3A').sub(/\A\[(.+)\]\z/, '\1') + URI.parse("ssh://#{user_host}/#{path}") + end + end + def self.perform(*args) Dir.mktmpdir do |dir| Dir.chdir(dir) { super } 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 index 39c600aee87..c1fa8d5b58a 100644 --- a/qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb +++ b/qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb @@ -45,7 +45,7 @@ module QA repository_location end - repository_uri = URI.parse(repository_url) + repository_uri = Git::Repository.parse_uri(repository_url) gitlab_ci = <<~YAML diff --git a/qa/spec/git/repository_spec.rb b/qa/spec/git/repository_spec.rb new file mode 100644 index 00000000000..ae58355d199 --- /dev/null +++ b/qa/spec/git/repository_spec.rb @@ -0,0 +1,52 @@ +describe QA::Git::Repository do + describe '.parse_uri' do + context 'when URI starts with ssh://' do + context 'when URI has port' do + it 'parses correctly' do + uri = described_class + .parse_uri('ssh://git@qa.test:2222/sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa.test') + expect(uri.port).to eq(2222) + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + + context 'when URI does not have port' do + it 'parses correctly' do + uri = described_class + .parse_uri('ssh://git@qa.test/sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa.test') + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + end + + context 'when URI does not start with ssh://' do + context 'when host does not have colons' do + it 'parses correctly' do + uri = described_class + .parse_uri('git@qa.test:sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa.test') + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + + context 'when host has a colon' do + it 'parses correctly' do + uri = described_class + .parse_uri('[git@qa:test]:sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa%3Atest') + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + end + end +end -- cgit v1.2.1 From 338bb2ac975bb5c4a7d8074c126029d86074e251 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Mon, 12 Feb 2018 20:50:15 +0800 Subject: Remove unused codes and address feedback --- qa/qa/factory/resource/runner.rb | 12 +--- qa/qa/service/runner.rb | 22 ++---- .../features/cicd/pull_with_deploy_key_spec.rb | 84 ---------------------- .../features/project/deploy_key_clone_spec.rb | 82 +++++++++++++++++++++ 4 files changed, 87 insertions(+), 113 deletions(-) delete mode 100644 qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb create mode 100644 qa/qa/specs/features/project/deploy_key_clone_spec.rb diff --git a/qa/qa/factory/resource/runner.rb b/qa/qa/factory/resource/runner.rb index da0f4b8f520..03b69eb1bdf 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, :image, :executor, :docker_image + attr_writer :name, :tags, :image dependency Factory::Resource::Project, as: :project do |project| project.name = 'project-with-ci-cd' @@ -23,14 +23,6 @@ module QA @image || 'gitlab/gitlab-runner:alpine' end - def executor - @executor || 'shell' - end - - def docker_image - @docker_image || 'ubuntu/16.04' - end - def fabricate! project.visit! @@ -44,8 +36,6 @@ module QA 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/service/runner.rb b/qa/qa/service/runner.rb index 1362d1b1410..d0ee33c69f2 100644 --- a/qa/qa/service/runner.rb +++ b/qa/qa/service/runner.rb @@ -6,15 +6,13 @@ module QA include Scenario::Actable include Service::Shellout - attr_accessor :token, :address, :tags, :image, :executor, :docker_image + attr_accessor :token, :address, :tags, :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 @@ -28,28 +26,16 @@ module QA -e CI_SERVER_URL=#{@address} -e REGISTER_NON_INTERACTIVE=true -e REGISTRATION_TOKEN=#{@token} - -e RUNNER_EXECUTOR=#{@executor} - -e DOCKER_IMAGE=#{@docker_image} + -e RUNNER_EXECUTOR=shell -e RUNNER_TAG_LIST=#{@tags.join(',')} -e RUNNER_NAME=#{@name} - #{@image} -c '#{docker_commands}' + #{@image} -c 'gitlab-runner register && gitlab-runner run' CMD end def remove! shell "docker rm -f #{@name}" end - - private - - def docker_commands - commands = [ - 'gitlab-runner register', - 'gitlab-runner run' - ] - - 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 deleted file mode 100644 index c1fa8d5b58a..00000000000 --- a/qa/qa/specs/features/cicd/pull_with_deploy_key_spec.rb +++ /dev/null @@ -1,84 +0,0 @@ -require 'digest/sha1' - -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 setup a deploy key and use it to pull from CI job' 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 - - repository_uri = Git::Repository.parse_uri(repository_url) - - gitlab_ci = - <<~YAML - cat-config: - script: - - mkdir -p ~/.ssh - - ssh-keyscan -p #{repository_uri.port || 22} #{repository_uri.host} >> ~/.ssh/known_hosts - - eval $(ssh-agent -s) - - echo "$DEPLOY_KEY" | ssh-add - - - git clone #{repository_url} - - sha1sum #{project.name}/.gitlab-ci.yml - tags: - - qa - - docker - YAML - - sha1sum = Digest::SHA1.hexdigest(gitlab_ci) - - 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 { go_to_latest_pipeline } - Page::Project::Pipeline::Show.act { go_to_first_job } - - Page::Project::Job::Show.perform do |job| - expect(job.output).to include(sha1sum) - end - end - end -end diff --git a/qa/qa/specs/features/project/deploy_key_clone_spec.rb b/qa/qa/specs/features/project/deploy_key_clone_spec.rb new file mode 100644 index 00000000000..297e677175f --- /dev/null +++ b/qa/qa/specs/features/project/deploy_key_clone_spec.rb @@ -0,0 +1,82 @@ +require 'digest/sha1' + +module QA + feature 'cloning code using 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 sets up a deploy key to clone code using pipelines' 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 = 'deploy-key-clone-project' + end + + Factory::Resource::Runner.fabricate! do |runner| + runner.project = project + runner.name = runner_name + runner.tags = %w[qa docker] + 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 + + repository_uri = Git::Repository.parse_uri(repository_url) + + gitlab_ci = <<~YAML + cat-config: + script: + - mkdir -p ~/.ssh + - ssh-keyscan -p #{repository_uri.port || 22} #{repository_uri.host} >> ~/.ssh/known_hosts + - eval $(ssh-agent -s) + - echo "$DEPLOY_KEY" | ssh-add - + - git clone #{repository_url} + - sha1sum #{project.name}/.gitlab-ci.yml + tags: + - qa + - docker + YAML + + sha1sum = Digest::SHA1.hexdigest(gitlab_ci) + + 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 { go_to_latest_pipeline } + Page::Project::Pipeline::Show.act { go_to_first_job } + + Page::Project::Job::Show.perform do |job| + expect(job.output).to include(sha1sum) + end + end + end +end -- cgit v1.2.1 From 2f34ef34fa230c1954e47504cd8ead1a6ab019fe Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Mon, 12 Feb 2018 22:03:49 +0800 Subject: Make wait return the value we yielded when it's not nil nor false. --- qa/qa/page/base.rb | 3 ++- qa/qa/page/project/pipeline/index.rb | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb index 5c3af4b9115..7924479e2a1 100644 --- a/qa/qa/page/base.rb +++ b/qa/qa/page/base.rb @@ -17,7 +17,8 @@ module QA start = Time.now while Time.now - start < max - return true if yield + result = yield + return result if result sleep(time) diff --git a/qa/qa/page/project/pipeline/index.rb b/qa/qa/page/project/pipeline/index.rb index 466010935b1..ce430a2a6ee 100644 --- a/qa/qa/page/project/pipeline/index.rb +++ b/qa/qa/page/project/pipeline/index.rb @@ -7,10 +7,9 @@ module QA::Page def go_to_latest_pipeline css = '.js-pipeline-url-link' - link = nil - wait(reload: false) do - link = first(css) + link = wait(reload: false) do + first(css) end link.click -- cgit v1.2.1 From 565fdd63cf49c266c7a6a2a0d2a843339a9d30e6 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Mon, 12 Feb 2018 23:25:18 +0800 Subject: Rearrange the test structure and introduce a new repository location class. --- qa/qa/git/repository.rb | 15 +--- qa/qa/git/repository/location.rb | 41 +++++++++++ qa/qa/page/project/show.rb | 4 ++ .../features/project/deploy_key_clone_spec.rb | 79 +++++++++++++--------- qa/spec/git/repository/location_spec.rb | 55 +++++++++++++++ qa/spec/git/repository_spec.rb | 52 -------------- 6 files changed, 149 insertions(+), 97 deletions(-) create mode 100644 qa/qa/git/repository/location.rb create mode 100644 qa/spec/git/repository/location_spec.rb delete mode 100644 qa/spec/git/repository_spec.rb diff --git a/qa/qa/git/repository.rb b/qa/qa/git/repository.rb index 606fc66b4d5..903d292b69c 100644 --- a/qa/qa/git/repository.rb +++ b/qa/qa/git/repository.rb @@ -4,20 +4,9 @@ require 'uri' module QA module Git class Repository - include Scenario::Actable + autoload :Location, 'qa/git/repository/location' - # See: config/initializers/1_settings.rb - # Settings#build_gitlab_shell_ssh_path_prefix - def self.parse_uri(git_uri) - if git_uri.start_with?('ssh://') - URI.parse(git_uri) - else - *rest, path = git_uri.split(':') - # Host cannot have : so we'll need to escape it - user_host = rest.join('%3A').sub(/\A\[(.+)\]\z/, '\1') - URI.parse("ssh://#{user_host}/#{path}") - end - end + include Scenario::Actable def self.perform(*args) Dir.mktmpdir do |dir| diff --git a/qa/qa/git/repository/location.rb b/qa/qa/git/repository/location.rb new file mode 100644 index 00000000000..dce8327ce82 --- /dev/null +++ b/qa/qa/git/repository/location.rb @@ -0,0 +1,41 @@ +require 'uri' +require 'forwardable' + +module QA + module Git + class Repository + class Location + extend Forwardable + + attr_reader :git_uri, :uri + def_delegators :@uri, :user, :host, :path + + # See: config/initializers/1_settings.rb + # Settings#build_gitlab_shell_ssh_path_prefix + def self.parse(git_uri) + if git_uri.start_with?('ssh://') + new(git_uri, URI.parse(git_uri)) + else + *rest, path = git_uri.split(':') + # Host cannot have : so we'll need to escape it + user_host = rest.join('%3A').sub(/\A\[(.+)\]\z/, '\1') + new(git_uri, URI.parse("ssh://#{user_host}/#{path}")) + end + end + + def initialize(git_uri, uri) + @git_uri = git_uri + @uri = uri + end + + def scheme + uri.scheme || 'ssh' + end + + def port + uri.port || 22 + end + end + end + end +end diff --git a/qa/qa/page/project/show.rb b/qa/qa/page/project/show.rb index 93fcfe6d5e5..834a36c4bd0 100644 --- a/qa/qa/page/project/show.rb +++ b/qa/qa/page/project/show.rb @@ -33,6 +33,10 @@ module QA find('#project_clone').value end + def repository_location_uri + Git::Repository::Location.parse(repository_location) + end + def project_name find('.qa-project-name').text end diff --git a/qa/qa/specs/features/project/deploy_key_clone_spec.rb b/qa/qa/specs/features/project/deploy_key_clone_spec.rb index 297e677175f..9b4897a1f96 100644 --- a/qa/qa/specs/features/project/deploy_key_clone_spec.rb +++ b/qa/qa/specs/features/project/deploy_key_clone_spec.rb @@ -3,71 +3,86 @@ require 'digest/sha1' module QA feature 'cloning code using a deploy key', :core, :docker do let(:runner_name) { "qa-runner-#{Time.now.to_i}" } + let(:key) { Runtime::RSAKey.new } - after do - Service::Runner.new(runner_name).remove! - end - - scenario 'user sets up a deploy key to clone code using pipelines' do - Runtime::Browser.visit(:gitlab, Page::Main::Login) - Page::Main::Login.act { sign_in_using_credentials } - - project = Factory::Resource::Project.fabricate! do |resource| + given(:project) do + Factory::Resource::Project.fabricate! do |resource| resource.name = 'deploy-key-clone-project' end + end - Factory::Resource::Runner.fabricate! do |runner| - runner.project = project - runner.name = runner_name - runner.tags = %w[qa docker] - runner.image = 'gitlab/gitlab-runner:ubuntu' + def fabricate_runner + Factory::Resource::Runner.fabricate! do |resource| + resource.project = project + resource.name = runner_name + resource.tags = %w[qa docker] + resource.image = 'gitlab/gitlab-runner:ubuntu' end + end - key = Runtime::RSAKey.new - + def fabricate_deploy_key Factory::Resource::DeployKey.fabricate! do |resource| resource.project = project resource.title = 'deploy key title' resource.key = key.public_key end + end + def fabricate_secret_variable Factory::Resource::SecretVariable.fabricate! do |resource| resource.project = project resource.key = 'DEPLOY_KEY' resource.value = key.to_pem end + end - project.visit! - - repository_url = Page::Project::Show.act do + def fabricate_gitlab_ci + repository_uri = Page::Project::Show.act do choose_repository_clone_ssh - repository_location + repository_location_uri end - repository_uri = Git::Repository.parse_uri(repository_url) - - gitlab_ci = <<~YAML + <<~YAML cat-config: script: - mkdir -p ~/.ssh - - ssh-keyscan -p #{repository_uri.port || 22} #{repository_uri.host} >> ~/.ssh/known_hosts + - ssh-keyscan -p #{repository_uri.port} #{repository_uri.host} >> ~/.ssh/known_hosts - eval $(ssh-agent -s) - echo "$DEPLOY_KEY" | ssh-add - - - git clone #{repository_url} + - git clone #{repository_uri.git_uri} - sha1sum #{project.name}/.gitlab-ci.yml tags: - qa - docker YAML + end - sha1sum = Digest::SHA1.hexdigest(gitlab_ci) - - 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 + def fabricate_push(gitlab_ci) + Factory::Repository::Push.fabricate! do |resource| + resource.project = project + resource.file_name = '.gitlab-ci.yml' + resource.commit_message = 'Add .gitlab-ci.yml' + resource.file_content = gitlab_ci end + end + + after do + Service::Runner.new(runner_name).remove! + end + + scenario 'user sets up a deploy key to clone code using pipelines' do + Runtime::Browser.visit(:gitlab, Page::Main::Login) + Page::Main::Login.act { sign_in_using_credentials } + + fabricate_runner + fabricate_deploy_key + fabricate_secret_variable + + project.visit! + + gitlab_ci = fabricate_gitlab_ci + fabricate_push(gitlab_ci) + sha1sum = Digest::SHA1.hexdigest(gitlab_ci) Page::Project::Show.act { wait_for_push } Page::Menu::Side.act { click_ci_cd_pipelines } diff --git a/qa/spec/git/repository/location_spec.rb b/qa/spec/git/repository/location_spec.rb new file mode 100644 index 00000000000..c1fe01becd7 --- /dev/null +++ b/qa/spec/git/repository/location_spec.rb @@ -0,0 +1,55 @@ +describe QA::Git::Repository::Location do + describe '.parse' do + context 'when URI starts with ssh://' do + context 'when URI has port' do + it 'parses correctly' do + uri = described_class + .parse('ssh://git@qa.test:2222/sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa.test') + expect(uri.port).to eq(2222) + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + + context 'when URI does not have port' do + it 'parses correctly' do + uri = described_class + .parse('ssh://git@qa.test/sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa.test') + expect(uri.port).to eq(22) + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + end + + context 'when URI does not start with ssh://' do + context 'when host does not have colons' do + it 'parses correctly' do + uri = described_class + .parse('git@qa.test:sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa.test') + expect(uri.port).to eq(22) + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + + context 'when host has a colon' do + it 'parses correctly' do + uri = described_class + .parse('[git@qa:test]:sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa%3Atest') + expect(uri.port).to eq(22) + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + end + end +end diff --git a/qa/spec/git/repository_spec.rb b/qa/spec/git/repository_spec.rb deleted file mode 100644 index ae58355d199..00000000000 --- a/qa/spec/git/repository_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -describe QA::Git::Repository do - describe '.parse_uri' do - context 'when URI starts with ssh://' do - context 'when URI has port' do - it 'parses correctly' do - uri = described_class - .parse_uri('ssh://git@qa.test:2222/sandbox/qa/repo.git') - - expect(uri.user).to eq('git') - expect(uri.host).to eq('qa.test') - expect(uri.port).to eq(2222) - expect(uri.path).to eq('/sandbox/qa/repo.git') - end - end - - context 'when URI does not have port' do - it 'parses correctly' do - uri = described_class - .parse_uri('ssh://git@qa.test/sandbox/qa/repo.git') - - expect(uri.user).to eq('git') - expect(uri.host).to eq('qa.test') - expect(uri.path).to eq('/sandbox/qa/repo.git') - end - end - end - - context 'when URI does not start with ssh://' do - context 'when host does not have colons' do - it 'parses correctly' do - uri = described_class - .parse_uri('git@qa.test:sandbox/qa/repo.git') - - expect(uri.user).to eq('git') - expect(uri.host).to eq('qa.test') - expect(uri.path).to eq('/sandbox/qa/repo.git') - end - end - - context 'when host has a colon' do - it 'parses correctly' do - uri = described_class - .parse_uri('[git@qa:test]:sandbox/qa/repo.git') - - expect(uri.user).to eq('git') - expect(uri.host).to eq('qa%3Atest') - expect(uri.path).to eq('/sandbox/qa/repo.git') - end - end - end - end -end -- cgit v1.2.1 From 59d49f70c3b36e633b78e82fe3bd85b53f06900b Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 13 Feb 2018 23:35:45 +0800 Subject: Rename Git::Repository::Location to Git::Location --- qa/qa.rb | 1 + qa/qa/git/location.rb | 39 +++++++++++++++++++++++ qa/qa/git/repository.rb | 2 -- qa/qa/git/repository/location.rb | 41 ------------------------ qa/spec/git/location_spec.rb | 55 +++++++++++++++++++++++++++++++++ qa/spec/git/repository/location_spec.rb | 55 --------------------------------- 6 files changed, 95 insertions(+), 98 deletions(-) create mode 100644 qa/qa/git/location.rb delete mode 100644 qa/qa/git/repository/location.rb create mode 100644 qa/spec/git/location_spec.rb delete mode 100644 qa/spec/git/repository/location_spec.rb diff --git a/qa/qa.rb b/qa/qa.rb index c1b5d278186..c6de8625f3d 100644 --- a/qa/qa.rb +++ b/qa/qa.rb @@ -169,6 +169,7 @@ module QA # module Git autoload :Repository, 'qa/git/repository' + autoload :Location, 'qa/git/location' end ## diff --git a/qa/qa/git/location.rb b/qa/qa/git/location.rb new file mode 100644 index 00000000000..fa3f5721d7a --- /dev/null +++ b/qa/qa/git/location.rb @@ -0,0 +1,39 @@ +require 'uri' +require 'forwardable' + +module QA + module Git + class Location + extend Forwardable + + attr_reader :git_uri, :uri + def_delegators :@uri, :user, :host, :path + + # See: config/initializers/1_settings.rb + # Settings#build_gitlab_shell_ssh_path_prefix + def self.parse(git_uri) + if git_uri.start_with?('ssh://') + new(git_uri, URI.parse(git_uri)) + else + *rest, path = git_uri.split(':') + # Host cannot have : so we'll need to escape it + user_host = rest.join('%3A').sub(/\A\[(.+)\]\z/, '\1') + new(git_uri, URI.parse("ssh://#{user_host}/#{path}")) + end + end + + def initialize(git_uri, uri) + @git_uri = git_uri + @uri = uri + end + + def scheme + uri.scheme || 'ssh' + end + + def port + uri.port || 22 + end + end + end +end diff --git a/qa/qa/git/repository.rb b/qa/qa/git/repository.rb index 903d292b69c..8eb7031f609 100644 --- a/qa/qa/git/repository.rb +++ b/qa/qa/git/repository.rb @@ -4,8 +4,6 @@ require 'uri' module QA module Git class Repository - autoload :Location, 'qa/git/repository/location' - include Scenario::Actable def self.perform(*args) diff --git a/qa/qa/git/repository/location.rb b/qa/qa/git/repository/location.rb deleted file mode 100644 index dce8327ce82..00000000000 --- a/qa/qa/git/repository/location.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'uri' -require 'forwardable' - -module QA - module Git - class Repository - class Location - extend Forwardable - - attr_reader :git_uri, :uri - def_delegators :@uri, :user, :host, :path - - # See: config/initializers/1_settings.rb - # Settings#build_gitlab_shell_ssh_path_prefix - def self.parse(git_uri) - if git_uri.start_with?('ssh://') - new(git_uri, URI.parse(git_uri)) - else - *rest, path = git_uri.split(':') - # Host cannot have : so we'll need to escape it - user_host = rest.join('%3A').sub(/\A\[(.+)\]\z/, '\1') - new(git_uri, URI.parse("ssh://#{user_host}/#{path}")) - end - end - - def initialize(git_uri, uri) - @git_uri = git_uri - @uri = uri - end - - def scheme - uri.scheme || 'ssh' - end - - def port - uri.port || 22 - end - end - end - end -end diff --git a/qa/spec/git/location_spec.rb b/qa/spec/git/location_spec.rb new file mode 100644 index 00000000000..4c68a0cda61 --- /dev/null +++ b/qa/spec/git/location_spec.rb @@ -0,0 +1,55 @@ +describe QA::Git::Location do + describe '.parse' do + context 'when URI starts with ssh://' do + context 'when URI has port' do + it 'parses correctly' do + uri = described_class + .parse('ssh://git@qa.test:2222/sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa.test') + expect(uri.port).to eq(2222) + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + + context 'when URI does not have port' do + it 'parses correctly' do + uri = described_class + .parse('ssh://git@qa.test/sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa.test') + expect(uri.port).to eq(22) + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + end + + context 'when URI does not start with ssh://' do + context 'when host does not have colons' do + it 'parses correctly' do + uri = described_class + .parse('git@qa.test:sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa.test') + expect(uri.port).to eq(22) + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + + context 'when host has a colon' do + it 'parses correctly' do + uri = described_class + .parse('[git@qa:test]:sandbox/qa/repo.git') + + expect(uri.user).to eq('git') + expect(uri.host).to eq('qa%3Atest') + expect(uri.port).to eq(22) + expect(uri.path).to eq('/sandbox/qa/repo.git') + end + end + end + end +end diff --git a/qa/spec/git/repository/location_spec.rb b/qa/spec/git/repository/location_spec.rb deleted file mode 100644 index c1fe01becd7..00000000000 --- a/qa/spec/git/repository/location_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -describe QA::Git::Repository::Location do - describe '.parse' do - context 'when URI starts with ssh://' do - context 'when URI has port' do - it 'parses correctly' do - uri = described_class - .parse('ssh://git@qa.test:2222/sandbox/qa/repo.git') - - expect(uri.user).to eq('git') - expect(uri.host).to eq('qa.test') - expect(uri.port).to eq(2222) - expect(uri.path).to eq('/sandbox/qa/repo.git') - end - end - - context 'when URI does not have port' do - it 'parses correctly' do - uri = described_class - .parse('ssh://git@qa.test/sandbox/qa/repo.git') - - expect(uri.user).to eq('git') - expect(uri.host).to eq('qa.test') - expect(uri.port).to eq(22) - expect(uri.path).to eq('/sandbox/qa/repo.git') - end - end - end - - context 'when URI does not start with ssh://' do - context 'when host does not have colons' do - it 'parses correctly' do - uri = described_class - .parse('git@qa.test:sandbox/qa/repo.git') - - expect(uri.user).to eq('git') - expect(uri.host).to eq('qa.test') - expect(uri.port).to eq(22) - expect(uri.path).to eq('/sandbox/qa/repo.git') - end - end - - context 'when host has a colon' do - it 'parses correctly' do - uri = described_class - .parse('[git@qa:test]:sandbox/qa/repo.git') - - expect(uri.user).to eq('git') - expect(uri.host).to eq('qa%3Atest') - expect(uri.port).to eq(22) - expect(uri.path).to eq('/sandbox/qa/repo.git') - end - end - end - end -end -- cgit v1.2.1 From de484c6ba035a4b0ed0c0a42212aaedf9788c45c Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 13 Feb 2018 23:37:36 +0800 Subject: Just use initialize and remove scheme we're not using --- qa/qa/git/location.rb | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/qa/qa/git/location.rb b/qa/qa/git/location.rb index fa3f5721d7a..55f7213972d 100644 --- a/qa/qa/git/location.rb +++ b/qa/qa/git/location.rb @@ -11,26 +11,18 @@ module QA # See: config/initializers/1_settings.rb # Settings#build_gitlab_shell_ssh_path_prefix - def self.parse(git_uri) - if git_uri.start_with?('ssh://') - new(git_uri, URI.parse(git_uri)) + def initialize(git_uri) + @git_uri = git_uri + @uri = if git_uri.start_with?('ssh://') + URI.parse(git_uri) else *rest, path = git_uri.split(':') # Host cannot have : so we'll need to escape it user_host = rest.join('%3A').sub(/\A\[(.+)\]\z/, '\1') - new(git_uri, URI.parse("ssh://#{user_host}/#{path}")) + URI.parse("ssh://#{user_host}/#{path}") end end - def initialize(git_uri, uri) - @git_uri = git_uri - @uri = uri - end - - def scheme - uri.scheme || 'ssh' - end - def port uri.port || 22 end -- cgit v1.2.1 From 2e9b6b533301f2bbf03104e8b27b6e6df0c3dcdf Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 13 Feb 2018 23:45:15 +0800 Subject: Add a comment about why @ is picked for ssh --- qa/qa/page/project/show.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/qa/qa/page/project/show.rb b/qa/qa/page/project/show.rb index 834a36c4bd0..8d4a8c51184 100644 --- a/qa/qa/page/project/show.rb +++ b/qa/qa/page/project/show.rb @@ -26,6 +26,9 @@ module QA end def choose_repository_clone_ssh + # It's not always beginning with ssh:// so detecting with @ + # would be more reliable because ssh would always contain it. + # We can't use .git because HTTP also contain that part. choose_repository_clone('SSH', '@') end -- cgit v1.2.1 From ab4f80329c7cb60a3837737641d7d2ce238b605b Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 13 Feb 2018 23:46:37 +0800 Subject: Inline helper methods --- .../features/project/deploy_key_clone_spec.rb | 38 +++++++--------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/qa/qa/specs/features/project/deploy_key_clone_spec.rb b/qa/qa/specs/features/project/deploy_key_clone_spec.rb index 9b4897a1f96..19d3c83758a 100644 --- a/qa/qa/specs/features/project/deploy_key_clone_spec.rb +++ b/qa/qa/specs/features/project/deploy_key_clone_spec.rb @@ -11,38 +11,41 @@ module QA end end - def fabricate_runner + after do + Service::Runner.new(runner_name).remove! + end + + scenario 'user sets up a deploy key to clone code using pipelines' do + Runtime::Browser.visit(:gitlab, Page::Main::Login) + Page::Main::Login.act { sign_in_using_credentials } + Factory::Resource::Runner.fabricate! do |resource| resource.project = project resource.name = runner_name resource.tags = %w[qa docker] resource.image = 'gitlab/gitlab-runner:ubuntu' end - end - def fabricate_deploy_key Factory::Resource::DeployKey.fabricate! do |resource| resource.project = project resource.title = 'deploy key title' resource.key = key.public_key end - end - def fabricate_secret_variable Factory::Resource::SecretVariable.fabricate! do |resource| resource.project = project resource.key = 'DEPLOY_KEY' resource.value = key.to_pem end - end - def fabricate_gitlab_ci + project.visit! + repository_uri = Page::Project::Show.act do choose_repository_clone_ssh repository_location_uri end - <<~YAML + gitlab_ci = <<~YAML cat-config: script: - mkdir -p ~/.ssh @@ -55,33 +58,14 @@ module QA - qa - docker YAML - end - def fabricate_push(gitlab_ci) Factory::Repository::Push.fabricate! do |resource| resource.project = project resource.file_name = '.gitlab-ci.yml' resource.commit_message = 'Add .gitlab-ci.yml' resource.file_content = gitlab_ci end - end - - after do - Service::Runner.new(runner_name).remove! - end - - scenario 'user sets up a deploy key to clone code using pipelines' do - Runtime::Browser.visit(:gitlab, Page::Main::Login) - Page::Main::Login.act { sign_in_using_credentials } - - fabricate_runner - fabricate_deploy_key - fabricate_secret_variable - - project.visit! - gitlab_ci = fabricate_gitlab_ci - fabricate_push(gitlab_ci) sha1sum = Digest::SHA1.hexdigest(gitlab_ci) Page::Project::Show.act { wait_for_push } -- cgit v1.2.1 From 305c8751c2845dc9c96f654579c7c9063c760534 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 14 Feb 2018 00:59:38 +0800 Subject: Fix the use to Git::Location --- qa/qa/page/project/show.rb | 2 +- qa/spec/git/location_spec.rb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/qa/qa/page/project/show.rb b/qa/qa/page/project/show.rb index 8d4a8c51184..b603557f59c 100644 --- a/qa/qa/page/project/show.rb +++ b/qa/qa/page/project/show.rb @@ -37,7 +37,7 @@ module QA end def repository_location_uri - Git::Repository::Location.parse(repository_location) + Git::Location.new(repository_location) end def project_name diff --git a/qa/spec/git/location_spec.rb b/qa/spec/git/location_spec.rb index 4c68a0cda61..aef906ee836 100644 --- a/qa/spec/git/location_spec.rb +++ b/qa/spec/git/location_spec.rb @@ -1,10 +1,10 @@ describe QA::Git::Location do - describe '.parse' do + describe '.new' do context 'when URI starts with ssh://' do context 'when URI has port' do it 'parses correctly' do uri = described_class - .parse('ssh://git@qa.test:2222/sandbox/qa/repo.git') + .new('ssh://git@qa.test:2222/sandbox/qa/repo.git') expect(uri.user).to eq('git') expect(uri.host).to eq('qa.test') @@ -16,7 +16,7 @@ describe QA::Git::Location do context 'when URI does not have port' do it 'parses correctly' do uri = described_class - .parse('ssh://git@qa.test/sandbox/qa/repo.git') + .new('ssh://git@qa.test/sandbox/qa/repo.git') expect(uri.user).to eq('git') expect(uri.host).to eq('qa.test') @@ -30,7 +30,7 @@ describe QA::Git::Location do context 'when host does not have colons' do it 'parses correctly' do uri = described_class - .parse('git@qa.test:sandbox/qa/repo.git') + .new('git@qa.test:sandbox/qa/repo.git') expect(uri.user).to eq('git') expect(uri.host).to eq('qa.test') @@ -42,7 +42,7 @@ describe QA::Git::Location do context 'when host has a colon' do it 'parses correctly' do uri = described_class - .parse('[git@qa:test]:sandbox/qa/repo.git') + .new('[git@qa:test]:sandbox/qa/repo.git') expect(uri.user).to eq('git') expect(uri.host).to eq('qa%3Atest') -- cgit v1.2.1 From 36c76ec6f2f72d48319e1dc2050850cb393c4959 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 14 Feb 2018 15:27:18 +0800 Subject: Indent as Rubocop like --- qa/qa/git/location.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/qa/qa/git/location.rb b/qa/qa/git/location.rb index 55f7213972d..30538388530 100644 --- a/qa/qa/git/location.rb +++ b/qa/qa/git/location.rb @@ -13,14 +13,15 @@ module QA # Settings#build_gitlab_shell_ssh_path_prefix def initialize(git_uri) @git_uri = git_uri - @uri = if git_uri.start_with?('ssh://') - URI.parse(git_uri) - else - *rest, path = git_uri.split(':') - # Host cannot have : so we'll need to escape it - user_host = rest.join('%3A').sub(/\A\[(.+)\]\z/, '\1') - URI.parse("ssh://#{user_host}/#{path}") - end + @uri = + if git_uri.start_with?('ssh://') + URI.parse(git_uri) + else + *rest, path = git_uri.split(':') + # Host cannot have : so we'll need to escape it + user_host = rest.join('%3A').sub(/\A\[(.+)\]\z/, '\1') + URI.parse("ssh://#{user_host}/#{path}") + end end def port -- cgit v1.2.1