From 9638ecbcbc5b03e65961c21492df378b90a75485 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 4 Feb 2018 04:15:06 -0800 Subject: Add QA specs for LDAP login --- qa/qa.rb | 1 + qa/qa/page/main/login.rb | 17 +++++++++++++++++ qa/qa/scenario/test/integration/ldap.rb | 11 +++++++++++ qa/qa/specs/features/login/ldap_spec.rb | 15 +++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 qa/qa/scenario/test/integration/ldap.rb create mode 100644 qa/qa/specs/features/login/ldap_spec.rb (limited to 'qa') diff --git a/qa/qa.rb b/qa/qa.rb index 8630e2a522c..3a4c2d575f1 100644 --- a/qa/qa.rb +++ b/qa/qa.rb @@ -64,6 +64,7 @@ module QA autoload :Instance, 'qa/scenario/test/instance' module Integration + autoload :Ldap, 'qa/scenario/test/integration/ldap' autoload :Mattermost, 'qa/scenario/test/integration/mattermost' end diff --git a/qa/qa/page/main/login.rb b/qa/qa/page/main/login.rb index 95880475ffa..454573621ce 100644 --- a/qa/qa/page/main/login.rb +++ b/qa/qa/page/main/login.rb @@ -14,12 +14,27 @@ module QA element :sign_in_button, 'submit "Sign in"' end + view 'app/views/devise/sessions/_new_ldap.html.haml' do + element :username_field, 'text_field_tag :username' + element :password_field, 'password_field_tag :password' + element :sign_in_button, 'submit_tag "Sign in"' + end + def initialize wait(max: 500) do page.has_css?('.application') end end + def sign_in_using_ldap_credentials + click_link 'LDAP' + + fill_in :username, with: Runtime::User.name + fill_in :password, with: Runtime::User.password + + click_button 'Sign in' + end + def sign_in_using_credentials using_wait_time 0 do if page.has_content?('Change your password') @@ -28,6 +43,8 @@ module QA click_button 'Change your password' end + click_link 'Standard' if page.has_content?('LDAP') + fill_in :user_login, with: Runtime::User.name fill_in :user_password, with: Runtime::User.password click_button 'Sign in' diff --git a/qa/qa/scenario/test/integration/ldap.rb b/qa/qa/scenario/test/integration/ldap.rb new file mode 100644 index 00000000000..6f68ad9db5c --- /dev/null +++ b/qa/qa/scenario/test/integration/ldap.rb @@ -0,0 +1,11 @@ +module QA + module Scenario + module Test + module Integration + class Ldap < Test::Instance + tags :ldap + end + end + end + end +end diff --git a/qa/qa/specs/features/login/ldap_spec.rb b/qa/qa/specs/features/login/ldap_spec.rb new file mode 100644 index 00000000000..ac2bd5a3c39 --- /dev/null +++ b/qa/qa/specs/features/login/ldap_spec.rb @@ -0,0 +1,15 @@ +module QA + feature 'LDAP user login', :ldap do + scenario 'user logs in using LDAP credentials' do + Runtime::Browser.visit(:gitlab, Page::Main::Login) + Page::Main::Login.act { sign_in_using_ldap_credentials } + + # TODO, since `Signed in successfully` message was removed + # this is the only way to tell if user is signed in correctly. + # + Page::Menu::Main.perform do |menu| + expect(menu).to have_personal_area + end + end + end +end -- cgit v1.2.1 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 (limited to 'qa') 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 3be32027b6c543287b94b5be34bf53039d86f88c Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Tue, 16 Jan 2018 15:13:14 -0600 Subject: Use dynamic variable list in scheduled pipelines and group/project CI secret variables See https://gitlab.com/gitlab-org/gitlab-ce/issues/39118 Conflicts: app/views/ci/variables/_form.html.haml app/views/ci/variables/_table.html.haml ee/app/views/ci/variables/_environment_scope.html.haml spec/javascripts/ci_variable_list/ci_variable_list_ee_spec.js spec/javascripts/fixtures/projects.rb --- qa/qa/factory/resource/secret_variable.rb | 2 +- qa/qa/page/project/settings/secret_variables.rb | 43 ++++++++++--------------- 2 files changed, 18 insertions(+), 27 deletions(-) (limited to 'qa') diff --git a/qa/qa/factory/resource/secret_variable.rb b/qa/qa/factory/resource/secret_variable.rb index 54ef4d8d964..af0fa8af2df 100644 --- a/qa/qa/factory/resource/secret_variable.rb +++ b/qa/qa/factory/resource/secret_variable.rb @@ -31,7 +31,7 @@ module QA page.fill_variable_key(key) page.fill_variable_value(value) - page.add_variable + page.save_variables end end end diff --git a/qa/qa/page/project/settings/secret_variables.rb b/qa/qa/page/project/settings/secret_variables.rb index e3bfbfcf080..fea4acb389a 100644 --- a/qa/qa/page/project/settings/secret_variables.rb +++ b/qa/qa/page/project/settings/secret_variables.rb @@ -5,49 +5,40 @@ module QA class SecretVariables < Page::Base include Common - view 'app/views/ci/variables/_table.html.haml' do - element :variable_key, '.variable-key' - element :variable_value, '.variable-value' + view 'app/views/ci/variables/_variable_row.html.haml' do + element :variable_key, '.js-ci-variable-input-key' + element :variable_value, '.js-ci-variable-input-value' end view 'app/views/ci/variables/_index.html.haml' do - element :add_new_variable, 'btn_text: "Add new variable"' - end - - view 'app/assets/javascripts/behaviors/secret_values.js' do - element :reveal_value, 'Reveal value' - element :hide_value, 'Hide value' + element :save_variables, '.js-secret-variables-save-button' end def fill_variable_key(key) - fill_in 'variable_key', with: key + page.within('.js-ci-variable-list-section .js-row:nth-child(1)') do + page.find('.js-ci-variable-input-key').set(key) + end end def fill_variable_value(value) - fill_in 'variable_value', with: value + page.within('.js-ci-variable-list-section .js-row:nth-child(1)') do + page.find('.js-ci-variable-input-value').set(value) + end end - def add_variable - click_on 'Add new variable' + def save_variables + click_button('Save variables') end def variable_key - page.find('.variable-key').text - end - - def variable_value - reveal_value do - page.find('.variable-value').text + page.within('.js-ci-variable-list-section .js-row:nth-child(1)') do + page.find('.js-ci-variable-input-key').value end end - private - - def reveal_value - click_button('Reveal value') - - yield.tap do - click_button('Hide value') + def variable_value + page.within('.js-ci-variable-list-section .js-row:nth-child(1)') do + page.find('.js-ci-variable-input-value').value end end end -- cgit v1.2.1 From bf0ec00996c37992e101fd4348f205a3ce851f6c Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 31 Jan 2018 10:30:06 -0600 Subject: Expand QA spec file paths to allow running bin/qa from anywhere --- qa/qa/scenario/test/instance.rb | 7 ++++++- qa/qa/specs/runner.rb | 2 +- qa/spec/scenario/test/instance_spec.rb | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'qa') diff --git a/qa/qa/scenario/test/instance.rb b/qa/qa/scenario/test/instance.rb index 993bbd723a3..0af9afd1ea4 100644 --- a/qa/qa/scenario/test/instance.rb +++ b/qa/qa/scenario/test/instance.rb @@ -22,7 +22,12 @@ module QA Specs::Runner.perform do |specs| specs.tty = true specs.tags = self.class.focus - specs.files = files.any? ? files : 'qa/specs/features' + specs.files = + if files.any? + files + else + File.expand_path('../../specs/features', __dir__) + end end end end diff --git a/qa/qa/specs/runner.rb b/qa/qa/specs/runner.rb index 3f7b75df986..752e3e60b8c 100644 --- a/qa/qa/specs/runner.rb +++ b/qa/qa/specs/runner.rb @@ -8,7 +8,7 @@ module QA def initialize @tty = false @tags = [] - @files = ['qa/specs/features'] + @files = [File.expand_path('./features', __dir__)] end def perform diff --git a/qa/spec/scenario/test/instance_spec.rb b/qa/spec/scenario/test/instance_spec.rb index 1824db54c9b..bd09c28e924 100644 --- a/qa/spec/scenario/test/instance_spec.rb +++ b/qa/spec/scenario/test/instance_spec.rb @@ -29,7 +29,8 @@ describe QA::Scenario::Test::Instance do it 'should call runner with default arguments' do subject.perform("test") - expect(runner).to have_received(:files=).with('qa/specs/features') + expect(runner).to have_received(:files=) + .with(File.expand_path('../../../qa/specs/features', __dir__)) end end -- cgit v1.2.1 From 4067b64d3efe32180ee07a8e921f241a9de1eb5e Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 31 Jan 2018 10:38:02 -0600 Subject: Revert "Merge branch 'update-qa-docs-with-directory-req' into 'master'" This reverts commit e6579d82cb87ca5cb94639851482f48a73a2b74f, reversing changes made to afcd9fc7f415dc5a8794ad1ef2498baee08aa825. --- qa/README.md | 3 --- 1 file changed, 3 deletions(-) (limited to 'qa') diff --git a/qa/README.md b/qa/README.md index b937dc4c7a0..3c1b61900d9 100644 --- a/qa/README.md +++ b/qa/README.md @@ -34,9 +34,6 @@ You can use GitLab QA to exercise tests on any live instance! For example, the following call would login to a local [GDK] instance and run all specs in `qa/specs/features`: -First, `cd` into the `$gdk/gitlab/qa` directory. -The `bin/qa` script expects you to be in the `qa` folder of the app. - ``` bin/qa Test::Instance http://localhost:3000 ``` -- cgit v1.2.1 From 739916748d692194c561b7ad07cd33d867079bed Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 6 Feb 2018 16:27:37 -0800 Subject: Address review comments for LDAP QA test --- qa/qa.rb | 2 +- qa/qa/page/main/login.rb | 5 +++++ qa/qa/scenario/test/integration/ldap.rb | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) (limited to 'qa') diff --git a/qa/qa.rb b/qa/qa.rb index 3a4c2d575f1..3c7778a4260 100644 --- a/qa/qa.rb +++ b/qa/qa.rb @@ -64,7 +64,7 @@ module QA autoload :Instance, 'qa/scenario/test/instance' module Integration - autoload :Ldap, 'qa/scenario/test/integration/ldap' + autoload :LDAP, 'qa/scenario/test/integration/ldap' autoload :Mattermost, 'qa/scenario/test/integration/mattermost' end diff --git a/qa/qa/page/main/login.rb b/qa/qa/page/main/login.rb index 454573621ce..0d1ffd9694a 100644 --- a/qa/qa/page/main/login.rb +++ b/qa/qa/page/main/login.rb @@ -20,6 +20,11 @@ module QA element :sign_in_button, 'submit_tag "Sign in"' end + view 'app/views/devise/shared/_tabs_ldap.html.haml' do + element :ldap_tab, "link_to server['label']" + element :standard_tab, "link_to 'Standard'" + end + def initialize wait(max: 500) do page.has_css?('.application') diff --git a/qa/qa/scenario/test/integration/ldap.rb b/qa/qa/scenario/test/integration/ldap.rb index 6f68ad9db5c..257ed81d9e1 100644 --- a/qa/qa/scenario/test/integration/ldap.rb +++ b/qa/qa/scenario/test/integration/ldap.rb @@ -2,7 +2,7 @@ module QA module Scenario module Test module Integration - class Ldap < Test::Instance + class LDAP < Test::Instance tags :ldap end end -- cgit v1.2.1 From 4c45c106a32adedad5dd6c18fe6131ab6e873a68 Mon Sep 17 00:00:00 2001 From: Brett Walker Date: Thu, 8 Feb 2018 15:02:44 +0100 Subject: don't check against a hardcoded user name and use an invalid user name that is random so we know it's invalid --- qa/qa/specs/features/api/users_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qa') diff --git a/qa/qa/specs/features/api/users_spec.rb b/qa/qa/specs/features/api/users_spec.rb index 9d039590a0e..d4ff4ebbc9a 100644 --- a/qa/qa/specs/features/api/users_spec.rb +++ b/qa/qa/specs/features/api/users_spec.rb @@ -14,7 +14,7 @@ module QA end scenario 'submit request with a valid user name' do - get request.url, { params: { username: 'root' } } + get request.url, { params: { username: Runtime::User.name } } expect_status(200) expect(json_body).to be_an Array @@ -23,7 +23,7 @@ module QA end scenario 'submit request with an invalid user name' do - get request.url, { params: { username: 'invalid' } } + get request.url, { params: { username: SecureRandom.hex(10) } } expect_status(200) expect(json_body).to be_an Array -- cgit v1.2.1 From 133b3f20fc60a9294eede7c4233c5272566e580e Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Thu, 8 Feb 2018 22:34:56 +0800 Subject: Allow using a different sandbox group for QA --- qa/README.md | 8 ++++++++ qa/qa/runtime/namespace.rb | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'qa') diff --git a/qa/README.md b/qa/README.md index 3c1b61900d9..29720668251 100644 --- a/qa/README.md +++ b/qa/README.md @@ -70,6 +70,14 @@ If you need to authenticate as a different user, you can provide the GITLAB_USERNAME=jsmith GITLAB_PASSWORD=password bin/qa Test::Instance https://gitlab.example.com ``` +If your user doesn't have permission to default sandbox group +`gitlab-qa-sandbox`, you could also use another sandbox group by giving +`GITLAB_SANDBOX_NAME`: + +``` +GITLAB_USERNAME=jsmith GITLAB_PASSWORD=password GITLAB_SANDBOX_NAME=jsmith-qa-sandbox bin/qa Test::Instance https://gitlab.example.com +``` + All [supported environment variables are here](https://gitlab.com/gitlab-org/gitlab-qa#supported-environment-variables). [GDK]: https://gitlab.com/gitlab-org/gitlab-development-kit/ diff --git a/qa/qa/runtime/namespace.rb b/qa/qa/runtime/namespace.rb index a72c2d21898..2ff5686c78d 100644 --- a/qa/qa/runtime/namespace.rb +++ b/qa/qa/runtime/namespace.rb @@ -16,7 +16,7 @@ module QA end def sandbox_name - 'gitlab-qa-sandbox' + ENV['GITLAB_SANDBOX_NAME'] || 'gitlab-qa-sandbox' end end end -- cgit v1.2.1 From 589f6b1907f1492396e02d12964984e0ed273a00 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Wed, 7 Feb 2018 15:54:23 -0800 Subject: Set initial password for instance in LDAP QA test For a new instance, the root password needs to be set, regardless of whether LDAP is enabled. --- qa/qa/page/main/login.rb | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'qa') diff --git a/qa/qa/page/main/login.rb b/qa/qa/page/main/login.rb index 0d1ffd9694a..fd49b27cb1a 100644 --- a/qa/qa/page/main/login.rb +++ b/qa/qa/page/main/login.rb @@ -31,22 +31,29 @@ module QA end end + def set_initial_password_if_present + if page.has_content?('Change your password') + fill_in :user_password, with: Runtime::User.password + fill_in :user_password_confirmation, with: Runtime::User.password + click_button 'Change your password' + end + end + def sign_in_using_ldap_credentials - click_link 'LDAP' + using_wait_time 0 do + set_initial_password_if_present - fill_in :username, with: Runtime::User.name - fill_in :password, with: Runtime::User.password + click_link 'LDAP' - click_button 'Sign in' + fill_in :username, with: Runtime::User.name + fill_in :password, with: Runtime::User.password + click_button 'Sign in' + end end def sign_in_using_credentials using_wait_time 0 do - if page.has_content?('Change your password') - fill_in :user_password, with: Runtime::User.password - fill_in :user_password_confirmation, with: Runtime::User.password - click_button 'Change your password' - end + set_initial_password_if_present click_link 'Standard' if page.has_content?('LDAP') -- cgit v1.2.1 From 5f62a935c3522517bffb6f4e0f48271dd81a9f39 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 9 Feb 2018 17:25:43 +0800 Subject: Move all ENV to Runtime::Env --- qa/qa/runtime/env.rb | 12 ++++++++++++ qa/qa/runtime/namespace.rb | 2 +- qa/qa/runtime/user.rb | 4 ++-- 3 files changed, 15 insertions(+), 3 deletions(-) (limited to 'qa') diff --git a/qa/qa/runtime/env.rb b/qa/qa/runtime/env.rb index 56944e8b641..115d5ee58d1 100644 --- a/qa/qa/runtime/env.rb +++ b/qa/qa/runtime/env.rb @@ -16,6 +16,18 @@ module QA def personal_access_token ENV['PERSONAL_ACCESS_TOKEN'] end + + def user_username + ENV['GITLAB_USERNAME'] + end + + def user_password + ENV['GITLAB_PASSWORD'] + end + + def sandbox_name + ENV['GITLAB_SANDBOX_NAME'] + end end end end diff --git a/qa/qa/runtime/namespace.rb b/qa/qa/runtime/namespace.rb index 2ff5686c78d..8d05b387416 100644 --- a/qa/qa/runtime/namespace.rb +++ b/qa/qa/runtime/namespace.rb @@ -16,7 +16,7 @@ module QA end def sandbox_name - ENV['GITLAB_SANDBOX_NAME'] || 'gitlab-qa-sandbox' + Runtime::Env.sandbox_name || 'gitlab-qa-sandbox' end end end diff --git a/qa/qa/runtime/user.rb b/qa/qa/runtime/user.rb index 60027c89ab1..6b377f6b287 100644 --- a/qa/qa/runtime/user.rb +++ b/qa/qa/runtime/user.rb @@ -4,11 +4,11 @@ module QA extend self def name - ENV['GITLAB_USERNAME'] || 'root' + Runtime::Env.user_username || 'root' end def password - ENV['GITLAB_PASSWORD'] || '5iveL!fe' + Runtime::Env.user_password || '5iveL!fe' end end end -- cgit v1.2.1 From 27a70018842e1ac130403db319ab013270901e6e Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 9 Feb 2018 12:27:55 +0100 Subject: Do not attach runner to a non-exsiting network in QA --- qa/qa/service/runner.rb | 10 +++++++++- qa/qa/service/shellout.rb | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'qa') diff --git a/qa/qa/service/runner.rb b/qa/qa/service/runner.rb index d0ee33c69f2..c0352e0467a 100644 --- a/qa/qa/service/runner.rb +++ b/qa/qa/service/runner.rb @@ -15,6 +15,14 @@ module QA @tags = %w[qa test] end + def network + shell "docker network inspect #{@network}" + rescue CommandError + 'bridge' + else + @network + end + def pull shell "docker pull #{@image}" end @@ -22,7 +30,7 @@ module QA def register! shell <<~CMD.tr("\n", ' ') docker run -d --rm --entrypoint=/bin/sh - --network #{@network} --name #{@name} + --network #{network} --name #{@name} -e CI_SERVER_URL=#{@address} -e REGISTER_NON_INTERACTIVE=true -e REGISTRATION_TOKEN=#{@token} diff --git a/qa/qa/service/shellout.rb b/qa/qa/service/shellout.rb index 898febde63c..76fb2af6319 100644 --- a/qa/qa/service/shellout.rb +++ b/qa/qa/service/shellout.rb @@ -3,6 +3,8 @@ require 'open3' module QA module Service module Shellout + CommandError = Class.new(StandardError) + ## # TODO, make it possible to use generic QA framework classes # as a library - gitlab-org/gitlab-qa#94 @@ -14,7 +16,7 @@ module QA out.each { |line| puts line } if wait.value.exited? && wait.value.exitstatus.nonzero? - raise "Command `#{command}` failed!" + raise CommandError, "Command `#{command}` failed!" 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(-) (limited to 'qa') 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 (limited to 'qa') 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 d42e68341dd115718c151d81994da19ff4e899b9 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 9 Feb 2018 08:49:10 -0800 Subject: Add documentation on how to build a QA Docker image --- qa/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'qa') diff --git a/qa/README.md b/qa/README.md index 29720668251..44f3e262f4d 100644 --- a/qa/README.md +++ b/qa/README.md @@ -80,4 +80,14 @@ GITLAB_USERNAME=jsmith GITLAB_PASSWORD=password GITLAB_SANDBOX_NAME=jsmith-qa-sa All [supported environment variables are here](https://gitlab.com/gitlab-org/gitlab-qa#supported-environment-variables). +### Building a Docker image to test + +Once you have made changes to the CE/EE repositories, you may want to build a +Docker image to test locally instead of waiting for the `gitlab-ce-qa` or +`gitlab-ee-qa` nightly builds. To do that, you can run from this directory: + +```sh +docker build -t gitlab/gitlab-ce-qa:nightly . +``` + [GDK]: https://gitlab.com/gitlab-org/gitlab-development-kit/ -- cgit v1.2.1 From dc8cf732078dc03af52e4821683ea1c04946091e Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sat, 10 Feb 2018 14:20:44 -0800 Subject: GitLab QA: Add GITLAB_USER_TYPE to support different login types (e.g. standard, LDAP) GITLAB_USERNAME and GITLAB_PASSWORD may be specified for an LDAP login, but QA scenarios may need to know which type it is in order to log in successfully. --- qa/README.md | 6 ++++++ qa/qa/page/main/login.rb | 10 +++++++++- qa/qa/runtime/env.rb | 10 ++++++++++ qa/qa/runtime/user.rb | 4 ++++ qa/spec/runtime/env_spec.rb | 21 +++++++++++++++++++++ 5 files changed, 50 insertions(+), 1 deletion(-) (limited to 'qa') diff --git a/qa/README.md b/qa/README.md index 44f3e262f4d..3a99a30d379 100644 --- a/qa/README.md +++ b/qa/README.md @@ -78,6 +78,12 @@ If your user doesn't have permission to default sandbox group GITLAB_USERNAME=jsmith GITLAB_PASSWORD=password GITLAB_SANDBOX_NAME=jsmith-qa-sandbox bin/qa Test::Instance https://gitlab.example.com ``` +In addition, the `GITLAB_USER_TYPE` can be set to "ldap" to sign in as an LDAP user: + +``` +GITLAB_USER_TYPE=ldap GITLAB_USERNAME=jsmith GITLAB_PASSWORD=password GITLAB_SANDBOX_NAME=jsmith-qa-sandbox bin/qa Test::Instance https://gitlab.example.com +``` + All [supported environment variables are here](https://gitlab.com/gitlab-org/gitlab-qa#supported-environment-variables). ### Building a Docker image to test diff --git a/qa/qa/page/main/login.rb b/qa/qa/page/main/login.rb index fd49b27cb1a..a8a5601dbe6 100644 --- a/qa/qa/page/main/login.rb +++ b/qa/qa/page/main/login.rb @@ -39,6 +39,14 @@ module QA end end + def sign_in_using_credentials + if Runtime::User.ldap_user? + sign_in_using_ldap_credentials + else + sign_in_using_gitlab_credentials + end + end + def sign_in_using_ldap_credentials using_wait_time 0 do set_initial_password_if_present @@ -51,7 +59,7 @@ module QA end end - def sign_in_using_credentials + def sign_in_using_gitlab_credentials using_wait_time 0 do set_initial_password_if_present diff --git a/qa/qa/runtime/env.rb b/qa/qa/runtime/env.rb index 115d5ee58d1..5401372e225 100644 --- a/qa/qa/runtime/env.rb +++ b/qa/qa/runtime/env.rb @@ -17,6 +17,16 @@ module QA ENV['PERSONAL_ACCESS_TOKEN'] end + # By default, "standard" denotes a standard GitLab user login. + # Set this to "ldap" if the user should be logged in via LDAP. + def user_type + (ENV['GITLAB_USER_TYPE'] || 'standard').tap do |type| + unless %w(ldap standard).include?(type) + raise ArgumentError.new("Invalid user type '#{type}': must be 'ldap' or 'standard'") + end + end + end + def user_username ENV['GITLAB_USERNAME'] end diff --git a/qa/qa/runtime/user.rb b/qa/qa/runtime/user.rb index 6b377f6b287..39e6adf9522 100644 --- a/qa/qa/runtime/user.rb +++ b/qa/qa/runtime/user.rb @@ -10,6 +10,10 @@ module QA def password Runtime::Env.user_password || '5iveL!fe' end + + def ldap_user? + Runtime::Env.user_type == 'ldap' + end end end end diff --git a/qa/spec/runtime/env_spec.rb b/qa/spec/runtime/env_spec.rb index 103573db6be..2b6365dbc41 100644 --- a/qa/spec/runtime/env_spec.rb +++ b/qa/spec/runtime/env_spec.rb @@ -55,4 +55,25 @@ describe QA::Runtime::Env do end end end + + describe '.user_type' do + it 'returns standard if not defined' do + expect(described_class.user_type).to eq('standard') + end + + it 'returns standard as defined' do + stub_env('GITLAB_USER_TYPE', 'standard') + expect(described_class.user_type).to eq('standard') + end + + it 'returns ldap as defined' do + stub_env('GITLAB_USER_TYPE', 'ldap') + expect(described_class.user_type).to eq('ldap') + end + + it 'returns an error if invalid user type' do + stub_env('GITLAB_USER_TYPE', 'foobar') + expect { described_class.user_type }.to raise_error(ArgumentError) + end + end end -- 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 (limited to 'qa') 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 (limited to 'qa') 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(-) (limited to 'qa') 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 (limited to 'qa') 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 68a2ddd1495b6c6b5fd56018f50eecc553e14562 Mon Sep 17 00:00:00 2001 From: Michael Kozono Date: Mon, 12 Feb 2018 20:42:16 -0800 Subject: Fix artifact creation --- qa/qa/specs/features/project/pipelines_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'qa') diff --git a/qa/qa/specs/features/project/pipelines_spec.rb b/qa/qa/specs/features/project/pipelines_spec.rb index 1bb7730e06c..74f6474443d 100644 --- a/qa/qa/specs/features/project/pipelines_spec.rb +++ b/qa/qa/specs/features/project/pipelines_spec.rb @@ -69,7 +69,7 @@ module QA tags: - qa - test - script: echo "CONTENTS" > my-artifacts/artifact.txt + script: mkdir my-artifacts; echo "CONTENTS" > my-artifacts/artifact.txt artifacts: paths: - my-artifacts/ @@ -95,7 +95,7 @@ module QA expect(pipeline).to have_build('test-success', status: :success) expect(pipeline).to have_build('test-failure', status: :failed) expect(pipeline).to have_build('test-tags', status: :pending) - expect(pipeline).to have_build('test-artifacts', status: :failed) + expect(pipeline).to have_build('test-artifacts', status: :success) 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 (limited to 'qa') 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(-) (limited to 'qa') 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(+) (limited to 'qa') 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(-) (limited to 'qa') 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(-) (limited to 'qa') 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(-) (limited to 'qa') 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 From 104d5af8ba63aa5c284c260dc207e7ddb9e1a918 Mon Sep 17 00:00:00 2001 From: Felipe Artur Date: Wed, 14 Feb 2018 11:53:37 -0200 Subject: Wait for create merge request button to appear --- qa/qa/page/project/show.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'qa') diff --git a/qa/qa/page/project/show.rb b/qa/qa/page/project/show.rb index b603557f59c..0c7ad46d36b 100644 --- a/qa/qa/page/project/show.rb +++ b/qa/qa/page/project/show.rb @@ -45,6 +45,10 @@ module QA end def new_merge_request + wait(reload: true) do + has_css?(element_selector_css(:create_merge_request)) + end + click_element :create_merge_request end -- cgit v1.2.1 From d6fd2f5b0f8e54ea36118d5cf6a6abce9d623188 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 8 Feb 2018 10:09:51 -0600 Subject: Add Runtime::User.default_name --- qa/qa/runtime/user.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'qa') diff --git a/qa/qa/runtime/user.rb b/qa/qa/runtime/user.rb index 39e6adf9522..ecc9ab321ba 100644 --- a/qa/qa/runtime/user.rb +++ b/qa/qa/runtime/user.rb @@ -3,8 +3,12 @@ module QA module User extend self + def default_name + 'root' + end + def name - Runtime::Env.user_username || 'root' + Runtime::Env.user_username || default_name end def password -- cgit v1.2.1 From 8bf5203bdc9d5953d73473809b65ba4166dc9913 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 8 Feb 2018 10:11:04 -0600 Subject: Suppress git output when running QA as a non-default user --- qa/qa/git/repository.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'qa') diff --git a/qa/qa/git/repository.rb b/qa/qa/git/repository.rb index 8eb7031f609..4c4ef3ef477 100644 --- a/qa/qa/git/repository.rb +++ b/qa/qa/git/repository.rb @@ -33,7 +33,7 @@ module QA end def clone(opts = '') - `git clone #{opts} #{@uri.to_s} ./` + `git clone #{opts} #{@uri.to_s} ./ #{suppress_output}` end def shallow_clone @@ -61,12 +61,22 @@ module QA end def push_changes(branch = 'master') - `git push #{@uri.to_s} #{branch}` + `git push #{@uri.to_s} #{branch} #{suppress_output}` end def commits `git log --oneline`.split("\n") end + + private + + def suppress_output + # If we're running as the default user, it's probably a temporary + # instance and output can be useful for debugging + return if @username == Runtime::User.default_name + + "&> #{File::NULL}" + end end end end -- cgit v1.2.1 From 07b6ad351a966eed6ed4ae60145def2d8ab60ac7 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Wed, 14 Feb 2018 21:27:06 -0800 Subject: Add LDAP_USERNAME and LDAP_PASSWORD user environment variables for QA --- qa/qa/page/main/login.rb | 4 ++-- qa/qa/runtime/env.rb | 8 ++++++++ qa/qa/runtime/user.rb | 8 ++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) (limited to 'qa') diff --git a/qa/qa/page/main/login.rb b/qa/qa/page/main/login.rb index a8a5601dbe6..596205fe540 100644 --- a/qa/qa/page/main/login.rb +++ b/qa/qa/page/main/login.rb @@ -53,8 +53,8 @@ module QA click_link 'LDAP' - fill_in :username, with: Runtime::User.name - fill_in :password, with: Runtime::User.password + fill_in :username, with: Runtime::User.ldap_username + fill_in :password, with: Runtime::User.ldap_password click_button 'Sign in' end end diff --git a/qa/qa/runtime/env.rb b/qa/qa/runtime/env.rb index 5401372e225..fe432edfa2a 100644 --- a/qa/qa/runtime/env.rb +++ b/qa/qa/runtime/env.rb @@ -35,6 +35,14 @@ module QA ENV['GITLAB_PASSWORD'] end + def ldap_username + ENV['GITLAB_LDAP_USERNAME'] + end + + def ldap_password + ENV['GITLAB_LDAP_PASSWORD'] + end + def sandbox_name ENV['GITLAB_SANDBOX_NAME'] end diff --git a/qa/qa/runtime/user.rb b/qa/qa/runtime/user.rb index ecc9ab321ba..c80ee6d4d96 100644 --- a/qa/qa/runtime/user.rb +++ b/qa/qa/runtime/user.rb @@ -18,6 +18,14 @@ module QA def ldap_user? Runtime::Env.user_type == 'ldap' end + + def ldap_username + Runtime::Env.ldap_username || name + end + + def ldap_password + Runtime::Env.ldap_password || password + end end end end -- cgit v1.2.1