summaryrefslogtreecommitdiff
path: root/spec/tooling/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-06-20 11:10:13 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-06-20 11:10:13 +0000
commit0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch)
tree7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/tooling/lib
parent72123183a20411a36d607d70b12d57c484394c8e (diff)
downloadgitlab-ce-0ea3fcec397b69815975647f5e2aa5fe944a8486.tar.gz
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/tooling/lib')
-rw-r--r--spec/tooling/lib/tooling/find_codeowners_spec.rb107
-rw-r--r--spec/tooling/lib/tooling/test_map_generator_spec.rb14
2 files changed, 64 insertions, 57 deletions
diff --git a/spec/tooling/lib/tooling/find_codeowners_spec.rb b/spec/tooling/lib/tooling/find_codeowners_spec.rb
index b29c5f35ec9..10c2a076847 100644
--- a/spec/tooling/lib/tooling/find_codeowners_spec.rb
+++ b/spec/tooling/lib/tooling/find_codeowners_spec.rb
@@ -31,13 +31,37 @@ RSpec.describe Tooling::FindCodeowners do
end
end.to output(<<~CODEOWNERS).to_stdout
[Section name]
- /dir0/dir1 @group
+ /dir0/dir1/ @group
/file @group
CODEOWNERS
end
end
describe '#load_definitions' do
+ before do
+ allow(subject).to receive(:load_config).and_return(
+ {
+ '[Authentication and Authorization]': {
+ '@gitlab-org/manage/authentication-and-authorization': {
+ allow: {
+ keywords: %w[password auth token],
+ patterns:
+ %w[
+ /{,ee/}app/**/*%{keyword}*{,/**/*}
+ /{,ee/}config/**/*%{keyword}*{,/**/*}
+ /{,ee/}lib/**/*%{keyword}*{,/**/*}
+ ]
+ },
+ deny: {
+ keywords: %w[*author.* *author_* *authored*],
+ patterns: ['%{keyword}']
+ }
+ }
+ }
+ }
+ )
+ end
+
it 'expands the allow and deny list with keywords and patterns' do
subject.load_definitions.each do |section, group_defintions|
group_defintions.each do |group, definitions|
@@ -54,56 +78,20 @@ RSpec.describe Tooling::FindCodeowners do
expect(auth).to eq(
allow: %w[
- /{,ee/}app/**/*password*{/**/*,}
- /{,ee/}config/**/*password*{/**/*,}
- /{,ee/}lib/**/*password*{/**/*,}
- /{,ee/}app/**/*auth*{/**/*,}
- /{,ee/}config/**/*auth*{/**/*,}
- /{,ee/}lib/**/*auth*{/**/*,}
- /{,ee/}app/**/*token*{/**/*,}
- /{,ee/}config/**/*token*{/**/*,}
- /{,ee/}lib/**/*token*{/**/*,}
+ /{,ee/}app/**/*password*{,/**/*}
+ /{,ee/}config/**/*password*{,/**/*}
+ /{,ee/}lib/**/*password*{,/**/*}
+ /{,ee/}app/**/*auth*{,/**/*}
+ /{,ee/}config/**/*auth*{,/**/*}
+ /{,ee/}lib/**/*auth*{,/**/*}
+ /{,ee/}app/**/*token*{,/**/*}
+ /{,ee/}config/**/*token*{,/**/*}
+ /{,ee/}lib/**/*token*{,/**/*}
],
deny: %w[
- **/*author.*{/**/*,}
- **/*author_*{/**/*,}
- **/*authored*{/**/*,}
- **/*authoring*{/**/*,}
- **/*.png*{/**/*,}
- **/*.svg*{/**/*,}
- **/*deploy_token*{/**/*,}
- **/*runner{,s}_token*{/**/*,}
- **/*job_token*{/**/*,}
- **/*autocomplete_tokens*{/**/*,}
- **/*dast_site_token*{/**/*,}
- **/*reset_prometheus_token*{/**/*,}
- **/*reset_registration_token*{/**/*,}
- **/*runners_registration_token*{/**/*,}
- **/*terraform_registry_token*{/**/*,}
- **/*tokenizer*{/**/*,}
- **/*filtered_search*{/**/*,}
- **/*/alert_management/*{/**/*,}
- **/*/analytics/*{/**/*,}
- **/*/bitbucket/*{/**/*,}
- **/*/clusters/*{/**/*,}
- **/*/clusters_list/*{/**/*,}
- **/*/dast/*{/**/*,}
- **/*/dast_profiles/*{/**/*,}
- **/*/dast_site_tokens/*{/**/*,}
- **/*/dast_site_validation/*{/**/*,}
- **/*/dependency_proxy/*{/**/*,}
- **/*/error_tracking/*{/**/*,}
- **/*/google_api/*{/**/*,}
- **/*/google_cloud/*{/**/*,}
- **/*/jira_connect/*{/**/*,}
- **/*/kubernetes/*{/**/*,}
- **/*/protected_environments/*{/**/*,}
- **/*/config/feature_flags/development/jira_connect_*{/**/*,}
- **/*/config/metrics/*{/**/*,}
- **/*/app/controllers/groups/dependency_proxy_auth_controller.rb*{/**/*,}
- **/*/app/finders/ci/auth_job_finder.rb*{/**/*,}
- **/*/ee/config/metrics/*{/**/*,}
- **/*/lib/gitlab/conan_token.rb*{/**/*,}
+ *author.*
+ *author_*
+ *authored*
]
)
end
@@ -159,12 +147,31 @@ RSpec.describe Tooling::FindCodeowners do
expected_flags =
::File::FNM_DOTMATCH | ::File::FNM_PATHNAME | ::File::FNM_EXTGLOB
- expect(File).to receive(:fnmatch?).with(pattern, path, expected_flags)
+ expect(File).to receive(:fnmatch?)
+ .with("/**/#{pattern}", path, expected_flags)
subject.path_matches?(pattern, path)
end
end
+ describe '#normalize_pattern' do
+ it 'returns /**/* if the input is *' do
+ expect(subject.normalize_pattern('*')).to eq('/**/*')
+ end
+
+ it 'prepends /** if the input does not start with /' do
+ expect(subject.normalize_pattern('app')).to eq('/**/app')
+ end
+
+ it 'returns the pattern if the input starts with /' do
+ expect(subject.normalize_pattern('/app')).to eq('/app')
+ end
+
+ it 'appends **/* if the input ends with /' do
+ expect(subject.normalize_pattern('/app/')).to eq('/app/**/*')
+ end
+ end
+
describe '#consolidate_paths' do
before do
allow(subject).to receive(:find_dir_maxdepth_1).and_return(<<~LINES)
diff --git a/spec/tooling/lib/tooling/test_map_generator_spec.rb b/spec/tooling/lib/tooling/test_map_generator_spec.rb
index b52d78b01a3..1b369923d8d 100644
--- a/spec/tooling/lib/tooling/test_map_generator_spec.rb
+++ b/spec/tooling/lib/tooling/test_map_generator_spec.rb
@@ -17,7 +17,7 @@ RSpec.describe Tooling::TestMapGenerator do
:timestamp: 1602668405
:version:
---
- "./spec/factories_spec.rb[1]":
+ "./spec/models/factories_spec.rb[1]":
- lib/gitlab/current_settings.rb
- lib/feature.rb
- lib/gitlab/marginalia.rb
@@ -62,13 +62,13 @@ RSpec.describe Tooling::TestMapGenerator do
let(:expected_mapping) do
{
'lib/gitlab/current_settings.rb' => [
- 'spec/factories_spec.rb'
+ 'spec/models/factories_spec.rb'
],
'lib/feature.rb' => [
- 'spec/factories_spec.rb'
+ 'spec/models/factories_spec.rb'
],
'lib/gitlab/marginalia.rb' => [
- 'spec/factories_spec.rb'
+ 'spec/models/factories_spec.rb'
]
}
end
@@ -96,15 +96,15 @@ RSpec.describe Tooling::TestMapGenerator do
let(:expected_mapping) do
{
'lib/gitlab/current_settings.rb' => [
- 'spec/factories_spec.rb',
+ 'spec/models/factories_spec.rb',
'spec/models/project_spec.rb'
],
'lib/feature.rb' => [
- 'spec/factories_spec.rb',
+ 'spec/models/factories_spec.rb',
'spec/models/project_spec.rb'
],
'lib/gitlab/marginalia.rb' => [
- 'spec/factories_spec.rb',
+ 'spec/models/factories_spec.rb',
'spec/models/project_spec.rb'
]
}