diff options
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/git_access_snippet_spec.rb | 85 | ||||
-rw-r--r-- | spec/lib/gitlab/gl_repository/repo_type_spec.rb | 38 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/all_models.yml | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/hash_util_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/dashboard/finder_spec.rb | 34 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/shell_spec.rb | 2 |
7 files changed, 168 insertions, 4 deletions
diff --git a/spec/lib/gitlab/git_access_snippet_spec.rb b/spec/lib/gitlab/git_access_snippet_spec.rb new file mode 100644 index 00000000000..ffb3d86408a --- /dev/null +++ b/spec/lib/gitlab/git_access_snippet_spec.rb @@ -0,0 +1,85 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::GitAccessSnippet do + include GitHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:personal_snippet) { create(:personal_snippet, :private, :repository) } + + let(:protocol) { 'ssh' } + let(:changes) { Gitlab::GitAccess::ANY } + let(:push_access_check) { access.check('git-receive-pack', changes) } + let(:pull_access_check) { access.check('git-upload-pack', changes) } + let(:snippet) { personal_snippet } + let(:actor) { personal_snippet.author } + + describe 'when feature flag :version_snippets is enabled' do + it 'allows push and pull access' do + aggregate_failures do + expect { pull_access_check }.not_to raise_error + expect { push_access_check }.not_to raise_error + end + end + end + + describe 'when feature flag :version_snippets is disabled' do + before do + stub_feature_flags(version_snippets: false) + end + + it 'does not allow push and pull access' do + aggregate_failures do + expect { push_access_check }.to raise_snippet_not_found + expect { pull_access_check }.to raise_snippet_not_found + end + end + end + + describe '#check_snippet_accessibility!' do + context 'when the snippet exists' do + it 'allows push and pull access' do + aggregate_failures do + expect { pull_access_check }.not_to raise_error + expect { push_access_check }.not_to raise_error + end + end + end + + context 'when the snippet is nil' do + let(:snippet) { nil } + + it 'blocks push and pull with "not found"' do + aggregate_failures do + expect { pull_access_check }.to raise_snippet_not_found + expect { push_access_check }.to raise_snippet_not_found + end + end + end + + context 'when the snippet does not have a repository' do + let(:snippet) { build_stubbed(:personal_snippet) } + + it 'blocks push and pull with "not found"' do + aggregate_failures do + expect { pull_access_check }.to raise_snippet_not_found + expect { push_access_check }.to raise_snippet_not_found + end + end + end + end + + private + + def access + described_class.new(actor, snippet, protocol, + authentication_abilities: [], + namespace_path: nil, project_path: nil, + redirected_path: nil, auth_result_type: nil) + end + + def raise_snippet_not_found + raise_error(Gitlab::GitAccess::NotFoundError, Gitlab::GitAccess::ERROR_MESSAGES[:snippet_not_found]) + end +end diff --git a/spec/lib/gitlab/gl_repository/repo_type_spec.rb b/spec/lib/gitlab/gl_repository/repo_type_spec.rb index 8bbcc644f6d..7cf0442fbe1 100644 --- a/spec/lib/gitlab/gl_repository/repo_type_spec.rb +++ b/spec/lib/gitlab/gl_repository/repo_type_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' describe Gitlab::GlRepository::RepoType do let_it_be(:project) { create(:project) } + let_it_be(:personal_snippet) { create(:personal_snippet, author: project.owner) } + let_it_be(:project_snippet) { create(:project_snippet, project: project, author: project.owner) } describe Gitlab::GlRepository::PROJECT do it_behaves_like 'a repo type' do @@ -16,6 +18,7 @@ describe Gitlab::GlRepository::RepoType do it 'knows its type' do expect(described_class).not_to be_wiki expect(described_class).to be_project + expect(described_class).not_to be_snippet end it 'checks if repository path is valid' do @@ -36,6 +39,7 @@ describe Gitlab::GlRepository::RepoType do it 'knows its type' do expect(described_class).to be_wiki expect(described_class).not_to be_project + expect(described_class).not_to be_snippet end it 'checks if repository path is valid' do @@ -43,4 +47,38 @@ describe Gitlab::GlRepository::RepoType do expect(described_class.valid?(project.wiki.repository.full_path)).to be_truthy end end + + describe Gitlab::GlRepository::SNIPPET do + context 'when PersonalSnippet' do + it_behaves_like 'a repo type' do + let(:expected_id) { personal_snippet.id.to_s } + let(:expected_identifier) { "snippet-#{expected_id}" } + let(:expected_suffix) { '' } + let(:expected_repository) { personal_snippet.repository } + let(:expected_container) { personal_snippet } + end + + it 'knows its type' do + expect(described_class).to be_snippet + expect(described_class).not_to be_wiki + expect(described_class).not_to be_project + end + end + + context 'when ProjectSnippet' do + it_behaves_like 'a repo type' do + let(:expected_id) { project_snippet.id.to_s } + let(:expected_identifier) { "snippet-#{expected_id}" } + let(:expected_suffix) { '' } + let(:expected_repository) { project_snippet.repository } + let(:expected_container) { project_snippet } + end + + it 'knows its type' do + expect(described_class).to be_snippet + expect(described_class).not_to be_wiki + expect(described_class).not_to be_project + end + end + end end diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 4c521ae7f07..e6a60f39bd4 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -91,6 +91,7 @@ snippets: - award_emoji - user_agent_detail - user_mentions +- snippet_repository releases: - author - project diff --git a/spec/lib/gitlab/import_export/hash_util_spec.rb b/spec/lib/gitlab/import_export/hash_util_spec.rb index ddd874ddecf..b97c6665d0e 100644 --- a/spec/lib/gitlab/import_export/hash_util_spec.rb +++ b/spec/lib/gitlab/import_export/hash_util_spec.rb @@ -9,7 +9,7 @@ describe Gitlab::ImportExport::HashUtil do describe '.deep_symbolize_array!' do it 'symbolizes keys' do expect { described_class.deep_symbolize_array!(stringified_array) }.to change { - stringified_array.first.keys.first + stringified_array.first.each_key.first }.from('test').to(:test) end end @@ -17,13 +17,13 @@ describe Gitlab::ImportExport::HashUtil do describe '.deep_symbolize_array_with_date!' do it 'symbolizes keys' do expect { described_class.deep_symbolize_array_with_date!(stringified_array_with_date) }.to change { - stringified_array_with_date.first.keys.first + stringified_array_with_date.first.each_key.first }.from('test_date').to(:test_date) end it 'transforms date strings into Time objects' do expect { described_class.deep_symbolize_array_with_date!(stringified_array_with_date) }.to change { - stringified_array_with_date.first.values.first.class + stringified_array_with_date.first.each_value.first.class }.from(String).to(ActiveSupport::TimeWithZone) end end diff --git a/spec/lib/gitlab/metrics/dashboard/finder_spec.rb b/spec/lib/gitlab/metrics/dashboard/finder_spec.rb index 697bedf7362..2d3b61e61ce 100644 --- a/spec/lib/gitlab/metrics/dashboard/finder_spec.rb +++ b/spec/lib/gitlab/metrics/dashboard/finder_spec.rb @@ -44,6 +44,12 @@ describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store_cachi it_behaves_like 'valid dashboard service response' end + context 'when the self monitoring dashboard is specified' do + let(:dashboard_path) { self_monitoring_dashboard_path } + + it_behaves_like 'valid dashboard service response' + end + context 'when no dashboard is specified' do let(:service_call) { described_class.find(project, user, environment: environment) } @@ -152,5 +158,33 @@ describe Gitlab::Metrics::Dashboard::Finder, :use_clean_rails_memory_store_cachi expect(all_dashboard_paths).to contain_exactly(system_dashboard, project_dashboard) end end + + context 'when the project is self monitoring' do + let(:self_monitoring_dashboard) do + { + path: self_monitoring_dashboard_path, + display_name: 'Default', + default: true, + system_dashboard: false + } + end + let(:dashboard_path) { '.gitlab/dashboards/test.yml' } + let(:project) { project_with_dashboard(dashboard_path) } + + before do + stub_application_setting(self_monitoring_project_id: project.id) + end + + it 'includes self monitoring and project dashboards' do + project_dashboard = { + path: dashboard_path, + display_name: 'test.yml', + default: false, + system_dashboard: false + } + + expect(all_dashboard_paths).to contain_exactly(self_monitoring_dashboard, project_dashboard) + end + end end end diff --git a/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb b/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb index e0c8133994b..c0d71bfe5d0 100644 --- a/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb +++ b/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb @@ -30,6 +30,12 @@ describe Gitlab::Metrics::Dashboard::ServiceSelector do end end + context 'when the path is for the self monitoring dashboard' do + let(:arguments) { { dashboard_path: self_monitoring_dashboard_path } } + + it { is_expected.to be Metrics::Dashboard::SelfMonitoringDashboardService } + end + context 'when the embedded flag is provided' do let(:arguments) { { embedded: true } } diff --git a/spec/lib/gitlab/shell_spec.rb b/spec/lib/gitlab/shell_spec.rb index eefc548a4d9..7b8d1b6cd9b 100644 --- a/spec/lib/gitlab/shell_spec.rb +++ b/spec/lib/gitlab/shell_spec.rb @@ -397,7 +397,7 @@ describe Gitlab::Shell do describe 'namespace actions' do subject { described_class.new } - let(:storage) { Gitlab.config.repositories.storages.keys.first } + let(:storage) { Gitlab.config.repositories.storages.each_key.first } describe '#add_namespace' do it 'creates a namespace' do |