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
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 03:09:33 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 03:09:33 +0300
commitb56027c9d80ac0e297ba8a43c81e8504172dbf9f (patch)
treeb85f743277145e930ae195664655d696e6e0a7fc /spec
parent7915c41e4261719719e791602c8235574157164c (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/import/gitea_controller_spec.rb2
-rw-r--r--spec/controllers/projects/import/jira_controller_spec.rb29
-rw-r--r--spec/lib/gitlab/git_access_snippet_spec.rb79
-rw-r--r--spec/models/snippet_spec.rb17
-rw-r--r--spec/support/helpers/test_env.rb10
5 files changed, 122 insertions, 15 deletions
diff --git a/spec/controllers/import/gitea_controller_spec.rb b/spec/controllers/import/gitea_controller_spec.rb
index b4834dffdb3..006b423ce5f 100644
--- a/spec/controllers/import/gitea_controller_spec.rb
+++ b/spec/controllers/import/gitea_controller_spec.rb
@@ -42,7 +42,7 @@ describe Import::GiteaController do
get :status, format: :json
expect(controller).to redirect_to(new_import_url)
- expect(flash[:alert]).to eq('Specified URL cannot be used.')
+ expect(flash[:alert]).to eq('Specified URL cannot be used: "Only allowed schemes are http, https"')
end
end
end
diff --git a/spec/controllers/projects/import/jira_controller_spec.rb b/spec/controllers/projects/import/jira_controller_spec.rb
index 33b51320391..f692f976bc0 100644
--- a/spec/controllers/projects/import/jira_controller_spec.rb
+++ b/spec/controllers/projects/import/jira_controller_spec.rb
@@ -93,18 +93,29 @@ describe Projects::Import::JiraController do
end
context 'post import' do
- it 'creates import state' do
- expect(project.import_state).to be_nil
+ context 'when jira project key is empty' do
+ it 'redirects back to show with an error' do
+ post :import, params: { namespace_id: project.namespace, project_id: project, jira_project_key: '' }
- post :import, params: { namespace_id: project.namespace, project_id: project, jira_project_key: 'Test' }
+ expect(response).to redirect_to(project_import_jira_path(project))
+ expect(flash[:alert]).to eq('No jira project key has been provided.')
+ end
+ end
- project.reload
+ context 'when everything is ok' do
+ it 'creates import state' do
+ expect(project.import_state).to be_nil
- jira_project = project.import_data.data.dig('jira', 'projects').first
- expect(project.import_type).to eq 'jira'
- expect(project.import_state.status).to eq 'scheduled'
- expect(jira_project['key']).to eq 'Test'
- expect(response).to redirect_to(project_import_jira_path(project))
+ post :import, params: { namespace_id: project.namespace, project_id: project, jira_project_key: 'Test' }
+
+ project.reload
+
+ jira_project = project.import_data.data.dig('jira', 'projects').first
+ expect(project.import_type).to eq 'jira'
+ expect(project.import_state.status).to eq 'scheduled'
+ expect(jira_project['key']).to eq 'Test'
+ expect(response).to redirect_to(project_import_jira_path(project))
+ end
end
end
end
diff --git a/spec/lib/gitlab/git_access_snippet_spec.rb b/spec/lib/gitlab/git_access_snippet_spec.rb
index f52fe8ef612..bbc3808df12 100644
--- a/spec/lib/gitlab/git_access_snippet_spec.rb
+++ b/spec/lib/gitlab/git_access_snippet_spec.rb
@@ -11,6 +11,7 @@ describe Gitlab::GitAccessSnippet do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public) }
let_it_be(:snippet) { create(:project_snippet, :public, :repository, project: project) }
+ let(:repository) { snippet.repository }
let(:actor) { user }
let(:protocol) { 'ssh' }
@@ -211,6 +212,84 @@ describe Gitlab::GitAccessSnippet do
end
end
+ describe 'repository size restrictions' do
+ let(:snippet) { create(:personal_snippet, :public, :repository) }
+ let(:actor) { snippet.author }
+
+ let(:oldrev) { TestEnv::BRANCH_SHA["snippet/single-file"] }
+ let(:newrev) { TestEnv::BRANCH_SHA["snippet/edit-file"] }
+ let(:ref) { "refs/heads/snippet/edit-file" }
+ let(:changes) { "#{oldrev} #{newrev} #{ref}" }
+
+ shared_examples_for 'a push to repository already over the limit' do
+ it 'errs' do
+ expect(snippet.repository_size_checker).to receive(:above_size_limit?).and_return(true)
+
+ expect do
+ push_access_check
+ end.to raise_error(described_class::ForbiddenError, /Your push has been rejected/)
+ end
+ end
+
+ shared_examples_for 'a push to repository below the limit' do
+ it 'does not err' do
+ expect(snippet.repository_size_checker).to receive(:above_size_limit?).and_return(false)
+ expect(snippet.repository_size_checker)
+ .to receive(:changes_will_exceed_size_limit?)
+ .with(change_size)
+ .and_return(false)
+
+ expect { push_access_check }.not_to raise_error
+ end
+ end
+
+ shared_examples_for 'a push to repository to make it over the limit' do
+ it 'errs' do
+ expect(snippet.repository_size_checker).to receive(:above_size_limit?).and_return(false)
+ expect(snippet.repository_size_checker)
+ .to receive(:changes_will_exceed_size_limit?)
+ .with(change_size)
+ .and_return(true)
+
+ expect do
+ push_access_check
+ end.to raise_error(described_class::ForbiddenError, /Your push to this repository would cause it to exceed the size limit/)
+ end
+ end
+
+ context 'when GIT_OBJECT_DIRECTORY_RELATIVE env var is set' do
+ let(:change_size) { 100 }
+
+ before do
+ allow(Gitlab::Git::HookEnv)
+ .to receive(:all)
+ .with(repository.gl_repository)
+ .and_return({ 'GIT_OBJECT_DIRECTORY_RELATIVE' => 'objects' })
+
+ # Stub the object directory size to "simulate" quarantine size
+ allow(repository).to receive(:object_directory_size).and_return(change_size)
+ end
+
+ it_behaves_like 'a push to repository already over the limit'
+ it_behaves_like 'a push to repository below the limit'
+ it_behaves_like 'a push to repository to make it over the limit'
+ end
+
+ context 'when GIT_OBJECT_DIRECTORY_RELATIVE env var is not set' do
+ let(:change_size) { 200 }
+
+ before do
+ allow(snippet.repository).to receive(:new_blobs).and_return(
+ [double(:blob, size: change_size)]
+ )
+ end
+
+ it_behaves_like 'a push to repository already over the limit'
+ it_behaves_like 'a push to repository below the limit'
+ it_behaves_like 'a push to repository to make it over the limit'
+ end
+ end
+
private
def raise_snippet_not_found
diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb
index 8ce3718e3c1..9cced1f24ab 100644
--- a/spec/models/snippet_spec.rb
+++ b/spec/models/snippet_spec.rb
@@ -696,6 +696,23 @@ describe Snippet do
end
end
+ describe '#repository_size_checker' do
+ subject { build(:personal_snippet) }
+
+ let(:checker) { subject.repository_size_checker }
+ let(:current_size) { 60 }
+
+ before do
+ allow(subject.repository).to receive(:_uncached_size).and_return(current_size)
+ end
+
+ it 'sets up size checker', :aggregate_failures do
+ expect(checker.current_size).to eq(current_size.megabytes)
+ expect(checker.limit).to eq(Gitlab::CurrentSettings.snippet_size_limit)
+ expect(checker.enabled?).to be_truthy
+ end
+ end
+
describe '#can_cache_field?' do
using RSpec::Parameterized::TableSyntax
diff --git a/spec/support/helpers/test_env.rb b/spec/support/helpers/test_env.rb
index 2e69c59c80a..fd41c5c8fe3 100644
--- a/spec/support/helpers/test_env.rb
+++ b/spec/support/helpers/test_env.rb
@@ -60,11 +60,11 @@ module TestEnv
'merge-commit-analyze-before' => '1adbdef',
'merge-commit-analyze-side-branch' => '8a99451',
'merge-commit-analyze-after' => '646ece5',
- 'snippet/single-file' => '43e4080',
- 'snippet/multiple-files' => 'b80faa8',
- 'snippet/rename-and-edit-file' => '220a1e4',
- 'snippet/edit-file' => 'c2f074f',
- 'snippet/no-files' => '671aaa8',
+ 'snippet/single-file' => '43e4080aaa14fc7d4b77ee1f5c9d067d5a7df10e',
+ 'snippet/multiple-files' => 'b80faa8c5b2b62f6489a0d84755580e927e1189b',
+ 'snippet/rename-and-edit-file' => '220a1e4b4dff37feea0625a7947a4c60fbe78365',
+ 'snippet/edit-file' => 'c2f074f4f26929c92795a75775af79a6ed6d8430',
+ 'snippet/no-files' => '671aaa842a4875e5f30082d1ab6feda345fdb94d',
'2-mb-file' => 'bf12d25',
'before-create-delete-modify-move' => '845009f',
'between-create-delete-modify-move' => '3f5f443',