diff options
Diffstat (limited to 'spec/requests/api/ci')
15 files changed, 262 insertions, 54 deletions
diff --git a/spec/requests/api/ci/job_artifacts_spec.rb b/spec/requests/api/ci/job_artifacts_spec.rb index b96ba356855..a8c09a5191d 100644 --- a/spec/requests/api/ci/job_artifacts_spec.rb +++ b/spec/requests/api/ci/job_artifacts_spec.rb @@ -187,7 +187,7 @@ RSpec.describe API::Ci::JobArtifacts, feature_category: :build_artifacts do end context 'when project is public with artifacts that are non public' do - let(:job) { create(:ci_build, :artifacts, :with_private_artifacts_config, pipeline: pipeline) } + let(:job) { create(:ci_build, :private_artifacts, :with_private_artifacts_config, pipeline: pipeline) } it 'rejects access to artifacts' do project.update_column(:visibility_level, Gitlab::VisibilityLevel::PUBLIC) @@ -197,21 +197,6 @@ RSpec.describe API::Ci::JobArtifacts, feature_category: :build_artifacts do expect(response).to have_gitlab_http_status(:forbidden) end - - context 'with the non_public_artifacts feature flag disabled' do - before do - stub_feature_flags(non_public_artifacts: false) - end - - it 'allows access to artifacts' do - project.update_column(:visibility_level, Gitlab::VisibilityLevel::PUBLIC) - project.update_column(:public_builds, true) - - get_artifact_file(artifact) - - expect(response).to have_gitlab_http_status(:ok) - end - end end context 'when project is public with builds access disabled' do @@ -433,7 +418,7 @@ RSpec.describe API::Ci::JobArtifacts, feature_category: :build_artifacts do context 'when public project guest and artifacts are non public' do let(:api_user) { guest } - let(:job) { create(:ci_build, :artifacts, :with_private_artifacts_config, pipeline: pipeline) } + let(:job) { create(:ci_build, :private_artifacts, :with_private_artifacts_config, pipeline: pipeline) } before do project.update_column(:visibility_level, @@ -445,17 +430,6 @@ RSpec.describe API::Ci::JobArtifacts, feature_category: :build_artifacts do it 'rejects access and hides existence of artifacts' do expect(response).to have_gitlab_http_status(:forbidden) end - - context 'with the non_public_artifacts feature flag disabled' do - before do - stub_feature_flags(non_public_artifacts: false) - get api("/projects/#{project.id}/jobs/#{job.id}/artifacts", api_user) - end - - it 'allows access to artifacts' do - expect(response).to have_gitlab_http_status(:ok) - end - end end it 'does not return job artifacts if not uploaded' do @@ -639,7 +613,7 @@ RSpec.describe API::Ci::JobArtifacts, feature_category: :build_artifacts do end context 'when project is public with non public artifacts' do - let(:job) { create(:ci_build, :artifacts, :with_private_artifacts_config, pipeline: pipeline, user: api_user) } + let(:job) { create(:ci_build, :private_artifacts, :with_private_artifacts_config, pipeline: pipeline, user: api_user) } let(:visibility_level) { Gitlab::VisibilityLevel::PUBLIC } let(:public_builds) { true } @@ -651,18 +625,6 @@ RSpec.describe API::Ci::JobArtifacts, feature_category: :build_artifacts do expect(response.headers.to_h) .not_to include('Gitlab-Workhorse-Send-Data' => /artifacts-entry/) end - - context 'with the non_public_artifacts feature flag disabled' do - before do - stub_feature_flags(non_public_artifacts: false) - end - - it 'allows access to artifacts', :sidekiq_might_not_need_inline do - get_artifact_file(artifact) - - expect(response).to have_gitlab_http_status(:ok) - end - end end context 'when project is private' do diff --git a/spec/requests/api/ci/pipeline_schedules_spec.rb b/spec/requests/api/ci/pipeline_schedules_spec.rb index a4bb379d01c..f534b093b7c 100644 --- a/spec/requests/api/ci/pipeline_schedules_spec.rb +++ b/spec/requests/api/ci/pipeline_schedules_spec.rb @@ -241,7 +241,7 @@ RSpec.describe API::Ci::PipelineSchedules, feature_category: :continuous_integra let(:url) { "/projects/#{project.id}/pipeline_schedules/#{pipeline_schedule.id}/pipelines" } matcher :return_pipeline_schedule_pipelines_successfully do - match_unless_raises do |reponse| + match_unless_raises do |response| expect(response).to have_gitlab_http_status(:ok) expect(response).to include_pagination_headers expect(response).to match_response_schema('public_api/v4/pipelines') diff --git a/spec/requests/api/ci/runner/jobs_request_post_spec.rb b/spec/requests/api/ci/runner/jobs_request_post_spec.rb index 2a870a25ea6..3d6d86335eb 100644 --- a/spec/requests/api/ci/runner/jobs_request_post_spec.rb +++ b/spec/requests/api/ci/runner/jobs_request_post_spec.rb @@ -272,16 +272,19 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_catego expect(json_response['job_info']).to include(expected_job_info) expect(json_response['git_info']).to eq(expected_git_info) expect(json_response['image']).to eq( - { 'name' => 'image:1.0', 'entrypoint' => '/bin/sh', 'ports' => [], 'pull_policy' => nil } + { 'name' => 'image:1.0', 'entrypoint' => '/bin/sh', 'ports' => [], 'executor_opts' => {}, + 'pull_policy' => nil } ) expect(json_response['services']).to eq( [ { 'name' => 'postgres', 'entrypoint' => nil, 'alias' => nil, 'command' => nil, 'ports' => [], - 'variables' => nil, 'pull_policy' => nil }, - { 'name' => 'docker:stable-dind', 'entrypoint' => '/bin/sh', 'alias' => 'docker', 'command' => 'sleep 30', - 'ports' => [], 'variables' => [], 'pull_policy' => nil }, + 'variables' => nil, 'executor_opts' => {}, 'pull_policy' => nil }, + { 'name' => 'docker:stable-dind', 'entrypoint' => '/bin/sh', 'alias' => 'docker', + 'command' => 'sleep 30', 'ports' => [], 'variables' => [], 'executor_opts' => {}, + 'pull_policy' => nil }, { 'name' => 'mysql:latest', 'entrypoint' => nil, 'alias' => nil, 'command' => nil, 'ports' => [], - 'variables' => [{ 'key' => 'MYSQL_ROOT_PASSWORD', 'value' => 'root123.' }], 'pull_policy' => nil } + 'variables' => [{ 'key' => 'MYSQL_ROOT_PASSWORD', 'value' => 'root123.' }], 'executor_opts' => {}, + 'pull_policy' => nil } ]) expect(json_response['steps']).to eq(expected_steps) expect(json_response['hooks']).to eq(expected_hooks) @@ -920,6 +923,41 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_catego end end + context 'when image has docker options' do + let(:job) { create(:ci_build, :pending, :queued, pipeline: pipeline, options: options) } + + let(:options) do + { + image: { + name: 'ruby', + executor_opts: { + docker: { + platform: 'amd64' + } + } + } + } + end + + it 'returns the image with docker options' do + request_job + + expect(response).to have_gitlab_http_status(:created) + expect(json_response).to include( + 'id' => job.id, + 'image' => { 'name' => 'ruby', + 'executor_opts' => { + 'docker' => { + 'platform' => 'amd64' + } + }, + 'pull_policy' => nil, + 'entrypoint' => nil, + 'ports' => [] } + ) + end + end + context 'when image has pull_policy' do let(:job) { create(:ci_build, :pending, :queued, pipeline: pipeline, options: options) } @@ -938,7 +976,11 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_catego expect(response).to have_gitlab_http_status(:created) expect(json_response).to include( 'id' => job.id, - 'image' => { 'name' => 'ruby', 'pull_policy' => ['if-not-present'], 'entrypoint' => nil, 'ports' => [] } + 'image' => { 'name' => 'ruby', + 'executor_opts' => {}, + 'pull_policy' => ['if-not-present'], + 'entrypoint' => nil, + 'ports' => [] } ) end end @@ -962,7 +1004,8 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_catego expect(json_response).to include( 'id' => job.id, 'services' => [{ 'alias' => nil, 'command' => nil, 'entrypoint' => nil, 'name' => 'postgres:11.9', - 'ports' => [], 'pull_policy' => ['if-not-present'], 'variables' => [] }] + 'ports' => [], 'executor_opts' => {}, 'pull_policy' => ['if-not-present'], + 'variables' => [] }] ) end end diff --git a/spec/requests/api/ci/runner/jobs_request_yamls_spec.rb b/spec/requests/api/ci/runner/jobs_request_yamls_spec.rb new file mode 100644 index 00000000000..f399c3e310e --- /dev/null +++ b/spec/requests/api/ci/runner/jobs_request_yamls_spec.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_category: :continuous_integration do + include StubGitlabCalls + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository, shared_runners_enabled: false) } + let_it_be(:runner) { create(:ci_runner, :project, projects: [project]) } + + let(:user_agent) { 'gitlab-runner 9.0.0 (9-0-stable; go1.7.4; linux/amd64)' } + + before_all do + project.add_maintainer(user) + end + + Dir[Rails.root.join("spec/requests/api/ci/runner/yamls/*.yml")].each do |yml_file| + context "for #{File.basename(yml_file)}" do + let(:yaml_content) { YAML.load_file(yml_file) } + let(:gitlab_ci_yml) { yaml_content.fetch("gitlab_ci") } + let(:request_response) { yaml_content.fetch("request_response") } + + it 'runs a job' do + stub_ci_pipeline_yaml_file(YAML.dump(gitlab_ci_yml)) + + pipeline_response = create_pipeline! + expect(pipeline_response).to be_success, pipeline_response.message + expect(pipeline_response.payload).to be_created_successfully + expect(pipeline_response.payload.builds).to be_one + + build = pipeline_response.payload.builds.first + + process_pipeline!(pipeline_response.payload) + expect(build.reload).to be_pending + + request_job(runner.token) + expect(response).to have_gitlab_http_status(:created) + expect(response.headers['Content-Type']).to eq('application/json') + expect(json_response).to include('id' => build.id, 'token' => build.token) + expect(json_response).to include(request_response) + end + end + end + + def create_pipeline! + params = { ref: 'master', + before: '00000000', + after: project.commit.id, + commits: [{ message: 'some commit' }] } + + Ci::CreatePipelineService.new(project, user, params).execute(:push) + end + + def process_pipeline!(pipeline) + PipelineProcessWorker.new.perform(pipeline.id) + end + + def request_job(token, **params) + new_params = params.merge(token: token) + post api('/jobs/request'), params: new_params.to_json, + headers: { 'User-Agent' => user_agent, 'Content-Type': 'application/json' } + end +end diff --git a/spec/requests/api/ci/runner/runners_delete_spec.rb b/spec/requests/api/ci/runner/runners_delete_spec.rb index d1488828bad..61420afd578 100644 --- a/spec/requests/api/ci/runner/runners_delete_spec.rb +++ b/spec/requests/api/ci/runner/runners_delete_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_category: :runner_fleet do +RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_category: :fleet_visibility do include StubGitlabCalls include RedisHelpers include WorkhorseHelpers diff --git a/spec/requests/api/ci/runner/runners_post_spec.rb b/spec/requests/api/ci/runner/runners_post_spec.rb index 1490172d1c3..748efe3cd54 100644 --- a/spec/requests/api/ci/runner/runners_post_spec.rb +++ b/spec/requests/api/ci/runner/runners_post_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_category: :runner_fleet do +RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_category: :fleet_visibility do describe '/api/v4/runners' do describe 'POST /api/v4/runners' do it_behaves_like 'runner migrations backoff' do diff --git a/spec/requests/api/ci/runner/runners_reset_spec.rb b/spec/requests/api/ci/runner/runners_reset_spec.rb index 03cb6238fc1..92de1276dbb 100644 --- a/spec/requests/api/ci/runner/runners_reset_spec.rb +++ b/spec/requests/api/ci/runner/runners_reset_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_category: :runner_fleet do +RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state, feature_category: :fleet_visibility do include StubGitlabCalls include RedisHelpers include WorkhorseHelpers diff --git a/spec/requests/api/ci/runner/yamls/README.md b/spec/requests/api/ci/runner/yamls/README.md new file mode 100644 index 00000000000..db8ef51ff9c --- /dev/null +++ b/spec/requests/api/ci/runner/yamls/README.md @@ -0,0 +1,15 @@ +# .gitlab-ci.yml end-to-end tests + +The purpose of this folder is to provide a single job `.gitlab-ci.yml` +that will be validated against end-to-end response that is send to runner. + +This allows to easily test end-to-end all CI job transformation that +and impact on how such job is rendered to be executed by the GitLab Runner. + +```yaml +gitlab_ci: + # .gitlab-ci.yml to stub + +request_response: + # exact payload that is checked as returned by `/api/v4/jobs/request` +``` diff --git a/spec/requests/api/ci/runner/yamls/image-basic.yml b/spec/requests/api/ci/runner/yamls/image-basic.yml new file mode 100644 index 00000000000..0c01dbc6e8b --- /dev/null +++ b/spec/requests/api/ci/runner/yamls/image-basic.yml @@ -0,0 +1,19 @@ +gitlab_ci: + rspec: + image: alpine:latest + script: echo Hello World + +request_response: + image: + name: alpine:latest + entrypoint: null + executor_opts: {} + ports: [] + pull_policy: null + steps: + - name: script + script: ["echo Hello World"] + timeout: 3600 + when: on_success + allow_failure: false + services: [] diff --git a/spec/requests/api/ci/runner/yamls/image-executor_opts-platform.yml b/spec/requests/api/ci/runner/yamls/image-executor_opts-platform.yml new file mode 100644 index 00000000000..62e301f2e9a --- /dev/null +++ b/spec/requests/api/ci/runner/yamls/image-executor_opts-platform.yml @@ -0,0 +1,25 @@ +gitlab_ci: + rspec: + image: + name: alpine:latest + docker: + platform: amd64 + script: echo Hello World + +request_response: + image: + name: alpine:latest + entrypoint: null + executor_opts: + docker: + platform: amd64 + ports: [] + pull_policy: null + steps: + - name: script + script: ["echo Hello World"] + timeout: 3600 + when: on_success + allow_failure: false + services: [] + diff --git a/spec/requests/api/ci/runner/yamls/service-basic.yml b/spec/requests/api/ci/runner/yamls/service-basic.yml new file mode 100644 index 00000000000..5438837c496 --- /dev/null +++ b/spec/requests/api/ci/runner/yamls/service-basic.yml @@ -0,0 +1,23 @@ +gitlab_ci: + rspec: + services: + - docker:dind + script: echo Hello World + +request_response: + image: null + steps: + - name: script + script: ["echo Hello World"] + timeout: 3600 + when: on_success + allow_failure: false + services: + - name: docker:dind + alias: null + command: null + entrypoint: null + executor_opts: {} + ports: [] + pull_policy: null + variables: [] diff --git a/spec/requests/api/ci/runner/yamls/service-executor_opts-platform.yml b/spec/requests/api/ci/runner/yamls/service-executor_opts-platform.yml new file mode 100644 index 00000000000..6483d749c45 --- /dev/null +++ b/spec/requests/api/ci/runner/yamls/service-executor_opts-platform.yml @@ -0,0 +1,27 @@ +gitlab_ci: + rspec: + services: + - name: docker:dind + docker: + platform: amd64 + script: echo Hello World + +request_response: + image: null + steps: + - name: script + script: ["echo Hello World"] + timeout: 3600 + when: on_success + allow_failure: false + services: + - name: docker:dind + alias: null + command: null + entrypoint: null + executor_opts: + docker: + platform: amd64 + ports: [] + pull_policy: null + variables: [] diff --git a/spec/requests/api/ci/runner/yamls/service-variables.yml b/spec/requests/api/ci/runner/yamls/service-variables.yml new file mode 100644 index 00000000000..c8e4dde674b --- /dev/null +++ b/spec/requests/api/ci/runner/yamls/service-variables.yml @@ -0,0 +1,30 @@ +gitlab_ci: + rspec: + services: + - name: docker:dind + variables: + DOCKER_HOST: tcp://docker:2375 + DOCKER_DRIVER: overlay2 + script: echo Hello World + +request_response: + image: null + steps: + - name: script + script: ["echo Hello World"] + timeout: 3600 + when: on_success + allow_failure: false + services: + - name: docker:dind + alias: null + command: null + entrypoint: null + executor_opts: {} + ports: [] + pull_policy: null + variables: + - key: DOCKER_HOST + value: tcp://docker:2375 + - key: DOCKER_DRIVER + value: overlay2 diff --git a/spec/requests/api/ci/runners_reset_registration_token_spec.rb b/spec/requests/api/ci/runners_reset_registration_token_spec.rb index 98edde93e95..0b6a6abf419 100644 --- a/spec/requests/api/ci/runners_reset_registration_token_spec.rb +++ b/spec/requests/api/ci/runners_reset_registration_token_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe API::Ci::Runners, feature_category: :runner_fleet do +RSpec.describe API::Ci::Runners, feature_category: :fleet_visibility do let_it_be(:admin_mode) { false } subject { post api("#{prefix}/runners/reset_registration_token", user, admin_mode: admin_mode) } diff --git a/spec/requests/api/ci/runners_spec.rb b/spec/requests/api/ci/runners_spec.rb index ba80684e89e..187880e16a4 100644 --- a/spec/requests/api/ci/runners_spec.rb +++ b/spec/requests/api/ci/runners_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe API::Ci::Runners, :aggregate_failures, feature_category: :runner_fleet do +RSpec.describe API::Ci::Runners, :aggregate_failures, feature_category: :fleet_visibility do let_it_be(:admin) { create(:user, :admin) } let_it_be(:user) { create(:user) } let_it_be(:user2) { create(:user) } |