diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-15 09:09:46 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-15 09:09:46 +0000 |
commit | 221b529789f4090341a825695aeb49b8df6dd11d (patch) | |
tree | c8843e4ca5ef1034752eb68712fcf338b24950db /spec/lib | |
parent | 00a8c64ffd18e74df4b1cdeda7776b5221fddafe (diff) | |
download | gitlab-ce-221b529789f4090341a825695aeb49b8df6dd11d.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/container_registry/client_spec.rb | 67 | ||||
-rw-r--r-- | spec/lib/gitlab/static_site_editor/config_spec.rb | 35 |
2 files changed, 86 insertions, 16 deletions
diff --git a/spec/lib/container_registry/client_spec.rb b/spec/lib/container_registry/client_spec.rb index 5d2334a6d8f..0aad6568793 100644 --- a/spec/lib/container_registry/client_spec.rb +++ b/spec/lib/container_registry/client_spec.rb @@ -6,6 +6,21 @@ describe ContainerRegistry::Client do let(:token) { '12345' } let(:options) { { token: token } } let(:client) { described_class.new("http://container-registry", options) } + let(:push_blob_headers) do + { + 'Accept' => 'application/vnd.docker.distribution.manifest.v2+json, application/vnd.oci.image.manifest.v1+json', + 'Authorization' => "bearer #{token}", + 'Content-Type' => 'application/octet-stream', + 'User-Agent' => "GitLab/#{Gitlab::VERSION}" + } + end + let(:headers_with_accept_types) do + { + 'Accept' => 'application/vnd.docker.distribution.manifest.v2+json, application/vnd.oci.image.manifest.v1+json', + 'Authorization' => "bearer #{token}", + 'User-Agent' => "GitLab/#{Gitlab::VERSION}" + } + end shared_examples '#repository_manifest' do |manifest_type| let(:manifest) do @@ -25,14 +40,15 @@ describe ContainerRegistry::Client do "size" => 2828661 } ] - } + } end it 'GET /v2/:name/manifests/mytag' do stub_request(:get, "http://container-registry/v2/group/test/manifests/mytag") .with(headers: { - 'Accept' => described_class::ACCEPTED_TYPES.join(', '), - 'Authorization' => "bearer #{token}" + 'Accept' => 'application/vnd.docker.distribution.manifest.v2+json, application/vnd.oci.image.manifest.v1+json', + 'Authorization' => "bearer #{token}", + 'User-Agent' => "GitLab/#{Gitlab::VERSION}" }) .to_return(status: 200, body: manifest.to_json, headers: { content_type: manifest_type }) @@ -44,12 +60,23 @@ describe ContainerRegistry::Client do it_behaves_like '#repository_manifest', described_class::OCI_MANIFEST_V1_TYPE describe '#blob' do + let(:blob_headers) do + { + 'Accept' => 'application/octet-stream', + 'Authorization' => "bearer #{token}", + 'User-Agent' => "GitLab/#{Gitlab::VERSION}" + } + end + + let(:redirect_header) do + { + 'User-Agent' => "GitLab/#{Gitlab::VERSION}" + } + end + it 'GET /v2/:name/blobs/:digest' do stub_request(:get, "http://container-registry/v2/group/test/blobs/sha256:0123456789012345") - .with(headers: { - 'Accept' => 'application/octet-stream', - 'Authorization' => "bearer #{token}" - }) + .with(headers: blob_headers) .to_return(status: 200, body: "Blob") expect(client.blob('group/test', 'sha256:0123456789012345')).to eq('Blob') @@ -57,15 +84,14 @@ describe ContainerRegistry::Client do it 'follows 307 redirect for GET /v2/:name/blobs/:digest' do stub_request(:get, "http://container-registry/v2/group/test/blobs/sha256:0123456789012345") - .with(headers: { - 'Accept' => 'application/octet-stream', - 'Authorization' => "bearer #{token}" - }) + .with(headers: blob_headers) .to_return(status: 307, body: "", headers: { Location: 'http://redirected' }) # We should probably use hash_excluding here, but that requires an update to WebMock: # https://github.com/bblimke/webmock/blob/master/lib/webmock/matchers/hash_excluding_matcher.rb stub_request(:get, "http://redirected/") - .with { |request| !request.headers.include?('Authorization') } + .with(headers: redirect_header) do |request| + !request.headers.include?('Authorization') + end .to_return(status: 200, body: "Successfully redirected") response = client.blob('group/test', 'sha256:0123456789012345') @@ -76,10 +102,11 @@ describe ContainerRegistry::Client do def stub_upload(path, content, digest, status = 200) stub_request(:post, "http://container-registry/v2/#{path}/blobs/uploads/") + .with(headers: headers_with_accept_types) .to_return(status: status, body: "", headers: { 'location' => 'http://container-registry/next_upload?id=someid' }) stub_request(:put, "http://container-registry/next_upload?digest=#{digest}&id=someid") - .with(body: content) + .with(body: content, headers: push_blob_headers) .to_return(status: status, body: "", headers: {}) end @@ -136,11 +163,20 @@ describe ContainerRegistry::Client do end describe '#put_tag' do + let(:manifest_headers) do + { + 'Accept' => 'application/vnd.docker.distribution.manifest.v2+json, application/vnd.oci.image.manifest.v1+json', + 'Authorization' => "bearer #{token}", + 'Content-Type' => 'application/vnd.docker.distribution.manifest.v2+json', + 'User-Agent' => "GitLab/#{Gitlab::VERSION}" + } + end + subject { client.put_tag('path', 'tagA', { foo: :bar }) } it 'uploads the manifest and returns the digest' do stub_request(:put, "http://container-registry/v2/path/manifests/tagA") - .with(body: "{\n \"foo\": \"bar\"\n}") + .with(body: "{\n \"foo\": \"bar\"\n}", headers: manifest_headers) .to_return(status: 200, body: "", headers: { 'docker-content-digest' => 'sha256:123' }) expect(subject).to eq 'sha256:123' @@ -153,6 +189,7 @@ describe ContainerRegistry::Client do context 'when the tag exists' do before do stub_request(:delete, "http://container-registry/v2/group/test/tags/reference/a") + .with(headers: headers_with_accept_types) .to_return(status: 200, body: "") end @@ -162,6 +199,7 @@ describe ContainerRegistry::Client do context 'when the tag does not exist' do before do stub_request(:delete, "http://container-registry/v2/group/test/tags/reference/a") + .with(headers: headers_with_accept_types) .to_return(status: 404, body: "") end @@ -171,6 +209,7 @@ describe ContainerRegistry::Client do context 'when an error occurs' do before do stub_request(:delete, "http://container-registry/v2/group/test/tags/reference/a") + .with(headers: headers_with_accept_types) .to_return(status: 500, body: "") end diff --git a/spec/lib/gitlab/static_site_editor/config_spec.rb b/spec/lib/gitlab/static_site_editor/config_spec.rb index dea79fb0e92..8f61476722d 100644 --- a/spec/lib/gitlab/static_site_editor/config_spec.rb +++ b/spec/lib/gitlab/static_site_editor/config_spec.rb @@ -18,13 +18,44 @@ describe Gitlab::StaticSiteEditor::Config do it 'returns data for the frontend component' do is_expected.to eq( branch: 'master', - commit: repository.commit.id, + commit_id: repository.commit.id, namespace: 'namespace', path: 'README.md', project: 'project', project_id: project.id, - return_url: 'http://example.com' + return_url: 'http://example.com', + is_supported_content: true ) end + + context 'when branch is not master' do + let(:ref) { 'my-branch' } + + it { is_expected.to include(is_supported_content: false) } + end + + context 'when file does not have a markdown extension' do + let(:file_path) { 'README.txt' } + + it { is_expected.to include(is_supported_content: false) } + end + + context 'when file does not have an extension' do + let(:file_path) { 'README' } + + it { is_expected.to include(is_supported_content: false) } + end + + context 'when file does not exist' do + let(:file_path) { 'UNKNOWN.md' } + + it { is_expected.to include(is_supported_content: false) } + end + + context 'when repository is empty' do + let(:project) { create(:project_empty_repo) } + + it { is_expected.to include(is_supported_content: false) } + end end end |