Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-25 12:08:11 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-25 12:08:11 +0300
commit5064bf8c5647d4c4430cbb4d097cf1592416de29 (patch)
treed051bf2abe2cc7061b3a7facb6669a56ccb9cf54 /spec/models
parent9c83aadd2604e7e6cb1f84683f951e6b12872618 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/commit_status_spec.rb13
-rw-r--r--spec/models/concerns/noteable_spec.rb15
-rw-r--r--spec/models/project_services/prometheus_service_spec.rb60
3 files changed, 88 insertions, 0 deletions
diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb
index e1a748da7fd..40d9afcdd14 100644
--- a/spec/models/commit_status_spec.rb
+++ b/spec/models/commit_status_spec.rb
@@ -449,6 +449,19 @@ describe CommitStatus do
end
end
+ describe '.match_id_and_lock_version' do
+ let(:status_1) { create_status(lock_version: 1) }
+ let(:status_2) { create_status(lock_version: 2) }
+
+ it 'returns statuses that match the given id and lock versions' do
+ params = [
+ { id: status_1.id, lock_version: 1 },
+ { id: status_2.id, lock_version: 3 }
+ ]
+ expect(described_class.match_id_and_lock_version(params)).to contain_exactly(status_1)
+ end
+ end
+
describe '#before_sha' do
subject { commit_status.before_sha }
diff --git a/spec/models/concerns/noteable_spec.rb b/spec/models/concerns/noteable_spec.rb
index e8991a3a015..097bc24d90f 100644
--- a/spec/models/concerns/noteable_spec.rb
+++ b/spec/models/concerns/noteable_spec.rb
@@ -62,6 +62,21 @@ describe Noteable do
end
end
+ describe '#discussion_ids_relation' do
+ it 'returns ordered discussion_ids' do
+ discussion_ids = subject.discussion_ids_relation.pluck(:discussion_id)
+
+ expect(discussion_ids).to eq([
+ active_diff_note1,
+ active_diff_note3,
+ outdated_diff_note1,
+ discussion_note1,
+ note1,
+ note2
+ ].map(&:discussion_id))
+ end
+ end
+
describe '#grouped_diff_discussions' do
let(:grouped_diff_discussions) { subject.grouped_diff_discussions }
diff --git a/spec/models/project_services/prometheus_service_spec.rb b/spec/models/project_services/prometheus_service_spec.rb
index fd4783a60f2..297411f7980 100644
--- a/spec/models/project_services/prometheus_service_spec.rb
+++ b/spec/models/project_services/prometheus_service_spec.rb
@@ -66,6 +66,18 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
end
end
+ it 'can query when local requests are allowed' do
+ stub_application_setting(allow_local_requests_from_web_hooks_and_services: true)
+
+ aggregate_failures do
+ ['127.0.0.1', '192.168.2.3'].each do |url|
+ allow(Addrinfo).to receive(:getaddrinfo).with(domain, any_args).and_return([Addrinfo.tcp(url, 80)])
+
+ expect(service.can_query?).to be true
+ end
+ end
+ end
+
context 'with self-monitoring project and internal Prometheus' do
before do
service.api_url = 'http://localhost:9090'
@@ -152,6 +164,54 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
expect(service.prometheus_client).to be_nil
end
end
+
+ context 'when local requests are allowed' do
+ let(:manual_configuration) { true }
+ let(:api_url) { 'http://192.168.1.1:9090' }
+
+ before do
+ stub_application_setting(allow_local_requests_from_web_hooks_and_services: true)
+
+ stub_prometheus_request("#{api_url}/api/v1/query?query=1")
+ end
+
+ it 'allows local requests' do
+ expect(service.prometheus_client).not_to be_nil
+ expect { service.prometheus_client.ping }.not_to raise_error
+ end
+ end
+
+ context 'when local requests are blocked' do
+ let(:manual_configuration) { true }
+ let(:api_url) { 'http://192.168.1.1:9090' }
+
+ before do
+ stub_application_setting(allow_local_requests_from_web_hooks_and_services: false)
+
+ stub_prometheus_request("#{api_url}/api/v1/query?query=1")
+ end
+
+ it 'blocks local requests' do
+ expect(service.prometheus_client).to be_nil
+ end
+
+ context 'with self monitoring project and internal Prometheus URL' do
+ before do
+ stub_application_setting(allow_local_requests_from_web_hooks_and_services: false)
+ stub_application_setting(self_monitoring_project_id: project.id)
+
+ stub_config(prometheus: {
+ enable: true,
+ listen_address: api_url
+ })
+ end
+
+ it 'allows local requests' do
+ expect(service.prometheus_client).not_to be_nil
+ expect { service.prometheus_client.ping }.not_to raise_error
+ end
+ end
+ end
end
describe '#prometheus_available?' do