2020-11-13 16:09:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Group Dependency Proxy' do
|
2021-10-13 11:12:51 -04:00
|
|
|
let(:owner) { create(:user) }
|
2020-11-13 16:09:31 -05:00
|
|
|
let(:reporter) { create(:user) }
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:path) { group_dependency_proxy_path(group) }
|
2021-10-13 11:12:51 -04:00
|
|
|
let(:settings_path) { group_settings_packages_and_registries_path(group) }
|
2020-11-13 16:09:31 -05:00
|
|
|
|
|
|
|
before do
|
2021-10-13 11:12:51 -04:00
|
|
|
group.add_owner(owner)
|
2020-11-13 16:09:31 -05:00
|
|
|
group.add_reporter(reporter)
|
|
|
|
|
|
|
|
enable_feature
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'feature settings' do
|
|
|
|
context 'when not logged in and feature disabled' do
|
|
|
|
it 'does not show the feature settings' do
|
|
|
|
group.create_dependency_proxy_setting(enabled: false)
|
|
|
|
|
|
|
|
visit path
|
|
|
|
|
2021-10-13 14:12:40 -04:00
|
|
|
expect(page).not_to have_css('[data-testid="proxy-url"]')
|
2020-11-13 16:09:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'feature is available', :js do
|
2021-10-13 11:12:51 -04:00
|
|
|
context 'when logged in as group owner' do
|
2020-11-13 16:09:31 -05:00
|
|
|
before do
|
2021-10-13 11:12:51 -04:00
|
|
|
sign_in(owner)
|
2020-11-13 16:09:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'sidebar menu is open' do
|
2021-10-13 11:12:51 -04:00
|
|
|
visit path
|
|
|
|
|
2020-11-13 16:09:31 -05:00
|
|
|
sidebar = find('.nav-sidebar')
|
|
|
|
expect(sidebar).to have_link _('Dependency Proxy')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'toggles defaults to enabled' do
|
2021-10-13 11:12:51 -04:00
|
|
|
visit path
|
|
|
|
|
2021-10-13 14:12:40 -04:00
|
|
|
expect(page).to have_css('[data-testid="proxy-url"]')
|
2020-11-13 16:09:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows the proxy URL' do
|
2021-10-13 11:12:51 -04:00
|
|
|
visit path
|
|
|
|
|
2021-10-13 14:12:40 -04:00
|
|
|
expect(find('input[data-testid="proxy-url"]').value).to have_content('/dependency_proxy/containers')
|
2020-11-13 16:09:31 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'hides the proxy URL when feature is disabled' do
|
2021-10-13 11:12:51 -04:00
|
|
|
visit settings_path
|
|
|
|
wait_for_requests
|
|
|
|
|
|
|
|
click_button 'Enable Proxy'
|
|
|
|
|
|
|
|
expect(page).to have_button 'Enable Proxy', class: '!is-checked'
|
|
|
|
|
|
|
|
visit path
|
2020-11-13 16:09:31 -05:00
|
|
|
|
2021-10-13 14:12:40 -04:00
|
|
|
expect(page).not_to have_css('input[data-testid="proxy-url"]')
|
2020-11-13 16:09:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when logged in as group reporter' do
|
|
|
|
before do
|
|
|
|
sign_in(reporter)
|
|
|
|
visit path
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not show the feature toggle but shows the proxy URL' do
|
2021-10-13 14:12:40 -04:00
|
|
|
expect(find('input[data-testid="proxy-url"]').value).to have_content('/dependency_proxy/containers')
|
2020-11-13 16:09:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'feature is not avaible' do
|
|
|
|
before do
|
2021-10-13 11:12:51 -04:00
|
|
|
sign_in(owner)
|
2020-11-13 16:09:31 -05:00
|
|
|
end
|
|
|
|
|
2021-10-13 14:12:40 -04:00
|
|
|
context 'feature flag is disabled', :js do
|
2020-12-03 13:10:10 -05:00
|
|
|
before do
|
|
|
|
stub_feature_flags(dependency_proxy_for_private_groups: false)
|
|
|
|
end
|
2020-11-13 16:09:31 -05:00
|
|
|
|
2020-12-03 13:10:10 -05:00
|
|
|
context 'group is private' do
|
|
|
|
let(:group) { create(:group, :private) }
|
2020-11-13 16:09:31 -05:00
|
|
|
|
2020-12-03 13:10:10 -05:00
|
|
|
it 'informs user that feature is only available for public groups' do
|
|
|
|
visit path
|
|
|
|
|
2021-10-13 14:12:40 -04:00
|
|
|
expect(page).to have_content('Dependency Proxy feature is limited to public groups for now.')
|
2020-12-03 13:10:10 -05:00
|
|
|
end
|
2020-11-13 16:09:31 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'feature is disabled globally' do
|
|
|
|
it 'renders 404 page' do
|
|
|
|
disable_feature
|
|
|
|
|
|
|
|
visit path
|
|
|
|
|
|
|
|
expect(page).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def enable_feature
|
|
|
|
stub_config(dependency_proxy: { enabled: true })
|
|
|
|
end
|
|
|
|
|
|
|
|
def disable_feature
|
|
|
|
stub_config(dependency_proxy: { enabled: false })
|
|
|
|
end
|
|
|
|
end
|