Skip to content
Snippets Groups Projects
Commit fca89bb7 authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 76e9fc7b
No related branches found
No related tags found
No related merge requests found
Showing
with 192 additions and 62 deletions
Loading
Loading
@@ -3,7 +3,7 @@
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20190911251732_sync_issuables_state_id')
 
describe SyncIssuablesStateId, :migration do
describe SyncIssuablesStateId do
let(:migration) { described_class.new }
 
describe '#up' do
Loading
Loading
Loading
Loading
@@ -3,7 +3,7 @@
require 'spec_helper'
require Rails.root.join('db', 'migrate', '20190325080727_truncate_user_fullname.rb')
 
describe TruncateUserFullname, :migration do
describe TruncateUserFullname do
let(:users) { table(:users) }
 
let(:user_short) { create_user(name: 'abc', email: 'test_short@example.com') }
Loading
Loading
Loading
Loading
@@ -3,7 +3,7 @@
require 'spec_helper'
require Rails.root.join('db', 'migrate', '20200221105436_update_application_setting_npm_package_requests_forwarding_default.rb')
 
describe UpdateApplicationSettingNpmPackageRequestsForwardingDefault, :migration do
describe UpdateApplicationSettingNpmPackageRequestsForwardingDefault do
# Create test data - pipeline and CI/CD jobs.
let(:application_settings) { table(:application_settings) }
 
Loading
Loading
Loading
Loading
@@ -4,7 +4,7 @@ require 'spec_helper'
 
require Rails.root.join('db', 'post_migrate', '20200106071113_update_fingerprint_sha256_within_keys.rb')
 
describe UpdateFingerprintSha256WithinKeys, :migration do
describe UpdateFingerprintSha256WithinKeys do
let(:key_table) { table(:keys) }
 
describe '#up' do
Loading
Loading
Loading
Loading
@@ -3,7 +3,7 @@
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20191205084057_update_minimum_password_length')
 
