2020-03-30 05:07:58 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe API::ContainerRegistryEvent do
|
2020-03-30 05:07:58 -04:00
|
|
|
let(:secret_token) { 'secret_token' }
|
|
|
|
let(:events) { [{ action: 'push' }] }
|
|
|
|
let(:registry_headers) { { 'Content-Type' => ::API::ContainerRegistryEvent::DOCKER_DISTRIBUTION_EVENTS_V1_JSON } }
|
|
|
|
|
|
|
|
describe 'POST /container_registry_event/events' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab.config.registry).to receive(:notification_secret) { secret_token }
|
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
|
|
|
post api('/container_registry_event/events'),
|
|
|
|
params: { events: events }.to_json,
|
|
|
|
headers: registry_headers.merge('Authorization' => secret_token)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 200 status and events are passed to event handler' do
|
|
|
|
event = spy(:event)
|
|
|
|
allow(::ContainerRegistry::Event).to receive(:new).and_return(event)
|
|
|
|
expect(event).to receive(:supported?).and_return(true)
|
|
|
|
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(event).to have_received(:handle!).once
|
|
|
|
expect(event).to have_received(:track!).once
|
2020-03-31 17:08:05 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2020-03-30 05:07:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 401 error status when token is invalid' do
|
|
|
|
post api('/container_registry_event/events'),
|
|
|
|
params: { events: events }.to_json,
|
|
|
|
headers: registry_headers.merge('Authorization' => 'invalid_token')
|
|
|
|
|
2020-03-31 17:08:05 -04:00
|
|
|
expect(response).to have_gitlab_http_status(:unauthorized)
|
2020-03-30 05:07:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|