diff options
author | Ahmad Sherif <me@ahmadsherif.com> | 2019-07-10 20:34:05 +0300 |
---|---|---|
committer | Ahmad Sherif <me@ahmadsherif.com> | 2019-07-23 21:37:49 +0300 |
commit | 7b76c8d644624f9a8a05e2e7a39af30c0c0c4ae0 (patch) | |
tree | e11013ab87b27c5020f10a7471cecea3b15a891d /spec/controllers/projects | |
parent | 5b669c191d766ab980d647107d7c183be5f8f99e (diff) |
Return an ETag headers for the archive endpoint
We use the relative path of the archive to check for archive staleness.
Diffstat (limited to 'spec/controllers/projects')
-rw-r--r-- | spec/controllers/projects/repositories_controller_spec.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/controllers/projects/repositories_controller_spec.rb b/spec/controllers/projects/repositories_controller_spec.rb index 8fca9e680dd..fcab4d73dca 100644 --- a/spec/controllers/projects/repositories_controller_spec.rb +++ b/spec/controllers/projects/repositories_controller_spec.rb @@ -77,6 +77,53 @@ describe Projects::RepositoriesController do expect(response).to have_gitlab_http_status(404) end end + + describe 'caching' do + it 'sets appropriate caching headers' do + get_archive + + expect(response).to have_gitlab_http_status(200) + expect(response.header['ETag']).to be_present + expect(response.header['Cache-Control']).to include('max-age=60, private') + end + + context 'when project is public' do + let(:project) { create(:project, :repository, :public) } + + it 'sets appropriate caching headers' do + get_archive + + expect(response).to have_gitlab_http_status(200) + expect(response.header['ETag']).to be_present + expect(response.header['Cache-Control']).to include('max-age=60, public') + end + end + + context 'when ref is a commit SHA' do + it 'max-age is set to 3600 in Cache-Control header' do + get_archive('ddd0f15ae83993f5cb66a927a28673882e99100b') + + expect(response).to have_gitlab_http_status(200) + expect(response.header['Cache-Control']).to include('max-age=3600') + end + end + + context 'when If-None-Modified header is set' do + it 'returns a 304 status' do + # Get the archive cached first + get_archive + + request.headers['If-None-Match'] = response.headers['ETag'] + get_archive + + expect(response).to have_gitlab_http_status(304) + end + end + + def get_archive(id = 'feature') + get :archive, params: { namespace_id: project.namespace, project_id: project, id: id }, format: 'zip' + end + end end end end |