describe UpdateMinimumPasswordLength, :migration do
describe UpdateMinimumPasswordLength do
let(:application_settings) { table(:application_settings) }
let(:application_setting) do
application_settings.create!(
Loading
Loading
Loading
Loading
@@ -3,7 +3,7 @@
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20181219130552_update_project_import_visibility_level.rb')
 
describe UpdateProjectImportVisibilityLevel, :migration do
describe UpdateProjectImportVisibilityLevel do
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
let(:project) { projects.find_by_name(name) }
Loading
Loading
Loading
Loading
@@ -4,7 +4,7 @@ require 'spec_helper'
 
require Rails.root.join('db', 'migrate', '20200116175538_update_timestamp_softwarelicensespolicy.rb')
 
describe UpdateTimestampSoftwarelicensespolicy, :migration do
describe UpdateTimestampSoftwarelicensespolicy do
let(:software_licenses_policy) { table(:software_license_policies) }
let(:projects) { table(:projects) }
let(:licenses) { table(:software_licenses) }
Loading
Loading
Loading
Loading
@@ -195,56 +195,71 @@ describe API::DeployTokens do
end
end
 
describe 'POST /projects/:id/deploy_tokens' do
let(:params) do
{
name: 'Foo',
expires_at: 1.year.from_now,
scopes: [
'read_repository'
],
username: 'Bar'
}
end
context 'deploy token creation' do
shared_examples 'creating a deploy token' do |entity, unauthenticated_response|
let(:params) do
{
name: 'Foo',
expires_at: 1.year.from_now,
scopes: [
'read_repository'
],
username: 'Bar'
}
end
 
subject do
post api("/projects/#{project.id}/deploy_tokens", user), params: params
response
end
context 'when unauthenticated' do
let(:user) { nil }
 
context 'when unauthenticated' do
let(:user) { nil }
it { is_expected.to have_gitlab_http_status(unauthenticated_response) }
end
 
it { is_expected.to have_gitlab_http_status(:not_found) }
end
context 'when authenticated as non-admin user' do
before do
send(entity).add_developer(user)
end
 
context 'when authenticated as non-admin user' do
before do
project.add_developer(user)
it { is_expected.to have_gitlab_http_status(:forbidden) }
end
 
it { is_expected.to have_gitlab_http_status(:forbidden) }
end
context 'when authenticated as maintainer' do
before do
send(entity).add_maintainer(user)
end
 
context 'when authenticated as maintainer' do
before do
project.add_maintainer(user)
end
it 'creates the deploy token' do
expect { subject }.to change { DeployToken.count }.by(1)
 
it 'creates the deploy token' do
expect { subject }.to change { DeployToken.count }.by(1)
expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/deploy_token')
end
 
expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/deploy_token')
end
context 'with an invalid scope' do
before do
params[:scopes] = %w[read_repository all_access]
end
 
context 'with an invalid scope' do
before do
params[:scopes] = %w[read_repository all_access]
it { is_expected.to have_gitlab_http_status(:bad_request) }
end
end
end
describe 'POST /projects/:id/deploy_tokens' do
subject do
post api("/projects/#{project.id}/deploy_tokens", user), params: params
response
end
it_behaves_like 'creating a deploy token', :project, :not_found
end
 
it { is_expected.to have_gitlab_http_status(:bad_request) }
describe 'POST /groups/:id/deploy_tokens' do
subject do
post api("/groups/#{group.id}/deploy_tokens", user), params: params
response
end
it_behaves_like 'creating a deploy token', :group, :forbidden
end
end
end
Loading
Loading
@@ -488,6 +488,7 @@ describe 'project routing' do
end
 
it_behaves_like 'redirecting a legacy project path', "/gitlab/gitlabhq/project_members", "/gitlab/gitlabhq/-/project_members"
it_behaves_like 'redirecting a legacy project path', "/gitlab/gitlabhq/-/settings/members", "/gitlab/gitlabhq/-/project_members"
end
 
# project_milestones GET /:project_id/milestones(.:format) milestones#index
Loading
Loading
Loading
Loading
@@ -8,18 +8,27 @@ describe Projects::LfsPointers::LfsDownloadLinkListService do
let(:new_oids) { { 'oid1' => 123, 'oid2' => 125 } }
let(:remote_uri) { URI.parse(lfs_endpoint) }
 
let(:objects_response) do
body = new_oids.map do |oid, size|
let(:request_object) { HTTParty::Request.new(Net::HTTP::Post, '/') }
let(:parsed_block) { lambda {} }
let(:success_net_response) { Net::HTTPOK.new('', '', '') }
let(:response) { Gitlab::HTTP::Response.new(request_object, net_response, parsed_block) }
def objects_response(oids)
body = oids.map do |oid, size|
{
'oid' => oid,
'size' => size,
'oid' => oid, 'size' => size,
'actions' => {
'download' => { 'href' => "#{import_url}/gitlab-lfs/objects/#{oid}" }
}
}
end
 
Struct.new(:success?, :objects).new(true, body)
Struct.new(:success?, :objects).new(true, body).to_json
end
def custom_response(net_response, body = nil)
allow(net_response).to receive(:body).and_return(body)
Gitlab::HTTP::Response.new(request_object, net_response, parsed_block)
end
 
let(:invalid_object_response) do
Loading
Loading
@@ -33,9 +42,8 @@ describe Projects::LfsPointers::LfsDownloadLinkListService do
 
before do
allow(project).to receive(:lfs_enabled?).and_return(true)
response = instance_double(Gitlab::HTTP::Response)
allow(response).to receive(:body).and_return(objects_response.to_json)
allow(response).to receive(:success?).and_return(true)
response = custom_response(success_net_response, objects_response(new_oids))
allow(Gitlab::HTTP).to receive(:post).and_return(response)
end
 
Loading
Loading
@@ -46,6 +54,102 @@ describe Projects::LfsPointers::LfsDownloadLinkListService do
end
end
 
context 'when lfs objects size is larger than the batch size' do
def stub_successful_request(batch)
response = custom_response(success_net_response, objects_response(batch))
stub_request(batch, response)
end
def stub_entity_too_large_error_request(batch)
entity_too_large_net_response = Net::HTTPRequestEntityTooLarge.new('', '', '')
response = custom_response(entity_too_large_net_response)
stub_request(batch, response)
end
def stub_request(batch, response)
expect(Gitlab::HTTP).to receive(:post).with(
remote_uri,
{
body: { operation: 'download', objects: batch.map { |k, v| { oid: k, size: v } } }.to_json,
headers: subject.send(:headers)
}
).and_return(response)
end
let(:new_oids) { { 'oid1' => 123, 'oid2' => 125, 'oid3' => 126, 'oid4' => 127, 'oid5' => 128 } }
context 'when batch size' do
before do
stub_const("#{described_class.name}::REQUEST_BATCH_SIZE", 2)
data = new_oids.to_a
stub_successful_request([data[0], data[1]])
stub_successful_request([data[2], data[3]])
stub_successful_request([data[4]])
end
it 'retreives them in batches' do
subject.execute(new_oids).each do |lfs_download_object|
expect(lfs_download_object.link).to eq "#{import_url}/gitlab-lfs/objects/#{lfs_download_object.oid}"
end
end
end
context 'when request fails with PayloadTooLarge error' do
let(:error_class) { described_class::DownloadLinksRequestEntityTooLargeError }
context 'when the smaller batch eventually works' do
before do
stub_const("#{described_class.name}::REQUEST_BATCH_SIZE", 5)
data = new_oids.to_a
# with the batch size of 5
stub_entity_too_large_error_request(data)
# with the batch size of 2
stub_successful_request([data[0], data[1]])
stub_successful_request([data[2], data[3]])
stub_successful_request([data[4]])
end
it 'retreives them eventually and logs exceptions' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
an_instance_of(error_class), project_id: project.id, batch_size: 5, oids_count: 5
)
subject.execute(new_oids).each do |lfs_download_object|
expect(lfs_download_object.link).to eq "#{import_url}/gitlab-lfs/objects/#{lfs_download_object.oid}"
end
end
end
context 'when batch size cannot be any smaller' do
before do
stub_const("#{described_class.name}::REQUEST_BATCH_SIZE", 5)
data = new_oids.to_a
# with the batch size of 5
stub_entity_too_large_error_request(data)
# with the batch size of 2
stub_entity_too_large_error_request([data[0], data[1]])
end
it 'raises an error and logs exceptions' do
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
an_instance_of(error_class), project_id: project.id, batch_size: 5, oids_count: 5
)
expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
an_instance_of(error_class), project_id: project.id, batch_size: 2, oids_count: 5
)
expect { subject.execute(new_oids) }.to raise_error(described_class::DownloadLinksError)
end
end
end
end
context 'credentials' do
context 'when the download link and the lfs_endpoint have the same host' do
context 'when lfs_endpoint has credentials' do
Loading
Loading
@@ -87,17 +191,22 @@ describe Projects::LfsPointers::LfsDownloadLinkListService do
end
 
