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-06-18 14:18:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/models/project_services
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/models/project_services')
-rw-r--r--spec/models/project_services/chat_message/alert_message_spec.rb57
-rw-r--r--spec/models/project_services/chat_message/merge_message_spec.rb8
-rw-r--r--spec/models/project_services/chat_message/pipeline_message_spec.rb34
-rw-r--r--spec/models/project_services/emails_on_push_service_spec.rb22
-rw-r--r--spec/models/project_services/hipchat_service_spec.rb4
-rw-r--r--spec/models/project_services/jira_service_spec.rb16
-rw-r--r--spec/models/project_services/pipelines_email_service_spec.rb16
-rw-r--r--spec/models/project_services/prometheus_service_spec.rb45
8 files changed, 143 insertions, 59 deletions
diff --git a/spec/models/project_services/chat_message/alert_message_spec.rb b/spec/models/project_services/chat_message/alert_message_spec.rb
new file mode 100644
index 00000000000..a1dd332c005
--- /dev/null
+++ b/spec/models/project_services/chat_message/alert_message_spec.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe ChatMessage::AlertMessage do
+ subject { described_class.new(args) }
+
+ let_it_be(:start_time) { Time.current }
+ let(:alert) { create(:alert_management_alert, started_at: start_time) }
+
+ let(:args) do
+ {
+ project_name: 'project_name',
+ project_url: 'http://example.com'
+ }.merge(Gitlab::DataBuilder::Alert.build(alert))
+ end
+
+ describe '#message' do
+ it 'returns the correct message' do
+ expect(subject.message).to eq("Alert firing in #{args[:project_name]}")
+ end
+ end
+
+ describe '#attachments' do
+ it 'returns an array of one' do
+ expect(subject.attachments).to be_a(Array)
+ expect(subject.attachments.size).to eq(1)
+ end
+
+ it 'contains the correct attributes' do
+ attachments_item = subject.attachments.first
+ expect(attachments_item).to have_key(:title)
+ expect(attachments_item).to have_key(:title_link)
+ expect(attachments_item).to have_key(:color)
+ expect(attachments_item).to have_key(:fields)
+ end
+
+ it 'returns the correct color' do
+ expect(subject.attachments.first[:color]).to eq("#C95823")
+ end
+
+ it 'returns the correct attachment fields' do
+ attachments_item = subject.attachments.first
+ fields = attachments_item[:fields].map { |h| h[:title] }
+
+ expect(fields).to match_array(['Severity', 'Events', 'Status', 'Start time'])
+ end
+
+ it 'returns the correctly formatted time' do
+ time_item = subject.attachments.first[:fields].detect { |h| h[:title] == 'Start time' }
+
+ expected_time = start_time.strftime("%B #{start_time.day.ordinalize}, %Y %l:%M%p %Z")
+
+ expect(time_item[:value]).to eq(expected_time)
+ end
+ end
+end
diff --git a/spec/models/project_services/chat_message/merge_message_spec.rb b/spec/models/project_services/chat_message/merge_message_spec.rb
index 150ee6f7472..6063ef4ecb3 100644
--- a/spec/models/project_services/chat_message/merge_message_spec.rb
+++ b/spec/models/project_services/chat_message/merge_message_spec.rb
@@ -52,7 +52,7 @@ describe ChatMessage::MergeMessage do
context 'open' do
it 'returns a message regarding opening of merge requests' do
expect(subject.pretext).to eq(
- 'Test User (test.user) opened <http://somewhere.com/-/merge_requests/100|!100 *Merge Request title*> in <http://somewhere.com|project_name>')
+ 'Test User (test.user) opened merge request <http://somewhere.com/-/merge_requests/100|!100 *Merge Request title*> in <http://somewhere.com|project_name>')
expect(subject.attachments).to be_empty
end
end
@@ -63,7 +63,7 @@ describe ChatMessage::MergeMessage do
end
it 'returns a message regarding closing of merge requests' do
expect(subject.pretext).to eq(
- 'Test User (test.user) closed <http://somewhere.com/-/merge_requests/100|!100 *Merge Request title*> in <http://somewhere.com|project_name>')
+ 'Test User (test.user) closed merge request <http://somewhere.com/-/merge_requests/100|!100 *Merge Request title*> in <http://somewhere.com|project_name>')
expect(subject.attachments).to be_empty
end
end
@@ -77,7 +77,7 @@ describe ChatMessage::MergeMessage do
context 'open' do
it 'returns a message regarding opening of merge requests' do
expect(subject.pretext).to eq(
- 'Test User (test.user) opened [!100 *Merge Request title*](http://somewhere.com/-/merge_requests/100) in [project_name](http://somewhere.com)')
+ 'Test User (test.user) opened merge request [!100 *Merge Request title*](http://somewhere.com/-/merge_requests/100) in [project_name](http://somewhere.com)')
expect(subject.attachments).to be_empty
expect(subject.activity).to eq({
title: 'Merge Request opened by Test User (test.user)',
@@ -95,7 +95,7 @@ describe ChatMessage::MergeMessage do
it 'returns a message regarding closing of merge requests' do
expect(subject.pretext).to eq(
- 'Test User (test.user) closed [!100 *Merge Request title*](http://somewhere.com/-/merge_requests/100) in [project_name](http://somewhere.com)')
+ 'Test User (test.user) closed merge request [!100 *Merge Request title*](http://somewhere.com/-/merge_requests/100) in [project_name](http://somewhere.com)')
expect(subject.attachments).to be_empty
expect(subject.activity).to eq({
title: 'Merge Request closed by Test User (test.user)',
diff --git a/spec/models/project_services/chat_message/pipeline_message_spec.rb b/spec/models/project_services/chat_message/pipeline_message_spec.rb
index 7c3e48f572a..a7171577063 100644
--- a/spec/models/project_services/chat_message/pipeline_message_spec.rb
+++ b/spec/models/project_services/chat_message/pipeline_message_spec.rb
@@ -61,8 +61,8 @@ describe ChatMessage::PipelineMessage do
it "returns the pipeline summary in the activity's title" do
expect(subject.activity[:title]).to eq(
- "Pipeline [#123](http://example.gitlab.com/pipelines/123)" \
- " of branch [develop](http://example.gitlab.com/commits/develop)" \
+ "Pipeline [#123](http://example.gitlab.com/-/pipelines/123)" \
+ " of branch [develop](http://example.gitlab.com/-/commits/develop)" \
" by The Hacker (hacker) has passed"
)
end
@@ -74,8 +74,8 @@ describe ChatMessage::PipelineMessage do
it "returns the summary with a 'failed' status" do
expect(subject.activity[:title]).to eq(
- "Pipeline [#123](http://example.gitlab.com/pipelines/123)" \
- " of branch [develop](http://example.gitlab.com/commits/develop)" \
+ "Pipeline [#123](http://example.gitlab.com/-/pipelines/123)" \
+ " of branch [develop](http://example.gitlab.com/-/commits/develop)" \
" by The Hacker (hacker) has failed"
)
end
@@ -88,8 +88,8 @@ describe ChatMessage::PipelineMessage do
it "returns the summary with a 'passed with warnings' status" do
expect(subject.activity[:title]).to eq(
- "Pipeline [#123](http://example.gitlab.com/pipelines/123)" \
- " of branch [develop](http://example.gitlab.com/commits/develop)" \
+ "Pipeline [#123](http://example.gitlab.com/-/pipelines/123)" \
+ " of branch [develop](http://example.gitlab.com/-/commits/develop)" \
" by The Hacker (hacker) has passed with warnings"
)
end
@@ -102,8 +102,8 @@ describe ChatMessage::PipelineMessage do
it "returns the summary with 'API' as the username" do
expect(subject.activity[:title]).to eq(
- "Pipeline [#123](http://example.gitlab.com/pipelines/123)" \
- " of branch [develop](http://example.gitlab.com/commits/develop)" \
+ "Pipeline [#123](http://example.gitlab.com/-/pipelines/123)" \
+ " of branch [develop](http://example.gitlab.com/-/commits/develop)" \
" by API has passed"
)
end
@@ -134,8 +134,8 @@ describe ChatMessage::PipelineMessage do
it "returns the pipeline summary as the attachment's fallback property" do
expect(subject.attachments.first[:fallback]).to eq(
"<http://example.gitlab.com|project_name>:" \
- " Pipeline <http://example.gitlab.com/pipelines/123|#123>" \
- " of branch <http://example.gitlab.com/commits/develop|develop>" \
+ " Pipeline <http://example.gitlab.com/-/pipelines/123|#123>" \
+ " of branch <http://example.gitlab.com/-/commits/develop|develop>" \
" by The Hacker (hacker) has passed in 02:00:10"
)
end
@@ -199,7 +199,7 @@ describe ChatMessage::PipelineMessage do
end
it "returns the pipeline URL as the attachment's title_link property" do
- expect(subject.attachments.first[:title_link]).to eq("http://example.gitlab.com/pipelines/123")
+ expect(subject.attachments.first[:title_link]).to eq("http://example.gitlab.com/-/pipelines/123")
end
it "returns two attachment fields" do
@@ -209,7 +209,7 @@ describe ChatMessage::PipelineMessage do
it "returns the commit message as the attachment's second field property" do
expect(subject.attachments.first[:fields][0]).to eq({
title: "Branch",
- value: "<http://example.gitlab.com/commits/develop|develop>",
+ value: "<http://example.gitlab.com/-/commits/develop|develop>",
short: true
})
end
@@ -237,7 +237,7 @@ describe ChatMessage::PipelineMessage do
it "returns the stage name and link to the 'Failed jobs' tab on the pipeline's page as the attachment's third field property" do
expect(subject.attachments.first[:fields][2]).to eq({
title: "Failed stage",
- value: "<http://example.gitlab.com/pipelines/123/failures|test>",
+ value: "<http://example.gitlab.com/-/pipelines/123/failures|test>",
short: true
})
end
@@ -261,7 +261,7 @@ describe ChatMessage::PipelineMessage do
it "returns the stage names and links to the 'Failed jobs' tab on the pipeline's page as the attachment's third field property" do
expect(subject.attachments.first[:fields][2]).to eq({
title: "Failed stages",
- value: "<http://example.gitlab.com/pipelines/123/failures|stage-2>, <http://example.gitlab.com/pipelines/123/failures|stage-1>, <http://example.gitlab.com/pipelines/123/failures|stage-3>",
+ value: "<http://example.gitlab.com/-/pipelines/123/failures|stage-2>, <http://example.gitlab.com/-/pipelines/123/failures|stage-1>, <http://example.gitlab.com/-/pipelines/123/failures|stage-3>",
short: true
})
end
@@ -271,7 +271,7 @@ describe ChatMessage::PipelineMessage do
"<http://example.gitlab.com/-/jobs/#{i}|job-#{i}>"
end
- expected_jobs << "and <http://example.gitlab.com/pipelines/123/failures|15 more>"
+ expected_jobs << "and <http://example.gitlab.com/-/pipelines/123/failures|15 more>"
expect(subject.attachments.first[:fields][3]).to eq({
title: "Failed jobs",
@@ -369,8 +369,8 @@ describe ChatMessage::PipelineMessage do
it 'returns the pipeline summary as the attachments in markdown format' do
expect(subject.attachments).to eq(
"[project_name](http://example.gitlab.com):" \
- " Pipeline [#123](http://example.gitlab.com/pipelines/123)" \
- " of branch [develop](http://example.gitlab.com/commits/develop)" \
+ " Pipeline [#123](http://example.gitlab.com/-/pipelines/123)" \
+ " of branch [develop](http://example.gitlab.com/-/commits/develop)" \
" by The Hacker (hacker) has passed in 02:00:10"
)
end
diff --git a/spec/models/project_services/emails_on_push_service_spec.rb b/spec/models/project_services/emails_on_push_service_spec.rb
index ce1952b503f..44db95afc57 100644
--- a/spec/models/project_services/emails_on_push_service_spec.rb
+++ b/spec/models/project_services/emails_on_push_service_spec.rb
@@ -21,23 +21,25 @@ describe EmailsOnPushService do
end
end
- context 'when properties is missing branches_to_be_notified' do
- subject { described_class.new(properties: {}) }
+ describe '.new' do
+ context 'when properties is missing branches_to_be_notified' do
+ subject { described_class.new(properties: {}) }
- it 'sets the default value to all' do
- expect(subject.branches_to_be_notified).to eq('all')
+ it 'sets the default value to all' do
+ expect(subject.branches_to_be_notified).to eq('all')
+ end
end
- end
- context 'when branches_to_be_notified is already set' do
- subject { described_class.new(properties: { branches_to_be_notified: 'protected' }) }
+ context 'when branches_to_be_notified is already set' do
+ subject { described_class.new(properties: { branches_to_be_notified: 'protected' }) }
- it 'does not overwrite it with the default value' do
- expect(subject.branches_to_be_notified).to eq('protected')
+ it 'does not overwrite it with the default value' do
+ expect(subject.branches_to_be_notified).to eq('protected')
+ end
end
end
- context 'project emails' do
+ describe '#execute' do
let(:push_data) { { object_kind: 'push' } }
let(:project) { create(:project, :repository) }
let(:service) { create(:emails_on_push_service, project: project) }
diff --git a/spec/models/project_services/hipchat_service_spec.rb b/spec/models/project_services/hipchat_service_spec.rb
index ae6e93cfe3a..c25edf81352 100644
--- a/spec/models/project_services/hipchat_service_spec.rb
+++ b/spec/models/project_services/hipchat_service_spec.rb
@@ -327,8 +327,8 @@ describe HipchatService do
user_name = data[:user][:name]
expect(message).to eq("<a href=\"#{project_url}\">#{project_name}</a>: " \
- "Pipeline <a href=\"#{project_url}/pipelines/#{pipeline.id}\">##{pipeline.id}</a> " \
- "of <a href=\"#{project_url}/commits/#{ref}\">#{ref}</a> #{ref_type} " \
+ "Pipeline <a href=\"#{project_url}/-/pipelines/#{pipeline.id}\">##{pipeline.id}</a> " \
+ "of <a href=\"#{project_url}/-/commits/#{ref}\">#{ref}</a> #{ref_type} " \
"by #{user_name} failed in #{duration} second(s)")
end
end
diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb
index a0d36f0a238..20e85f0fd4b 100644
--- a/spec/models/project_services/jira_service_spec.rb
+++ b/spec/models/project_services/jira_service_spec.rb
@@ -688,22 +688,18 @@ describe JiraService do
context 'when the test fails' do
it 'returns result with the error' do
test_url = 'http://jira.example.com/rest/api/2/serverInfo'
+ error_message = 'Some specific failure.'
WebMock.stub_request(:get, test_url).with(basic_auth: [username, password])
- .to_raise(JIRA::HTTPError.new(double(message: 'Some specific failure.')))
+ .to_raise(JIRA::HTTPError.new(double(message: error_message)))
expect(jira_service).to receive(:log_error).with(
- "Error sending message",
- hash_including(
- client_url: url,
- error: hash_including(
- exception_class: 'JIRA::HTTPError',
- exception_message: 'Some specific failure.'
- )
- )
+ 'Error sending message',
+ client_url: 'http://jira.example.com',
+ error: error_message
)
- expect(jira_service.test(nil)).to eq(success: false, result: 'Some specific failure.')
+ expect(jira_service.test(nil)).to eq(success: false, result: error_message)
end
end
end
diff --git a/spec/models/project_services/pipelines_email_service_spec.rb b/spec/models/project_services/pipelines_email_service_spec.rb
index f29414c80c9..de1edf2099a 100644
--- a/spec/models/project_services/pipelines_email_service_spec.rb
+++ b/spec/models/project_services/pipelines_email_service_spec.rb
@@ -37,22 +37,6 @@ describe PipelinesEmailService, :mailer do
end
end
- describe '#test_data' do
- let(:build) { create(:ci_build) }
- let(:project) { build.project }
- let(:user) { create(:user) }
-
- before do
- project.add_developer(user)
- end
-
- it 'builds test data' do
- data = subject.test_data(project, user)
-
- expect(data[:object_kind]).to eq('pipeline')
- end
- end
-
shared_examples 'sending email' do |branches_to_be_notified: nil|
before do
subject.recipients = recipients
diff --git a/spec/models/project_services/prometheus_service_spec.rb b/spec/models/project_services/prometheus_service_spec.rb
index a85dbe3a7df..db3cbe23ad3 100644
--- a/spec/models/project_services/prometheus_service_spec.rb
+++ b/spec/models/project_services/prometheus_service_spec.rb
@@ -252,6 +252,26 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
end
end
end
+
+ context 'behind IAP' do
+ let(:manual_configuration) { true }
+
+ before do
+ # dummy private key generated only for this test to pass openssl validation
+ service.google_iap_service_account_json = '{"type":"service_account","private_key":"-----BEGIN RSA PRIVATE KEY-----\nMIIBOAIBAAJAU85LgUY5o6j6j/07GMLCNUcWJOBA1buZnNgKELayA6mSsHrIv31J\nY8kS+9WzGPQninea7DcM4hHA7smMgQD1BwIDAQABAkAqKxMy6PL3tn7dFL43p0ex\nJyOtSmlVIiAZG1t1LXhE/uoLpYi5DnbYqGgu0oih+7nzLY/dXpNpXUmiRMOUEKmB\nAiEAoTi2rBXbrLSi2C+H7M/nTOjMQQDuZ8Wr4uWpKcjYJTMCIQCFEskL565oFl/7\nRRQVH+cARrAsAAoJSbrOBAvYZ0PI3QIgIEFwis10vgEF86rOzxppdIG/G+JL0IdD\n9IluZuXAGPECIGUo7qSaLr75o2VEEgwtAFH5aptIPFjrL5LFCKwtdB4RAiAYZgFV\nHCMmaooAw/eELuMoMWNYmujZ7VaAnOewGDW0uw==\n-----END RSA PRIVATE KEY-----\n"}'
+ service.google_iap_audience_client_id = "IAP_CLIENT_ID.apps.googleusercontent.com"
+
+ stub_request(:post, "https://oauth2.googleapis.com/token").to_return(status: 200, body: '{"id_token": "FOO"}', headers: { 'Content-Type': 'application/json; charset=UTF-8' })
+
+ stub_feature_flags(prometheus_service_iap_auth: true)
+ end
+
+ it 'includes the authorization header' do
+ expect(service.prometheus_client).not_to be_nil
+ expect(service.prometheus_client.send(:options)).to have_key(:headers)
+ expect(service.prometheus_client.send(:options)[:headers]).to eq(authorization: "Bearer FOO")
+ end
+ end
end
describe '#prometheus_available?' do
@@ -457,9 +477,34 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
}
]
end
+ let(:feature_flagged_fields) do
+ [
+ {
+ type: 'text',
+ name: 'google_iap_audience_client_id',
+ title: 'Google IAP Audience Client ID',
+ placeholder: s_('PrometheusService|Client ID of the IAP secured resource (looks like IAP_CLIENT_ID.apps.googleusercontent.com)'),
+ autocomplete: 'off',
+ required: false
+ },
+ {
+ type: 'textarea',
+ name: 'google_iap_service_account_json',
+ title: 'Google IAP Service Account JSON',
+ placeholder: s_('PrometheusService|Contents of the credentials.json file of your service account, like: { "type": "service_account", "project_id": ... }'),
+ required: false
+ }
+ ]
+ end
it 'returns fields' do
+ stub_feature_flags(prometheus_service_iap_auth: false)
expect(service.fields).to eq(expected_fields)
end
+
+ it 'returns fields with feature flag on' do
+ stub_feature_flags(prometheus_service_iap_auth: true)
+ expect(service.fields).to eq(expected_fields + feature_flagged_fields)
+ end
end
end