Commit ed0395e8 authored by Adrien Kohlbecker's avatar Adrien Kohlbecker Committed by Dylan Griffith

Add suggested specs on developper access to logs

parent dbe3821d
......@@ -18,6 +18,7 @@ describe Clusters::EnvironmentEntity do
subject { described_class.new(environment, request: request).as_json }
context 'with maintainer access' do
before do
group.add_maintainer(user)
end
......@@ -55,4 +56,15 @@ describe Clusters::EnvironmentEntity do
expect(subject).to include(:logs_path)
end
end
context 'with developer access' do
before do
group.add_developer(user)
end
it 'does not expose logs_path' do
expect(subject).not_to include(:logs_path)
end
end
end
end
......@@ -16,16 +16,23 @@ describe Projects::LogsController do
let(:container) { 'container-1' }
before do
project.add_maintainer(user)
sign_in(user)
end
describe 'GET #index' do
let(:empty_project) { create(:project) }
it 'returns 404 with developer access' do
project.add_developer(user)
get :index, params: environment_params
expect(response).to have_gitlab_http_status(:not_found)
end
it 'renders empty logs page if no environment exists' do
empty_project.add_maintainer(user)
get :index, params: { namespace_id: empty_project.namespace, project_id: empty_project }
expect(response).to be_ok
......@@ -33,6 +40,8 @@ describe Projects::LogsController do
end
it 'renders index template' do
project.add_maintainer(user)
get :index, params: environment_params
expect(response).to be_ok
......@@ -60,6 +69,19 @@ describe Projects::LogsController do
end
end
it 'returns 404 with developer access' do
project.add_developer(user)
get endpoint, params: environment_params(pod_name: pod_name, format: :json)
expect(response).to have_gitlab_http_status(:not_found)
end
context 'with maintainer access' do
before do
project.add_maintainer(user)
end
it 'returns the service result' do
get endpoint, params: environment_params(pod_name: pod_name, format: :json)
......@@ -126,6 +148,7 @@ describe Projects::LogsController do
it_behaves_like 'unsuccessful execution response', 'Environment does not have deployments'
end
end
end
describe 'GET #k8s' do
it_behaves_like 'pod logs service', :k8s, PodLogs::KubernetesService
......
......@@ -10,7 +10,13 @@ describe EnvironmentEntity do
described_class.new(environment, request: spy('request'))
end
let(:environment) { create(:environment) }
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:environment) { create(:environment, project: project) }
before do
allow(entity).to receive(:current_user).and_return(user)
end
subject { entity.as_json }
......@@ -67,14 +73,33 @@ describe EnvironmentEntity do
end
context 'with auto_stop_in' do
let(:environment) { create(:environment, :will_auto_stop) }
let(:environment) { create(:environment, :will_auto_stop, project: project) }
it 'exposes auto stop related information' do
project.add_maintainer(user)
expect(subject).to include(:cancel_auto_stop_path, :auto_stop_at)
end
end
context 'pod_logs' do
context 'with developer access' do
before do
project.add_developer(user)
end
it 'does not expose logs keys' do
expect(subject).not_to include(:logs_path)
expect(subject).not_to include(:logs_api_path)
expect(subject).not_to include(:enable_advanced_logs_querying)
end
end
context 'with maintainer access' do
before do
project.add_maintainer(user)
end
it 'exposes logs keys' do
expect(subject).to include(:logs_path)
expect(subject).to include(:logs_api_path)
......@@ -82,13 +107,14 @@ describe EnvironmentEntity do
end
it 'uses k8s api when ES is not available' do
expect(subject[:logs_api_path]).to eq(k8s_project_logs_path(environment.project, environment_name: environment.name, format: :json))
expect(subject[:logs_api_path]).to eq(k8s_project_logs_path(project, environment_name: environment.name, format: :json))
end
it 'uses ES api when ES is available' do
allow(environment).to receive(:elastic_stack_available?).and_return(true)
expect(subject[:logs_api_path]).to eq(elasticsearch_project_logs_path(environment.project, environment_name: environment.name, format: :json))
expect(subject[:logs_api_path]).to eq(elasticsearch_project_logs_path(project, environment_name: environment.name, format: :json))
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