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:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-05-08 16:07:55 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2018-05-10 18:02:27 +0300
commitf7f13f9db0da92c7b43481dfe5559f317711e533 (patch)
tree59359aecb555f844de1a81a0aebbd70336fbb8c1 /spec/lib/gitlab/git_access_spec.rb
parentf667bbceaba7556d5fb2adadce4b7d170b914e8a (diff)
Block access to API & git when terms are enforced
When terms are enforced, but the user has not accepted the terms access to the API & git is rejected with a message directing the user to the web app to accept the terms.
Diffstat (limited to 'spec/lib/gitlab/git_access_spec.rb')
-rw-r--r--spec/lib/gitlab/git_access_spec.rb78
1 files changed, 77 insertions, 1 deletions
diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb
index 6c625596605..f421a7135f3 100644
--- a/spec/lib/gitlab/git_access_spec.rb
+++ b/spec/lib/gitlab/git_access_spec.rb
@@ -1,7 +1,9 @@
require 'spec_helper'
describe Gitlab::GitAccess do
- set(:user) { create(:user) }
+ include TermsHelper
+
+ let(:user) { create(:user) }
let(:actor) { user }
let(:project) { create(:project, :repository) }
@@ -1040,6 +1042,80 @@ describe Gitlab::GitAccess do
end
end
+ context 'terms are enforced' do
+ before do
+ enforce_terms
+ end
+
+ shared_examples 'access after accepting terms' do
+ let(:actions) do
+ [-> { pull_access_check },
+ -> { push_access_check }]
+ end
+
+ it 'blocks access when the user did not accept terms', :aggregate_failures do
+ actions.each do |action|
+ expect { action.call }.to raise_unauthorized(/You must accept the Terms of Service in order to perform this action/)
+ end
+ end
+
+ it 'allows access when the user accepted the terms', :aggregate_failures do
+ accept_terms(user)
+
+ actions.each do |action|
+ expect { action.call }.not_to raise_error
+ end
+ end
+ end
+
+ describe 'as an anonymous user to a public project' do
+ let(:actor) { nil }
+ let(:project) { create(:project, :public, :repository) }
+
+ it { expect { pull_access_check }.not_to raise_error }
+ end
+
+ describe 'as a guest to a public project' do
+ let(:project) { create(:project, :public, :repository) }
+
+ it_behaves_like 'access after accepting terms' do
+ let(:actions) { [-> { pull_access_check }] }
+ end
+ end
+
+ describe 'as a reporter to the project' do
+ before do
+ project.add_reporter(user)
+ end
+
+ it_behaves_like 'access after accepting terms' do
+ let(:actions) { [-> { pull_access_check }] }
+ end
+ end
+
+ describe 'as a developer of the project' do
+ before do
+ project.add_developer(user)
+ end
+
+ it_behaves_like 'access after accepting terms'
+ end
+
+ describe 'as a master of the project' do
+ before do
+ project.add_master(user)
+ end
+
+ it_behaves_like 'access after accepting terms'
+ end
+
+ describe 'as an owner of the project' do
+ let(:project) { create(:project, :repository, namespace: user.namespace) }
+
+ it_behaves_like 'access after accepting terms'
+ end
+ end
+
private
def raise_unauthorized(message)