diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-21 12:09:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-21 12:09:11 +0300 |
commit | 49abdb108a4d3c3f2ef9b27c7c4dcde43da1016a (patch) | |
tree | 31dee66af9f14c3bd320c349810d877d96fd66cf /spec/requests | |
parent | 760dc7721406a82bbea06f3512a4e270d0bb3f0a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/helpers_spec.rb | 6 | ||||
-rw-r--r-- | spec/requests/api/npm_group_packages_spec.rb | 8 | ||||
-rw-r--r-- | spec/requests/api/npm_instance_packages_spec.rb | 8 | ||||
-rw-r--r-- | spec/requests/api/npm_project_packages_spec.rb | 42 |
4 files changed, 64 insertions, 0 deletions
diff --git a/spec/requests/api/helpers_spec.rb b/spec/requests/api/helpers_spec.rb index 0be9df41e8f..7304437bc42 100644 --- a/spec/requests/api/helpers_spec.rb +++ b/spec/requests/api/helpers_spec.rb @@ -32,6 +32,9 @@ RSpec.describe API::Helpers, :enable_admin_mode, feature_category: :system_acces before do allow_any_instance_of(self.class).to receive(:options).and_return({}) + + allow(env['rack.session']).to receive(:enabled?).and_return(true) + allow(env['rack.session']).to receive(:loaded?).and_return(true) end def warden_authenticate_returns(value) @@ -567,6 +570,9 @@ RSpec.describe API::Helpers, :enable_admin_mode, feature_category: :system_acces context 'using warden authentication' do before do + allow(session).to receive(:enabled?).and_return(true) + allow(session).to receive(:loaded?).and_return(true) + warden_authenticate_returns admin env[API::Helpers::SUDO_HEADER] = user.username end diff --git a/spec/requests/api/npm_group_packages_spec.rb b/spec/requests/api/npm_group_packages_spec.rb index d97c7682b4b..efb606b23d7 100644 --- a/spec/requests/api/npm_group_packages_spec.rb +++ b/spec/requests/api/npm_group_packages_spec.rb @@ -152,6 +152,14 @@ RSpec.describe API::NpmGroupPackages, feature_category: :package_registry do it_behaves_like 'returning response status', params[:expected_status] end end + + context 'when metadata cache exists' do + let_it_be(:npm_metadata_cache) { create(:npm_metadata_cache, package_name: package.name, project_id: project.id) } + + subject { get(url) } + + it_behaves_like 'generates metadata response "on-the-fly"' + end end describe 'GET /api/v4/packages/npm/-/package/*package_name/dist-tags' do diff --git a/spec/requests/api/npm_instance_packages_spec.rb b/spec/requests/api/npm_instance_packages_spec.rb index 97de7fa9e52..63a50e7f511 100644 --- a/spec/requests/api/npm_instance_packages_spec.rb +++ b/spec/requests/api/npm_instance_packages_spec.rb @@ -45,6 +45,14 @@ RSpec.describe API::NpmInstancePackages, feature_category: :package_registry do end end end + + context 'when metadata cache exists' do + let_it_be(:npm_metadata_cache) { create(:npm_metadata_cache, package_name: package.name, project_id: project.id) } + + subject { get(url) } + + it_behaves_like 'generates metadata response "on-the-fly"' + end end describe 'GET /api/v4/packages/npm/-/package/*package_name/dist-tags' do diff --git a/spec/requests/api/npm_project_packages_spec.rb b/spec/requests/api/npm_project_packages_spec.rb index 60d4bddc502..33418e85601 100644 --- a/spec/requests/api/npm_project_packages_spec.rb +++ b/spec/requests/api/npm_project_packages_spec.rb @@ -26,6 +26,48 @@ RSpec.describe API::NpmProjectPackages, feature_category: :package_registry do it_behaves_like 'rejects invalid package names' do subject { get(url) } end + + context 'when metadata cache exists', :aggregate_failures do + let!(:npm_metadata_cache) { create(:npm_metadata_cache, package_name: package.name, project_id: project.id) } + let(:metadata) { Gitlab::Json.parse(npm_metadata_cache.file.read.gsub('dist_tags', 'dist-tags')) } + + subject { get(url) } + + before do + project.add_developer(user) + end + + it 'returns response from metadata cache' do + expect(Packages::Npm::GenerateMetadataService).not_to receive(:new) + expect(Packages::Npm::MetadataCache).to receive(:find_by_package_name_and_project_id) + .with(package.name, project.id).and_call_original + + subject + + expect(json_response).to eq(metadata) + end + + it 'bumps last_downloaded_at of metadata cache' do + expect { subject } + .to change { npm_metadata_cache.reload.last_downloaded_at }.from(nil).to(instance_of(ActiveSupport::TimeWithZone)) + end + + context 'when npm_metadata_cache disabled' do + before do + stub_feature_flags(npm_metadata_cache: false) + end + + it_behaves_like 'generates metadata response "on-the-fly"' + end + + context 'when metadata cache file does not exist' do + before do + FileUtils.rm_rf(npm_metadata_cache.file.path) + end + + it_behaves_like 'generates metadata response "on-the-fly"' + end + end end describe 'GET /api/v4/projects/:id/packages/npm/-/package/*package_name/dist-tags' do |