Commit 248475cd authored by Vitali Tatarintev's avatar Vitali Tatarintev

Add check for an active alerts service

Check if alerts service is active for the project
before creating a GitLab issue from `NotifyService`
parent b8c4b60c
...@@ -11,8 +11,8 @@ module Projects ...@@ -11,8 +11,8 @@ module Projects
DEV_TOKEN = :development_token DEV_TOKEN = :development_token
def execute(token) def execute(token)
return forbidden unless alerts_service_activated?
return unauthorized unless valid_token?(token) return unauthorized unless valid_token?(token)
return forbidden unless create_issue?
process_incident_issues process_incident_issues
...@@ -31,8 +31,10 @@ module Projects ...@@ -31,8 +31,10 @@ module Projects
project.feature_available?(:incident_management) project.feature_available?(:incident_management)
end end
def create_issue? def alerts_service_activated?
incident_management_available? && generic_alert_endpoint_enabled? incident_management_available? &&
generic_alert_endpoint_enabled? &&
project.alerts_service.try(:active?)
end end
def process_incident_issues def process_incident_issues
......
...@@ -59,26 +59,36 @@ describe Projects::Alerting::NotifyService do ...@@ -59,26 +59,36 @@ describe Projects::Alerting::NotifyService do
stub_feature_flags(generic_alert_endpoint: true) stub_feature_flags(generic_alert_endpoint: true)
end end
context 'with valid token' do context 'with activated Alerts Service' do
context 'with a valid payload' do let!(:alerts_service) { create(:alerts_service, project: project) }
it_behaves_like 'processes incident issues', 1
end context 'with valid token' do
context 'with a valid payload' do
it_behaves_like 'processes incident issues', 1
end
context 'with an invalid payload' do context 'with an invalid payload' do
before do before do
allow(Gitlab::Alerting::NotificationPayloadParser) allow(Gitlab::Alerting::NotificationPayloadParser)
.to receive(:call) .to receive(:call)
.and_raise(Gitlab::Alerting::NotificationPayloadParser::BadPayloadError) .and_raise(Gitlab::Alerting::NotificationPayloadParser::BadPayloadError)
end
it_behaves_like 'does not process incident issues', http_status: 400
end end
end
context 'with invalid token' do
let(:token) { 'invalid-token' }
it_behaves_like 'does not process incident issues', http_status: 400 it_behaves_like 'does not process incident issues', http_status: 401
end end
end end
context 'with invalid token' do context 'with deactivated Alerts Service' do
let(:token) { 'invalid-token' } let!(:alerts_service) { create(:alerts_service, :inactive, project: project) }
it_behaves_like 'does not process incident issues', http_status: 401 it_behaves_like 'does not process incident issues', http_status: 403
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment