2021-11-18 22:05:49 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
# Mock Types
|
|
|
|
MockGoogleOAuth2Credentials = Struct.new(:app_id, :app_secret)
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
RSpec.describe Projects::GoogleCloudController do
|
|
|
|
let_it_be(:project) { create(:project, :public) }
|
|
|
|
|
|
|
|
describe 'GET index' do
|
|
|
|
let_it_be(:url) { "#{project_google_cloud_index_path(project)}" }
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
context 'when a public request is made' do
|
|
|
|
it 'returns not found' do
|
|
|
|
get url
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
context 'when a project.guest makes request' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
it 'returns not found' do
|
|
|
|
project.add_guest(user)
|
2021-11-18 22:05:49 +05:30
|
|
|
sign_in(user)
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
get url
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
2021-12-11 22:18:48 +05:30
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
context 'when project.developer makes request' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
it 'returns not found' do
|
|
|
|
project.add_developer(user)
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get url
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
context 'when project.maintainer makes request' do
|
2021-11-18 22:05:49 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
it 'returns successful' do
|
|
|
|
project.add_maintainer(user)
|
2021-11-18 22:05:49 +05:30
|
|
|
sign_in(user)
|
2021-12-11 22:18:48 +05:30
|
|
|
|
|
|
|
get url
|
|
|
|
|
|
|
|
expect(response).to be_successful
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
2021-12-11 22:18:48 +05:30
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
context 'when project.creator makes request' do
|
|
|
|
let(:user) { project.creator }
|
|
|
|
|
|
|
|
it 'returns successful' do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get url
|
|
|
|
|
|
|
|
expect(response).to be_successful
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
describe 'when authorized user makes request' do
|
|
|
|
let(:user) { project.creator }
|
|
|
|
|
|
|
|
context 'but gitlab instance is not configured for google oauth2' do
|
|
|
|
before do
|
|
|
|
unconfigured_google_oauth2 = MockGoogleOAuth2Credentials.new('', '')
|
|
|
|
allow(Gitlab::Auth::OAuth::Provider).to receive(:config_for)
|
|
|
|
.with('google_oauth2')
|
|
|
|
.and_return(unconfigured_google_oauth2)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns forbidden' do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get url
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:forbidden)
|
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
context 'but feature flag is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(incubation_5mp_google_cloud: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns not found' do
|
|
|
|
sign_in(user)
|
|
|
|
|
|
|
|
get url
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|