Commit 4ec3d797 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'remove-generic_alert_endpoint-feature-flag' into 'master'

Remove generic alert endpoint feature flag

See merge request gitlab-org/gitlab!18570
parents 3b148b3e bfbb9661
......@@ -9,7 +9,6 @@ module Projects
skip_before_action :project
prepend_before_action :repository, :project_without_auth
before_action :check_generic_alert_endpoint_feature_flag!
def create
token = extract_alert_manager_token(request)
......@@ -25,10 +24,6 @@ module Projects
.find_by_full_path("#{params[:namespace_id]}/#{params[:project_id]}")
end
def check_generic_alert_endpoint_feature_flag!
render_404 unless Feature.enabled?(:generic_alert_endpoint, @project)
end
def extract_alert_manager_token(request)
Doorkeeper::OAuth::Token.from_bearer_authorization(request)
end
......
......@@ -639,8 +639,7 @@ module EE
end
def alerts_service_available?
::Feature.enabled?(:generic_alert_endpoint, self) &&
feature_available?(:incident_management)
feature_available?(:incident_management)
end
def package_already_taken?(package_name)
......
......@@ -20,17 +20,12 @@ module Projects
delegate :alerts_service, to: :project
def generic_alert_endpoint_enabled?
Feature.enabled?(:generic_alert_endpoint, project)
end
def incident_management_available?
project.feature_available?(:incident_management)
end
def alerts_service_activated?
incident_management_available? &&
generic_alert_endpoint_enabled? &&
alerts_service.try(:active?)
end
......
---
title: Adds a generic alert integration which can accept alerts from any source via a generic webhook receiver.
merge_request:
author:
type: added
......@@ -22,84 +22,66 @@ describe Projects::Alerting::NotificationsController do
post :create, params: project_params, body: body.to_json, as: :json
end
context 'when feature flag is on' do
before do
stub_feature_flags(generic_alert_endpoint: true)
context 'when notification service succeeds' do
let(:payload) do
{
title: 'Alert title',
hosts: 'https://gitlab.com'
}
end
context 'when notification service succeeds' do
let(:payload) do
{
title: 'Alert title',
hosts: 'https://gitlab.com'
}
end
let(:permitted_params) { ActionController::Parameters.new(payload).permit! }
it 'responds with ok' do
make_request
expect(response).to have_gitlab_http_status(:ok)
end
let(:permitted_params) { ActionController::Parameters.new(payload).permit! }
it 'does not pass excluded parameters to the notify service' do
make_request(payload)
it 'responds with ok' do
make_request
expect(Projects::Alerting::NotifyService)
.to have_received(:new)
.with(project, nil, permitted_params)
end
expect(response).to have_gitlab_http_status(:ok)
end
context 'when notification service fails' do
let(:service_response) { ServiceResponse.error(message: 'Unauthorized', http_status: 401) }
it 'responds with the service response' do
make_request
it 'does not pass excluded parameters to the notify service' do
make_request(payload)
expect(response).to have_gitlab_http_status(:unauthorized)
end
expect(Projects::Alerting::NotifyService)
.to have_received(:new)
.with(project, nil, permitted_params)
end
end
context 'bearer token' do
context 'when set' do
it 'extracts bearer token' do
request.headers['HTTP_AUTHORIZATION'] = 'Bearer some token'
context 'when notification service fails' do
let(:service_response) { ServiceResponse.error(message: 'Unauthorized', http_status: 401) }
expect(notify_service).to receive(:execute).with('some token')
it 'responds with the service response' do
make_request
make_request
end
expect(response).to have_gitlab_http_status(:unauthorized)
end
end
it 'pass nil if cannot extract a non-bearer token' do
request.headers['HTTP_AUTHORIZATION'] = 'some token'
context 'bearer token' do
context 'when set' do
it 'extracts bearer token' do
request.headers['HTTP_AUTHORIZATION'] = 'Bearer some token'
expect(notify_service).to receive(:execute).with(nil)
expect(notify_service).to receive(:execute).with('some token')
make_request
end
make_request
end
context 'when missing' do
it 'passes nil' do
expect(notify_service).to receive(:execute).with(nil)
it 'pass nil if cannot extract a non-bearer token' do
request.headers['HTTP_AUTHORIZATION'] = 'some token'
make_request
end
end
end
end
expect(notify_service).to receive(:execute).with(nil)
context 'when feature flag is off' do
before do
stub_feature_flags(generic_alert_endpoint: false)
make_request
end
end
it 'responds with not_found' do
make_request
context 'when missing' do
it 'passes nil' do
expect(notify_service).to receive(:execute).with(nil)
expect(response).to have_gitlab_http_status(:not_found)
make_request
end
end
end
end
......
......@@ -25,7 +25,6 @@ describe 'User activates Alerts' do
context 'when feature available', :js do
before do
stub_licensed_features(incident_management: true)
stub_feature_flags(generic_alert_endpoint: true)
end
context 'when service is deactivated' do
......@@ -60,14 +59,6 @@ describe 'User activates Alerts' do
expect(reset_key.value).to be_present
end
end
context 'when feature flag `generic_alert_endpoint` disabled' do
before do
stub_feature_flags(generic_alert_endpoint: false)
end
it_behaves_like 'no service'
end
end
context 'when feature unavailable' do
......
......@@ -1135,20 +1135,6 @@ describe Project do
it { is_expected.to include(*disabled_services) }
end
end
context 'when incident_management is available' do
before do
stub_licensed_features(incident_management: true)
end
context 'when feature flag generic_alert_endpoint is disabled' do
before do
stub_feature_flags(generic_alert_endpoint: false)
end
it { is_expected.to include('alerts') }
end
end
end
describe '#pull_mirror_available?' do
......
......@@ -54,48 +54,34 @@ describe Projects::Alerting::NotifyService do
stub_licensed_features(incident_management: true)
end
context 'with Generic Alert Endpoint feature enabled' do
before do
stub_feature_flags(generic_alert_endpoint: true)
end
context 'with activated Alerts Service' do
let!(:alerts_service) { create(:alerts_service, project: project) }
context 'with activated Alerts Service' do
let!(:alerts_service) { create(:alerts_service, project: project) }
context 'with valid token' do
let(:token) { alerts_service.token }
context 'with a valid payload' do
it_behaves_like 'processes incident issues', 1
end
context 'with valid token' do
let(:token) { alerts_service.token }
context 'with an invalid payload' do
before do
allow(Gitlab::Alerting::NotificationPayloadParser)
.to receive(:call)
.and_raise(Gitlab::Alerting::NotificationPayloadParser::BadPayloadError)
end
context 'with a valid payload' do
it_behaves_like 'processes incident issues', 1
end
it_behaves_like 'does not process incident issues', http_status: 400
context 'with an invalid payload' do
before do
allow(Gitlab::Alerting::NotificationPayloadParser)
.to receive(:call)
.and_raise(Gitlab::Alerting::NotificationPayloadParser::BadPayloadError)
end
end
context 'with invalid token' do
it_behaves_like 'does not process incident issues', http_status: 401
it_behaves_like 'does not process incident issues', http_status: 400
end
end
context 'with deactivated Alerts Service' do
let!(:alerts_service) { create(:alerts_service, :inactive, project: project) }
it_behaves_like 'does not process incident issues', http_status: 403
context 'with invalid token' do
it_behaves_like 'does not process incident issues', http_status: 401
end
end
context 'with Generic Alert Endpoint feature disabled' do
before do
stub_feature_flags(generic_alert_endpoint: false)
end
context 'with deactivated Alerts Service' do
let!(:alerts_service) { create(:alerts_service, :inactive, project: project) }
it_behaves_like 'does not process incident issues', http_status: 403
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