diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-17 03:07:45 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-17 03:07:45 +0000 |
commit | 9763c081708e4c2e08de1f4e9ca9abdef5cffe3c (patch) | |
tree | b27794ba1a039cdc42cdf5d90bcb7b7503437324 /spec | |
parent | 7480d774dfca97ea905321d52c70fd19496f0084 (diff) | |
download | gitlab-ce-9763c081708e4c2e08de1f4e9ca9abdef5cffe3c.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/initializers/database_config_spec.rb | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/auth/auth_finders_spec.rb | 66 | ||||
-rw-r--r-- | spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb | 27 | ||||
-rw-r--r-- | spec/lib/gitlab/gitaly_client_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/gpg_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/health_checks/puma_check_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/health_checks/unicorn_check_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/highlight_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/samplers/influx_sampler_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/runtime_spec.rb | 112 | ||||
-rw-r--r-- | spec/lib/prometheus/pid_provider_spec.rb | 18 | ||||
-rw-r--r-- | spec/services/git/branch_push_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/support/helpers/kubernetes_helpers.rb | 4 | ||||
-rw-r--r-- | spec/support/redis/redis_shared_examples.rb | 4 |
14 files changed, 107 insertions, 143 deletions
diff --git a/spec/initializers/database_config_spec.rb b/spec/initializers/database_config_spec.rb index 9200a625b38..a5a074f5884 100644 --- a/spec/initializers/database_config_spec.rb +++ b/spec/initializers/database_config_spec.rb @@ -16,7 +16,6 @@ describe 'Database config initializer' do let(:puma_options) { { max_threads: 8 } } before do - allow(Gitlab::Runtime).to receive(:puma?).and_return(true) stub_const("Puma", puma) allow(puma).to receive_message_chain(:cli_config, :options).and_return(puma_options) end diff --git a/spec/lib/gitlab/auth/auth_finders_spec.rb b/spec/lib/gitlab/auth/auth_finders_spec.rb index 3d10f411310..82ff8e7f76c 100644 --- a/spec/lib/gitlab/auth/auth_finders_spec.rb +++ b/spec/lib/gitlab/auth/auth_finders_spec.rb @@ -335,6 +335,72 @@ describe Gitlab::Auth::AuthFinders do end end + describe '#find_user_from_basic_auth_job' do + def basic_http_auth(username, password) + ActionController::HttpAuthentication::Basic.encode_credentials(username, password) + end + + def set_auth(username, password) + env['HTTP_AUTHORIZATION'] = basic_http_auth(username, password) + end + + subject { find_user_from_basic_auth_job } + + context 'when the request does not have AUTHORIZATION header' do + it { is_expected.to be_nil } + end + + context 'with wrong credentials' do + it 'returns nil without user and password' do + set_auth(nil, nil) + + is_expected.to be_nil + end + + it 'returns nil without password' do + set_auth('some-user', nil) + + is_expected.to be_nil + end + + it 'returns nil without user' do + set_auth(nil, 'password') + + is_expected.to be_nil + end + + it 'returns nil without CI username' do + set_auth('user', 'password') + + is_expected.to be_nil + end + end + + context 'with CI username' do + let(:username) { ::Ci::Build::CI_REGISTRY_USER } + let(:user) { create(:user) } + let(:build) { create(:ci_build, user: user) } + + it 'returns nil without password' do + set_auth(username, nil) + + is_expected.to be_nil + end + + it 'returns user with valid token' do + set_auth(username, build.token) + + is_expected.to eq user + end + + it 'raises error with invalid token' do + set_auth(username, 'token') + + expect { subject }.to raise_error(Gitlab::Auth::UnauthorizedError) + end + end + end + describe '#validate_access_token!' do let(:personal_access_token) { create(:personal_access_token, user: user) } diff --git a/spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb b/spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb index b3826666b18..0f68201a153 100644 --- a/spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb +++ b/spec/lib/gitlab/database/obsolete_ignored_columns_spec.rb @@ -4,6 +4,9 @@ require 'spec_helper' describe Gitlab::Database::ObsoleteIgnoredColumns do module Testing + # Used a fixed date to prevent tests failing across date boundaries + REMOVE_DATE = Date.new(2019, 12, 16) + class MyBase < ApplicationRecord end @@ -23,12 +26,12 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do self.table_name = 'issues' ignore_column :id, :other, remove_after: '2019-01-01', remove_with: '12.0' - ignore_column :not_used_but_still_ignored, remove_after: Date.today.to_s, remove_with: '12.1' + ignore_column :not_used_but_still_ignored, remove_after: REMOVE_DATE.to_s, remove_with: '12.1' end class A < SomeAbstract ignore_column :also_unused, remove_after: '2019-02-01', remove_with: '12.1' - ignore_column :not_used_but_still_ignored, remove_after: Date.today.to_s, remove_with: '12.1' + ignore_column :not_used_but_still_ignored, remove_after: REMOVE_DATE.to_s, remove_with: '12.1' end class C < MyBase @@ -40,15 +43,17 @@ describe Gitlab::Database::ObsoleteIgnoredColumns do describe '#execute' do it 'returns a list of class names and columns pairs' do - expect(subject.execute).to eq([ - ['Testing::A', { - 'unused' => IgnorableColumns::ColumnIgnore.new(Date.parse('2019-01-01'), '12.0'), - 'also_unused' => IgnorableColumns::ColumnIgnore.new(Date.parse('2019-02-01'), '12.1') - }], - ['Testing::B', { - 'other' => IgnorableColumns::ColumnIgnore.new(Date.parse('2019-01-01'), '12.0') - }] - ]) + Timecop.freeze(Testing::REMOVE_DATE) do + expect(subject.execute).to eq([ + ['Testing::A', { + 'unused' => IgnorableColumns::ColumnIgnore.new(Date.parse('2019-01-01'), '12.0'), + 'also_unused' => IgnorableColumns::ColumnIgnore.new(Date.parse('2019-02-01'), '12.1') + }], + ['Testing::B', { + 'other' => IgnorableColumns::ColumnIgnore.new(Date.parse('2019-01-01'), '12.0') + }] + ]) + end end end end diff --git a/spec/lib/gitlab/gitaly_client_spec.rb b/spec/lib/gitlab/gitaly_client_spec.rb index 0d9719a5663..4b69b4734f1 100644 --- a/spec/lib/gitlab/gitaly_client_spec.rb +++ b/spec/lib/gitlab/gitaly_client_spec.rb @@ -26,7 +26,7 @@ describe Gitlab::GitalyClient do context 'running in Unicorn' do before do - allow(Gitlab::Runtime).to receive(:unicorn?).and_return(true) + stub_const('Unicorn', 1) end it { expect(subject.long_timeout).to eq(55) } @@ -34,7 +34,7 @@ describe Gitlab::GitalyClient do context 'running in Puma' do before do - allow(Gitlab::Runtime).to receive(:puma?).and_return(true) + stub_const('Puma', 1) end it { expect(subject.long_timeout).to eq(55) } diff --git a/spec/lib/gitlab/gpg_spec.rb b/spec/lib/gitlab/gpg_spec.rb index 27a3010eeed..8600ef223c6 100644 --- a/spec/lib/gitlab/gpg_spec.rb +++ b/spec/lib/gitlab/gpg_spec.rb @@ -236,7 +236,7 @@ describe Gitlab::Gpg do context 'when running in Sidekiq' do before do - allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true) + allow(Sidekiq).to receive(:server?).and_return(true) end it_behaves_like 'multiple deletion attempts of the tmp-dir', described_class::BG_CLEANUP_RUNTIME_S diff --git a/spec/lib/gitlab/health_checks/puma_check_spec.rb b/spec/lib/gitlab/health_checks/puma_check_spec.rb index 93ef81978a8..dd052a4dd2c 100644 --- a/spec/lib/gitlab/health_checks/puma_check_spec.rb +++ b/spec/lib/gitlab/health_checks/puma_check_spec.rb @@ -22,7 +22,6 @@ describe Gitlab::HealthChecks::PumaCheck do context 'when Puma is not loaded' do before do - allow(Gitlab::Runtime).to receive(:puma?).and_return(false) hide_const('Puma') end @@ -34,7 +33,6 @@ describe Gitlab::HealthChecks::PumaCheck do context 'when Puma is loaded' do before do - allow(Gitlab::Runtime).to receive(:puma?).and_return(true) stub_const('Puma', Module.new) end diff --git a/spec/lib/gitlab/health_checks/unicorn_check_spec.rb b/spec/lib/gitlab/health_checks/unicorn_check_spec.rb index 7c57b6f1ca5..931b61cb168 100644 --- a/spec/lib/gitlab/health_checks/unicorn_check_spec.rb +++ b/spec/lib/gitlab/health_checks/unicorn_check_spec.rb @@ -26,7 +26,6 @@ describe Gitlab::HealthChecks::UnicornCheck do context 'when Unicorn is not loaded' do before do - allow(Gitlab::Runtime).to receive(:unicorn?).and_return(false) hide_const('Unicorn') end @@ -40,7 +39,6 @@ describe Gitlab::HealthChecks::UnicornCheck do let(:http_server_class) { Struct.new(:worker_processes) } before do - allow(Gitlab::Runtime).to receive(:unicorn?).and_return(true) stub_const('Unicorn::HttpServer', http_server_class) end diff --git a/spec/lib/gitlab/highlight_spec.rb b/spec/lib/gitlab/highlight_spec.rb index 2140cbae488..5a45d724b83 100644 --- a/spec/lib/gitlab/highlight_spec.rb +++ b/spec/lib/gitlab/highlight_spec.rb @@ -111,7 +111,7 @@ describe Gitlab::Highlight do end it 'utilizes longer timeout for sidekiq' do - allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true) + allow(Sidekiq).to receive(:server?).and_return(true) expect(Timeout).to receive(:timeout).with(described_class::TIMEOUT_BACKGROUND).and_call_original subject.highlight("Content") diff --git a/spec/lib/gitlab/metrics/samplers/influx_sampler_spec.rb b/spec/lib/gitlab/metrics/samplers/influx_sampler_spec.rb index 939c057c342..2d4b27a6ac1 100644 --- a/spec/lib/gitlab/metrics/samplers/influx_sampler_spec.rb +++ b/spec/lib/gitlab/metrics/samplers/influx_sampler_spec.rb @@ -63,7 +63,7 @@ describe Gitlab::Metrics::Samplers::InfluxSampler do describe '#add_metric' do it 'prefixes the series name for a Rails process' do - expect(Gitlab::Runtime).to receive(:sidekiq?).and_return(false) + expect(sampler).to receive(:sidekiq?).and_return(false) expect(Gitlab::Metrics::Metric).to receive(:new) .with('rails_cats', { value: 10 }, {}) @@ -73,7 +73,7 @@ describe Gitlab::Metrics::Samplers::InfluxSampler do end it 'prefixes the series name for a Sidekiq process' do - expect(Gitlab::Runtime).to receive(:sidekiq?).and_return(true) + expect(sampler).to receive(:sidekiq?).and_return(true) expect(Gitlab::Metrics::Metric).to receive(:new) .with('sidekiq_cats', { value: 10 }, {}) diff --git a/spec/lib/gitlab/runtime_spec.rb b/spec/lib/gitlab/runtime_spec.rb deleted file mode 100644 index 914c0fe2be7..00000000000 --- a/spec/lib/gitlab/runtime_spec.rb +++ /dev/null @@ -1,112 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe Gitlab::Runtime do - REAL_PATH = $0 - - after(:all) do - $0 = REAL_PATH - end - - context "when unknown" do - it "identifies as :unknown" do - expect(subject.name).to eq(:unknown) - end - end - - context "on multiple matches" do - before do - $0 = '/data/cache/bundle-2.5/bin/puma' - stub_const('::Puma', double) - stub_const('::Rails::Console', double) - end - - it "raises an exception when trying to identify" do - expect { subject.name }.to raise_error(RuntimeError, "Ambiguous process match: [:puma, :console]") - end - end - - context "puma" do - let(:puma_type) { double('::Puma') } - - before do - $0 = '/data/cache/bundle-2.5/bin/puma' - stub_const('::Puma', puma_type) - end - - it "identifies itself" do - expect(subject.name).to eq(:puma) - expect(subject.puma?).to be(true) - end - - it "does not identify as others" do - expect(subject.unicorn?).to be(false) - expect(subject.sidekiq?).to be(false) - expect(subject.console?).to be(false) - end - end - - context "unicorn" do - let(:unicorn_type) { Module.new } - let(:unicorn_server_type) { Class.new } - - before do - $0 = 'unicorn_rails master -E development -c /tmp/unicorn.rb -l 0.0.0.0:8080' - stub_const('::Unicorn', unicorn_type) - stub_const('::Unicorn::HttpServer', unicorn_server_type) - end - - it "identifies itself" do - expect(subject.name).to eq(:unicorn) - expect(subject.unicorn?).to be(true) - end - - it "does not identify as others" do - expect(subject.puma?).to be(false) - expect(subject.sidekiq?).to be(false) - expect(subject.console?).to be(false) - end - end - - context "sidekiq" do - let(:sidekiq_type) { double('::Sidekiq') } - - before do - $0 = '/data/cache/bundle-2.5/bin/sidekiq' - stub_const('::Sidekiq', sidekiq_type) - allow(sidekiq_type).to receive(:server?).and_return(true) - end - - it "identifies itself" do - expect(subject.name).to eq(:sidekiq) - expect(subject.sidekiq?).to be(true) - end - - it "does not identify as others" do - expect(subject.unicorn?).to be(false) - expect(subject.puma?).to be(false) - expect(subject.console?).to be(false) - end - end - - context "console" do - let(:console_type) { double('::Rails::Console') } - - before do - $0 = 'bin/rails' - stub_const('::Rails::Console', console_type) - end - - it "identifies itself" do - expect(subject.name).to eq(:console) - expect(subject.console?).to be(true) - end - - it "does not identify as others" do - expect(subject.unicorn?).to be(false) - expect(subject.sidekiq?).to be(false) - expect(subject.puma?).to be(false) - end - end -end diff --git a/spec/lib/prometheus/pid_provider_spec.rb b/spec/lib/prometheus/pid_provider_spec.rb index 5a17f25f144..6fdc11b14c4 100644 --- a/spec/lib/prometheus/pid_provider_spec.rb +++ b/spec/lib/prometheus/pid_provider_spec.rb @@ -6,13 +6,16 @@ describe Prometheus::PidProvider do describe '.worker_id' do subject { described_class.worker_id } + let(:sidekiq_module) { Module.new } + before do - allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(false) + allow(sidekiq_module).to receive(:server?).and_return(false) + stub_const('Sidekiq', sidekiq_module) end context 'when running in Sidekiq server mode' do before do - allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true) + expect(Sidekiq).to receive(:server?).and_return(true) end context 'in a clustered setup' do @@ -30,7 +33,8 @@ describe Prometheus::PidProvider do context 'when running in Unicorn mode' do before do - allow(Gitlab::Runtime).to receive(:unicorn?).and_return(true) + stub_const('Unicorn::Worker', Class.new) + hide_const('Puma') expect(described_class).to receive(:process_name) .at_least(:once) @@ -90,7 +94,8 @@ describe Prometheus::PidProvider do context 'when running in Puma mode' do before do - allow(Gitlab::Runtime).to receive(:puma?).and_return(true) + stub_const('Puma', Module.new) + hide_const('Unicorn::Worker') expect(described_class).to receive(:process_name) .at_least(:once) @@ -111,6 +116,11 @@ describe Prometheus::PidProvider do end context 'when running in unknown mode' do + before do + hide_const('Puma') + hide_const('Unicorn::Worker') + end + it { is_expected.to eq "process_#{Process.pid}" } end end diff --git a/spec/services/git/branch_push_service_spec.rb b/spec/services/git/branch_push_service_spec.rb index e7f005cff0b..19d7b84a3ce 100644 --- a/spec/services/git/branch_push_service_spec.rb +++ b/spec/services/git/branch_push_service_spec.rb @@ -108,7 +108,7 @@ describe Git::BranchPushService, services: true do end it 'reports an error' do - allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true) + allow(Sidekiq).to receive(:server?).and_return(true) expect(Sidekiq.logger).to receive(:warn) expect { subject }.not_to change { Ci::Pipeline.count } diff --git a/spec/support/helpers/kubernetes_helpers.rb b/spec/support/helpers/kubernetes_helpers.rb index cac43e94a92..a3b527e0ffe 100644 --- a/spec/support/helpers/kubernetes_helpers.rb +++ b/spec/support/helpers/kubernetes_helpers.rb @@ -84,7 +84,7 @@ module KubernetesHelpers end logs_url = service.api_url + "/api/v1/namespaces/#{namespace}/pods/#{pod_name}" \ - "/log?#{container_query_param}tailLines=#{Clusters::Platforms::Kubernetes::LOGS_LIMIT}" + "/log?#{container_query_param}tailLines=#{Clusters::Platforms::Kubernetes::LOGS_LIMIT}×tamps=true" if status response = { status: status } @@ -331,7 +331,7 @@ module KubernetesHelpers end def kube_logs_body - "Log 1\nLog 2\nLog 3" + "2019-12-13T14:04:22.123456Z Log 1\n2019-12-13T14:04:23.123456Z Log 2\n2019-12-13T14:04:24.123456Z Log 3" end def kube_deployments_body diff --git a/spec/support/redis/redis_shared_examples.rb b/spec/support/redis/redis_shared_examples.rb index e079c32d6ae..97a23f02b3e 100644 --- a/spec/support/redis/redis_shared_examples.rb +++ b/spec/support/redis/redis_shared_examples.rb @@ -118,7 +118,7 @@ RSpec.shared_examples "redis_shared_examples" do context 'when running not on sidekiq workers' do before do - allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(false) + allow(Sidekiq).to receive(:server?).and_return(false) end it 'instantiates a connection pool with size 5' do @@ -130,7 +130,7 @@ RSpec.shared_examples "redis_shared_examples" do context 'when running on sidekiq workers' do before do - allow(Gitlab::Runtime).to receive(:sidekiq?).and_return(true) + allow(Sidekiq).to receive(:server?).and_return(true) allow(Sidekiq).to receive(:options).and_return({ concurrency: 18 }) end |