2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe Admin::Clusters::ApplicationsController do
|
2019-07-31 22:56:46 +05:30
|
|
|
include AccessMatchersForController
|
|
|
|
|
|
|
|
def current_application
|
|
|
|
Clusters::Cluster::APPLICATIONS[application]
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'a secure endpoint' do
|
|
|
|
it { expect { subject }.to be_allowed_for(:admin) }
|
|
|
|
it { expect { subject }.to be_denied_for(:user) }
|
|
|
|
it { expect { subject }.to be_denied_for(:external) }
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:cluster) { create(:cluster, :instance, :provided_by_gcp) }
|
|
|
|
|
|
|
|
describe 'POST create' do
|
|
|
|
subject do
|
|
|
|
post :create, params: params
|
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
let(:application) { 'ingress' }
|
2019-07-31 22:56:46 +05:30
|
|
|
let(:params) { { application: application, id: cluster.id } }
|
|
|
|
|
|
|
|
describe 'functionality' do
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'schedule an application installation' do
|
|
|
|
expect(ClusterInstallAppWorker).to receive(:perform_async).with(application, anything).once
|
|
|
|
|
|
|
|
expect { subject }.to change { current_application.count }
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:no_content)
|
2021-02-22 17:27:13 +05:30
|
|
|
expect(cluster.application_ingress).to be_scheduled
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when cluster do not exists' do
|
|
|
|
before do
|
|
|
|
cluster.destroy!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'return 404' do
|
|
|
|
expect { subject }.not_to change { current_application.count }
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when application is unknown' do
|
|
|
|
let(:application) { 'unkwnown-app' }
|
|
|
|
|
|
|
|
it 'return 404' do
|
2020-03-13 15:44:24 +05:30
|
|
|
is_expected.to have_gitlab_http_status(:not_found)
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when application is already installing' do
|
|
|
|
before do
|
2021-02-22 17:27:13 +05:30
|
|
|
create(:clusters_applications_ingress, :installing, cluster: cluster)
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 400' do
|
2020-03-13 15:44:24 +05:30
|
|
|
is_expected.to have_gitlab_http_status(:bad_request)
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'security' do
|
|
|
|
before do
|
|
|
|
allow(ClusterInstallAppWorker).to receive(:perform_async)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a secure endpoint'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PATCH update' do
|
|
|
|
subject do
|
|
|
|
patch :update, params: params
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
let!(:application) { create(:clusters_applications_cert_manager, :installed, cluster: cluster) }
|
2019-07-31 22:56:46 +05:30
|
|
|
let(:application_name) { application.name }
|
|
|
|
let(:params) { { application: application_name, id: cluster.id, email: "new-email@example.com" } }
|
|
|
|
|
|
|
|
describe 'functionality' do
|
|
|
|
let(:admin) { create(:admin) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when cluster and app exists" do
|
|
|
|
it "schedules an application update" do
|
|
|
|
expect(ClusterPatchAppWorker).to receive(:perform_async).with(application.name, anything).once
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
is_expected.to have_gitlab_http_status(:no_content)
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
expect(cluster.application_cert_manager).to be_scheduled
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when cluster do not exists' do
|
|
|
|
before do
|
|
|
|
cluster.destroy!
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it { is_expected.to have_gitlab_http_status(:not_found) }
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when application is unknown' do
|
|
|
|
let(:application_name) { 'unkwnown-app' }
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it { is_expected.to have_gitlab_http_status(:not_found) }
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when application is already scheduled' do
|
|
|
|
before do
|
|
|
|
application.make_scheduled!
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it { is_expected.to have_gitlab_http_status(:bad_request) }
|
2019-07-31 22:56:46 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'security' do
|
|
|
|
before do
|
|
|
|
allow(ClusterPatchAppWorker).to receive(:perform_async)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'a secure endpoint'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|