Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 22:00:14 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 22:00:14 +0300
commit05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch)
tree11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /spec/support/shared_examples/controllers
parentec73467c23693d0db63a797d10194da9e72a74af (diff)
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'spec/support/shared_examples/controllers')
-rw-r--r--spec/support/shared_examples/controllers/githubish_import_controller_shared_examples.rb121
-rw-r--r--spec/support/shared_examples/controllers/issuables_list_metadata_shared_examples.rb4
-rw-r--r--spec/support/shared_examples/controllers/rate_limited_endpoint_shared_examples.rb26
3 files changed, 40 insertions, 111 deletions
diff --git a/spec/support/shared_examples/controllers/githubish_import_controller_shared_examples.rb b/spec/support/shared_examples/controllers/githubish_import_controller_shared_examples.rb
index 5506b05ca55..de38d1ff9f8 100644
--- a/spec/support/shared_examples/controllers/githubish_import_controller_shared_examples.rb
+++ b/spec/support/shared_examples/controllers/githubish_import_controller_shared_examples.rb
@@ -258,7 +258,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do
.to receive(:new).with(provider_repo, provider_repo[:name], user.namespace, user, type: provider, **access_params)
.and_return(double(execute: project))
- post :create, format: :json
+ post :create, params: { target_namespace: user.namespace }, format: :json
expect(response).to have_gitlab_http_status(:ok)
end
@@ -272,7 +272,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do
.to receive(:new).with(provider_repo, provider_repo[:name], user.namespace, user, type: provider, **access_params)
.and_return(double(execute: project))
- post :create, format: :json
+ post :create, params: { target_namespace: user.namespace_path }, format: :json
expect(response).to have_gitlab_http_status(:unprocessable_entity)
expect(json_response['errors']).to eq('Name is invalid, Path is old')
@@ -286,7 +286,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do
expect(store).to receive(:touch) { "realtime_changes_import_#{provider}_path" }
end
- post :create, format: :json
+ post :create, params: { target_namespace: user.namespace_path }, format: :json
end
context "when the repository owner is the provider user" do
@@ -296,7 +296,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do
.to receive(:new).with(provider_repo, provider_repo[:name], user.namespace, user, type: provider, **access_params)
.and_return(double(execute: project))
- post :create, format: :json
+ post :create, params: { target_namespace: user.namespace_path }, format: :json
end
end
@@ -308,7 +308,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do
.to receive(:new).with(provider_repo, provider_repo[:name], user.namespace, user, type: provider, **access_params)
.and_return(double(execute: project))
- post :create, format: :json
+ post :create, params: { target_namespace: user.namespace_path }, format: :json
end
end
end
@@ -333,7 +333,7 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do
.to receive(:new).with(provider_repo, provider_repo[:name], existing_namespace, user, type: provider, **access_params)
.and_return(double(execute: project))
- post :create, format: :json
+ post :create, params: { target_namespace: user.namespace_path }, format: :json
end
end
@@ -345,47 +345,17 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do
.to receive(:new).with(provider_repo, provider_repo[:name], user.namespace, user, type: provider, **access_params)
.and_return(double(execute: project))
- post :create, format: :json
+ post :create, params: { target_namespace: user.namespace_path }, format: :json
end
end
end
context "when a namespace with the provider user's username doesn't exist" do
context "when current user can create namespaces" do
- it "creates the namespace" do
- expect(Gitlab::LegacyGithubImport::ProjectCreator)
- .to receive(:new).and_return(double(execute: project))
-
- expect { post :create, params: { target_namespace: provider_repo[:name] }, format: :json }.to change { Namespace.count }.by(1)
- end
-
- it "takes the new namespace" do
- expect(Gitlab::LegacyGithubImport::ProjectCreator)
- .to receive(:new).with(provider_repo, provider_repo[:name], an_instance_of(Group), user, type: provider, **access_params)
- .and_return(double(execute: project))
-
- post :create, params: { target_namespace: provider_repo[:name] }, format: :json
- end
- end
-
- context "when current user can't create namespaces" do
- before do
- user.update_attribute(:can_create_group, false)
- end
-
- it "doesn't create the namespace" do
- expect(Gitlab::LegacyGithubImport::ProjectCreator)
- .to receive(:new).and_return(double(execute: project))
-
- expect { post :create, format: :json }.not_to change { Namespace.count }
- end
+ it "does not create the namespace" do
+ expect(Gitlab::LegacyGithubImport::ProjectCreator).not_to receive(:new)
- it "takes the current user's namespace" do
- expect(Gitlab::LegacyGithubImport::ProjectCreator)
- .to receive(:new).with(provider_repo, provider_repo[:name], user.namespace, user, type: provider, **access_params)
- .and_return(double(execute: project))
-
- post :create, format: :json
+ expect { post :create, params: { target_namespace: provider_repo[:name] }, format: :json }.not_to change { Namespace.count }
end
end
end
@@ -405,14 +375,6 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do
post :create, params: { target_namespace: test_namespace.name, new_name: test_name }, format: :json
end
-
- it 'takes the selected name and default namespace' do
- expect(Gitlab::LegacyGithubImport::ProjectCreator)
- .to receive(:new).with(provider_repo, test_name, user.namespace, user, type: provider, **access_params)
- .and_return(double(execute: project))
-
- post :create, params: { new_name: test_name }, format: :json
- end
end
context 'user has chosen an existing nested namespace and name for the project' do
@@ -437,31 +399,16 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do
context 'user has chosen a non-existent nested namespaces and name for the project' do
let(:test_name) { 'test_name' }
- it 'takes the selected namespace and name' do
+ it 'does not take the selected namespace and name' do
expect(Gitlab::LegacyGithubImport::ProjectCreator)
- .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, type: provider, **access_params)
- .and_return(double(execute: project))
+ .not_to receive(:new)
post :create, params: { target_namespace: 'foo/bar', new_name: test_name }, format: :json
end
- it 'creates the namespaces' do
- allow(Gitlab::LegacyGithubImport::ProjectCreator)
- .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, type: provider, **access_params)
- .and_return(double(execute: project))
-
+ it 'does not create namespaces' do
expect { post :create, params: { target_namespace: 'foo/bar', new_name: test_name }, format: :json }
- .to change { Namespace.count }.by(2)
- end
-
- it 'new namespace has the right parent' do
- allow(Gitlab::LegacyGithubImport::ProjectCreator)
- .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, type: provider, **access_params)
- .and_return(double(execute: project))
-
- post :create, params: { target_namespace: 'foo/bar', new_name: test_name }, format: :json
-
- expect(Namespace.find_by_path_or_name('bar').parent.path).to eq('foo')
+ .not_to change { Namespace.count }
end
end
@@ -473,55 +420,25 @@ RSpec.shared_examples 'a GitHub-ish import controller: POST create' do
parent_namespace.add_owner(user)
end
- it 'takes the selected namespace and name' do
- expect(Gitlab::LegacyGithubImport::ProjectCreator)
- .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, type: provider, **access_params)
- .and_return(double(execute: project))
+ it 'does not take the selected namespace and name' do
+ expect(Gitlab::LegacyGithubImport::ProjectCreator).not_to receive(:new)
post :create, params: { target_namespace: 'foo/foobar/bar', new_name: test_name }, format: :json
end
- it 'creates the namespaces' do
- allow(Gitlab::LegacyGithubImport::ProjectCreator)
- .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, type: provider, **access_params)
- .and_return(double(execute: project))
-
+ it 'does not create the namespaces' do
expect { post :create, params: { target_namespace: 'foo/foobar/bar', new_name: test_name }, format: :json }
- .to change { Namespace.count }.by(2)
+ .not_to change { Namespace.count }
end
it 'does not create a new namespace under the user namespace' do
- expect(Gitlab::LegacyGithubImport::ProjectCreator)
- .to receive(:new).with(provider_repo, test_name, user.namespace, user, type: provider, **access_params)
- .and_return(double(execute: project))
+ expect(Gitlab::LegacyGithubImport::ProjectCreator).not_to receive(:new)
expect { post :create, params: { target_namespace: "#{user.namespace_path}/test_group", new_name: test_name }, format: :js }
.not_to change { Namespace.count }
end
end
- context 'user cannot create a subgroup inside a group is not a member of' do
- let(:test_name) { 'test_name' }
- let!(:parent_namespace) { create(:group, name: 'foo') }
-
- it 'does not take the selected namespace and name' do
- expect(Gitlab::LegacyGithubImport::ProjectCreator)
- .to receive(:new).with(provider_repo, test_name, user.namespace, user, type: provider, **access_params)
- .and_return(double(execute: project))
-
- post :create, params: { target_namespace: 'foo/foobar/bar', new_name: test_name }, format: :js
- end
-
- it 'does not create the namespaces' do
- allow(Gitlab::LegacyGithubImport::ProjectCreator)
- .to receive(:new).with(provider_repo, test_name, kind_of(Namespace), user, type: provider, **access_params)
- .and_return(double(execute: project))
-
- expect { post :create, params: { target_namespace: 'foo/foobar/bar', new_name: test_name }, format: :js }
- .not_to change { Namespace.count }
- end
- end
-
context 'user can use a group without having permissions to create a group' do
let(:test_name) { 'test_name' }
let!(:group) { create(:group, name: 'foo') }
diff --git a/spec/support/shared_examples/controllers/issuables_list_metadata_shared_examples.rb b/spec/support/shared_examples/controllers/issuables_list_metadata_shared_examples.rb
index 02915206cc5..446bc4cd92f 100644
--- a/spec/support/shared_examples/controllers/issuables_list_metadata_shared_examples.rb
+++ b/spec/support/shared_examples/controllers/issuables_list_metadata_shared_examples.rb
@@ -42,6 +42,10 @@ RSpec.shared_examples 'issuables list meta-data' do |issuable_type, action = nil
let(:result_issuable) { issuables.first }
let(:search) { result_issuable.title }
+ before do
+ stub_application_setting(search_rate_limit: 0, search_rate_limit_unauthenticated: 0)
+ end
+
# .simple_sorts is the same across all Sortable classes
sorts = ::Issue.simple_sorts.keys + %w[popularity priority label_priority]
sorts.each do |sort|
diff --git a/spec/support/shared_examples/controllers/rate_limited_endpoint_shared_examples.rb b/spec/support/shared_examples/controllers/rate_limited_endpoint_shared_examples.rb
index 20edca1ee9f..b34038ca0e4 100644
--- a/spec/support/shared_examples/controllers/rate_limited_endpoint_shared_examples.rb
+++ b/spec/support/shared_examples/controllers/rate_limited_endpoint_shared_examples.rb
@@ -5,7 +5,9 @@
# - current_user
# - error_message # optional
-RSpec.shared_examples 'rate limited endpoint' do |rate_limit_key:|
+RSpec.shared_examples 'rate limited endpoint' do |rate_limit_key:, graphql: false|
+ let(:error_message) { _('This endpoint has been requested too many times. Try again later.') }
+
context 'when rate limiter enabled', :freeze_time, :clean_gitlab_redis_rate_limiting do
let(:expected_logger_attributes) do
{
@@ -25,8 +27,6 @@ RSpec.shared_examples 'rate limited endpoint' do |rate_limit_key:|
end
end
- let(:error_message) { _('This endpoint has been requested too many times. Try again later.') }
-
before do
allow(Gitlab::ApplicationRateLimiter).to receive(:threshold).with(rate_limit_key).and_return(1)
end
@@ -37,12 +37,16 @@ RSpec.shared_examples 'rate limited endpoint' do |rate_limit_key:|
request
request
- expect(response).to have_gitlab_http_status(:too_many_requests)
+ if graphql
+ expect_graphql_errors_to_include(error_message)
+ else
+ expect(response).to have_gitlab_http_status(:too_many_requests)
- if example.metadata[:type] == :controller
- expect(response.body).to eq(error_message)
- else # it is API spec
- expect(response.body).to eq({ message: { error: error_message } }.to_json)
+ if response.content_type == 'application/json' # it is API spec
+ expect(response.body).to eq({ message: { error: error_message } }.to_json)
+ else
+ expect(response.body).to eq(error_message)
+ end
end
end
end
@@ -57,7 +61,11 @@ RSpec.shared_examples 'rate limited endpoint' do |rate_limit_key:|
request
- expect(response).not_to have_gitlab_http_status(:too_many_requests)
+ if graphql
+ expect_graphql_errors_to_be_empty
+ else
+ expect(response).not_to have_gitlab_http_status(:too_many_requests)
+ end
end
end
end