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>2020-05-20 17:34:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-20 17:34:42 +0300
commit9f46488805e86b1bc341ea1620b866016c2ce5ed (patch)
treef9748c7e287041e37d6da49e0a29c9511dc34768 /spec/support/shared_examples/controllers
parentdfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff)
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/support/shared_examples/controllers')
-rw-r--r--spec/support/shared_examples/controllers/instance_statistics_controllers_shared_examples.rb20
-rw-r--r--spec/support/shared_examples/controllers/known_sign_in_shared_examples.rb59
-rw-r--r--spec/support/shared_examples/controllers/variables_shared_examples.rb25
3 files changed, 95 insertions, 9 deletions
diff --git a/spec/support/shared_examples/controllers/instance_statistics_controllers_shared_examples.rb b/spec/support/shared_examples/controllers/instance_statistics_controllers_shared_examples.rb
index e4d59463d93..17087456720 100644
--- a/spec/support/shared_examples/controllers/instance_statistics_controllers_shared_examples.rb
+++ b/spec/support/shared_examples/controllers/instance_statistics_controllers_shared_examples.rb
@@ -27,12 +27,24 @@ RSpec.shared_examples 'instance statistics availability' do
context 'for admins' do
let(:user) { create(:admin) }
- it 'allows access when the feature is not available publicly' do
- stub_application_setting(instance_statistics_visibility_private: true)
+ context 'when admin mode disabled' do
+ it 'forbids access when the feature is not available publicly' do
+ stub_application_setting(instance_statistics_visibility_private: true)
- get :index
+ get :index
- expect(response).to have_gitlab_http_status(:success)
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+
+ context 'when admin mode enabled', :enable_admin_mode do
+ it 'allows access when the feature is not available publicly' do
+ stub_application_setting(instance_statistics_visibility_private: true)
+
+ get :index
+
+ expect(response).to have_gitlab_http_status(:success)
+ end
end
end
end
diff --git a/spec/support/shared_examples/controllers/known_sign_in_shared_examples.rb b/spec/support/shared_examples/controllers/known_sign_in_shared_examples.rb
new file mode 100644
index 00000000000..60abb76acec
--- /dev/null
+++ b/spec/support/shared_examples/controllers/known_sign_in_shared_examples.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+RSpec.shared_examples 'known sign in' do
+ def stub_remote_ip(ip)
+ request.remote_ip = ip
+ end
+
+ def stub_user_ip(ip)
+ user.update!(current_sign_in_ip: ip)
+ end
+
+ context 'with a valid post' do
+ context 'when remote IP does not match user last sign in IP' do
+ before do
+ stub_user_ip('127.0.0.1')
+ stub_remote_ip('169.0.0.1')
+ end
+
+ it 'notifies the user' do
+ expect_next_instance_of(NotificationService) do |instance|
+ expect(instance).to receive(:unknown_sign_in)
+ end
+
+ post_action
+ end
+ end
+
+ context 'when remote IP matches an active session' do
+ before do
+ existing_sessions = ActiveSession.session_ids_for_user(user.id)
+ existing_sessions.each { |sessions| ActiveSession.destroy(user, sessions) }
+
+ stub_user_ip('169.0.0.1')
+ stub_remote_ip('127.0.0.1')
+
+ ActiveSession.set(user, request)
+ end
+
+ it 'does not notify the user' do
+ expect_any_instance_of(NotificationService).not_to receive(:unknown_sign_in)
+
+ post_action
+ end
+ end
+
+ context 'when remote IP address matches last sign in IP' do
+ before do
+ stub_user_ip('127.0.0.1')
+ stub_remote_ip('127.0.0.1')
+ end
+
+ it 'does not notify the user' do
+ expect_any_instance_of(NotificationService).not_to receive(:unknown_sign_in)
+
+ post_action
+ end
+ end
+ end
+end
diff --git a/spec/support/shared_examples/controllers/variables_shared_examples.rb b/spec/support/shared_examples/controllers/variables_shared_examples.rb
index 752bdc47851..9ff0bc3d217 100644
--- a/spec/support/shared_examples/controllers/variables_shared_examples.rb
+++ b/spec/support/shared_examples/controllers/variables_shared_examples.rb
@@ -27,6 +27,9 @@ RSpec.shared_examples 'PATCH #update updates variables' do
protected: 'false' }
end
+ let(:variables_scope) { owner.variables }
+ let(:file_variables_scope) { owner.variables.file }
+
context 'with invalid new variable parameters' do
let(:variables_attributes) do
[
@@ -40,7 +43,7 @@ RSpec.shared_examples 'PATCH #update updates variables' do
end
it 'does not create the new variable' do
- expect { subject }.not_to change { owner.variables.count }
+ expect { subject }.not_to change { variables_scope.count }
end
it 'returns a bad request response' do
@@ -63,7 +66,7 @@ RSpec.shared_examples 'PATCH #update updates variables' do
end
it 'does not create the new variable' do
- expect { subject }.not_to change { owner.variables.count }
+ expect { subject }.not_to change { variables_scope.count }
end
it 'returns a bad request response' do
@@ -86,7 +89,7 @@ RSpec.shared_examples 'PATCH #update updates variables' do
end
it 'creates the new variable' do
- expect { subject }.to change { owner.variables.count }.by(1)
+ expect { subject }.to change { variables_scope.count }.by(1)
end
it 'returns a successful response' do
@@ -106,7 +109,7 @@ RSpec.shared_examples 'PATCH #update updates variables' do
let(:variables_attributes) { [variable_attributes.merge(_destroy: 'true')] }
it 'destroys the variable' do
- expect { subject }.to change { owner.variables.count }.by(-1)
+ expect { subject }.to change { variables_scope.count }.by(-1)
expect { variable.reload }.to raise_error ActiveRecord::RecordNotFound
end
@@ -123,6 +126,18 @@ RSpec.shared_examples 'PATCH #update updates variables' do
end
end
+ context 'with missing variable' do
+ let(:variables_attributes) do
+ [variable_attributes.merge(_destroy: 'true', id: 'some-id')]
+ end
+
+ it 'returns not found response' do
+ subject
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+ end
+
context 'for variables of type file' do
let(:variables_attributes) do
[
@@ -131,7 +146,7 @@ RSpec.shared_examples 'PATCH #update updates variables' do
end
it 'creates new variable of type file' do
- expect { subject }.to change { owner.variables.file.count }.by(1)
+ expect { subject }.to change { file_variables_scope.count }.by(1)
end
end
end