debian-mirror-gitlab/spec/controllers/admin/hooks_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

88 lines
2.4 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Admin::HooksController do
2023-01-13 00:05:48 +05:30
let_it_be(:admin) { create(:admin) }
2017-09-10 17:25:29 +05:30
before do
sign_in(admin)
end
describe 'POST #create' do
it 'sets all parameters' do
hook_params = {
enable_ssl_verification: true,
2018-03-17 18:26:18 +05:30
token: "TEST TOKEN",
url: "http://example.com",
2017-09-10 17:25:29 +05:30
push_events: true,
2022-08-13 15:12:31 +05:30
tag_push_events: false,
2017-09-10 17:25:29 +05:30
repository_update_events: true,
2022-08-13 15:12:31 +05:30
merge_requests_events: false,
url_variables: [{ key: 'token', value: 'some secret value' }]
2017-09-10 17:25:29 +05:30
}
2019-02-15 15:39:39 +05:30
post :create, params: { hook: hook_params }
2017-09-10 17:25:29 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:found)
2017-09-10 17:25:29 +05:30
expect(SystemHook.all.size).to eq(1)
2022-08-13 15:12:31 +05:30
expect(SystemHook.first).to have_attributes(hook_params.except(:url_variables))
expect(SystemHook.first).to have_attributes(url_variables: { 'token' => 'some secret value' })
end
end
describe 'POST #update' do
2023-01-13 00:05:48 +05:30
let_it_be_with_reload(:hook) { create(:system_hook) }
context 'with an existing token' do
hook_params = {
token: WebHook::SECRET_MASK,
url: "http://example.com"
}
it 'does not change a token' do
expect do
post :update, params: { id: hook.id, hook: hook_params }
end.not_to change { hook.reload.token }
expect(response).to have_gitlab_http_status(:found)
expect(flash[:alert]).to be_blank
end
end
2022-08-13 15:12:31 +05:30
it 'sets all parameters' do
hook.update!(url_variables: { 'foo' => 'bar', 'baz' => 'woo' })
hook_params = {
url: 'http://example.com/{baz}?token={token}',
enable_ssl_verification: false,
url_variables: [
{ key: 'token', value: 'some secret value' },
2023-04-03 14:13:38 +05:30
{ key: 'baz', value: 'qux' },
2022-08-13 15:12:31 +05:30
{ key: 'foo', value: nil }
]
}
put :update, params: { id: hook.id, hook: hook_params }
hook.reload
expect(response).to have_gitlab_http_status(:found)
2023-03-04 22:38:38 +05:30
expect(flash[:notice]).to include('was updated')
2022-08-13 15:12:31 +05:30
expect(hook).to have_attributes(hook_params.except(:url_variables))
expect(hook).to have_attributes(
2023-04-03 14:13:38 +05:30
url_variables: { 'token' => 'some secret value', 'baz' => 'qux' }
2022-08-13 15:12:31 +05:30
)
2017-09-10 17:25:29 +05:30
end
end
2021-01-03 14:25:43 +05:30
describe 'DELETE #destroy' do
2023-01-13 00:05:48 +05:30
let_it_be(:hook) { create(:system_hook) }
let_it_be(:log) { create(:web_hook_log, web_hook: hook) }
2021-01-03 14:25:43 +05:30
let(:params) { { id: hook } }
it_behaves_like 'Web hook destroyer'
end
2017-09-10 17:25:29 +05:30
end