describe '#get_download_links' do
it 'raise error if request fails' do
allow(Gitlab::HTTP).to receive(:post).and_return(Struct.new(:success?, :message).new(false, 'Failed request'))
context 'if request fails' do
before do
request_timeout_net_response = Net::HTTPRequestTimeout.new('', '', '')
response = custom_response(request_timeout_net_response)
allow(Gitlab::HTTP).to receive(:post).and_return(response)
end
 
expect { subject.send(:get_download_links, new_oids) }.to raise_error(described_class::DownloadLinksError)
it 'raises an error' do
expect { subject.send(:get_download_links, new_oids) }.to raise_error(described_class::DownloadLinksError)
end
end
 
shared_examples 'JSON parse errors' do |body|
it 'raises error' do
response = instance_double(Gitlab::HTTP::Response)
it 'raises an error' do
response = custom_response(success_net_response)
allow(response).to receive(:body).and_return(body)
allow(response).to receive(:success?).and_return(true)
allow(Gitlab::HTTP).to receive(:post).and_return(response)
 
expect { subject.send(:get_download_links, new_oids) }.to raise_error(described_class::DownloadLinksError)
Loading
Loading
Loading
Loading
@@ -76,11 +76,16 @@ RSpec.configure do |config|
metadata[:level] = quality_level.level_for(location)
metadata[:api] = true if location =~ %r{/spec/requests/api/}
 
# do not overwrite type if it's already set
next if metadata.key?(:type)
# Do not overwrite migration if it's already set
unless metadata.key?(:migration)
metadata[:migration] = true if metadata[:level] == :migration
end
 
match = location.match(%r{/spec/([^/]+)/})
metadata[:type] = match[1].singularize.to_sym if match
# Do not overwrite type if it's already set
unless metadata.key?(:type)
match = location.match(%r{/spec/([^/]+)/})
metadata[:type] = match[1].singularize.to_sym if match
end
end
 
config.include LicenseHelpers
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment