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>2021-08-19 12:08:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 12:08:42 +0300
commitb76ae638462ab0f673e5915986070518dd3f9ad3 (patch)
treebdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/lib/gitlab/auth
parent434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff)
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/lib/gitlab/auth')
-rw-r--r--spec/lib/gitlab/auth/auth_finders_spec.rb12
-rw-r--r--spec/lib/gitlab/auth/result_spec.rb79
2 files changed, 79 insertions, 12 deletions
diff --git a/spec/lib/gitlab/auth/auth_finders_spec.rb b/spec/lib/gitlab/auth/auth_finders_spec.rb
index 2d4239eb761..b0522e269e0 100644
--- a/spec/lib/gitlab/auth/auth_finders_spec.rb
+++ b/spec/lib/gitlab/auth/auth_finders_spec.rb
@@ -496,18 +496,6 @@ RSpec.describe Gitlab::Auth::AuthFinders do
expect(find_user_from_web_access_token(:archive)).to eq(user)
end
- context 'when allow_archive_as_web_access_format feature flag is disabled' do
- before do
- stub_feature_flags(allow_archive_as_web_access_format: false)
- end
-
- it 'returns nil for ARCHIVE requests' do
- set_header('SCRIPT_NAME', '/-/archive/main.zip')
-
- expect(find_user_from_web_access_token(:archive)).to be_nil
- end
- end
-
context 'for API requests' do
it 'returns the user' do
set_header('SCRIPT_NAME', '/api/endpoint')
diff --git a/spec/lib/gitlab/auth/result_spec.rb b/spec/lib/gitlab/auth/result_spec.rb
new file mode 100644
index 00000000000..f8de4b80db2
--- /dev/null
+++ b/spec/lib/gitlab/auth/result_spec.rb
@@ -0,0 +1,79 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Auth::Result do
+ let_it_be(:actor) { create(:user) }
+
+ subject { described_class.new(actor, nil, nil, []) }
+
+ context 'when actor is User' do
+ let_it_be(:actor) { create(:user) }
+
+ it 'returns auth_user' do
+ expect(subject.auth_user).to eq(actor)
+ end
+
+ it 'does not return deploy token' do
+ expect(subject.deploy_token).to be_nil
+ end
+ end
+
+ context 'when actor is Deploy token' do
+ let_it_be(:actor) { create(:deploy_token) }
+
+ it 'returns deploy token' do
+ expect(subject.deploy_token).to eq(actor)
+ end
+
+ it 'does not return auth_user' do
+ expect(subject.auth_user).to be_nil
+ end
+ end
+
+ describe '#authentication_abilities_include?' do
+ context 'when authentication abilities are empty' do
+ it 'returns false' do
+ expect(subject.authentication_abilities_include?(:read_code)).to be_falsey
+ end
+ end
+
+ context 'when authentication abilities are not empty' do
+ subject { described_class.new(actor, nil, nil, [:push_code]) }
+
+ it 'returns false when ability is not allowed' do
+ expect(subject.authentication_abilities_include?(:read_code)).to be_falsey
+ end
+
+ it 'returns true when ability is allowed' do
+ expect(subject.authentication_abilities_include?(:push_code)).to be_truthy
+ end
+ end
+ end
+
+ describe '#can_perform_action_on_project?' do
+ let(:project) { double }
+
+ it 'returns if actor can do perform given action on given project' do
+ expect(Ability).to receive(:allowed?).with(actor, :push_code, project).and_return(true)
+ expect(subject.can_perform_action_on_project?(:push_code, project)).to be_truthy
+ end
+
+ it 'returns if actor cannot do perform given action on given project' do
+ expect(Ability).to receive(:allowed?).with(actor, :push_code, project).and_return(false)
+ expect(subject.can_perform_action_on_project?(:push_code, project)).to be_falsey
+ end
+ end
+
+ describe '#can?' do
+ it 'returns if actor can do perform given action on given project' do
+ expect(actor).to receive(:can?).with(:push_code).and_return(true)
+ expect(subject.can?(:push_code)).to be_truthy
+ end
+
+ it 'returns if actor cannot do perform given action on given project' do
+ expect(actor).to receive(:can?).with(:push_code).and_return(false)
+ expect(subject.can?(:push_code)).to be_falsey
+ end
+ end
+end