diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/graphql/types | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/graphql/types')
22 files changed, 326 insertions, 37 deletions
diff --git a/spec/graphql/types/ci/pipeline_type_spec.rb b/spec/graphql/types/ci/pipeline_type_spec.rb index d435e337ad7..2a1e030480d 100644 --- a/spec/graphql/types/ci/pipeline_type_spec.rb +++ b/spec/graphql/types/ci/pipeline_type_spec.rb @@ -12,7 +12,7 @@ RSpec.describe Types::Ci::PipelineType do id iid sha before_sha status detailed_status config_source duration coverage created_at updated_at started_at finished_at committed_at stages user retryable cancelable jobs source_job downstream - upstream path project active user_permissions + upstream path project active user_permissions warnings ] if Gitlab.ee? diff --git a/spec/graphql/types/ci_configuration/sast/analyzers_entity_input_type_spec.rb b/spec/graphql/types/ci_configuration/sast/analyzers_entity_input_type_spec.rb new file mode 100644 index 00000000000..ac18f8d53a1 --- /dev/null +++ b/spec/graphql/types/ci_configuration/sast/analyzers_entity_input_type_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::Types::CiConfiguration::Sast::AnalyzersEntityInputType do + it { expect(described_class.graphql_name).to eq('SastCiConfigurationAnalyzersEntityInput') } + + it { expect(described_class.arguments.keys).to match_array(%w[enabled name variables]) } +end diff --git a/spec/graphql/types/ci_configuration/sast/analyzers_entity_type_spec.rb b/spec/graphql/types/ci_configuration/sast/analyzers_entity_type_spec.rb new file mode 100644 index 00000000000..27f6703b429 --- /dev/null +++ b/spec/graphql/types/ci_configuration/sast/analyzers_entity_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['SastCiConfigurationAnalyzersEntity'] do + let(:fields) { %i[name label enabled description variables] } + + it { expect(described_class.graphql_name).to eq('SastCiConfigurationAnalyzersEntity') } + + it { expect(described_class).to have_graphql_fields(fields) } +end diff --git a/spec/graphql/types/ci_configuration/sast/entity_input_type_spec.rb b/spec/graphql/types/ci_configuration/sast/entity_input_type_spec.rb new file mode 100644 index 00000000000..cefcf64164a --- /dev/null +++ b/spec/graphql/types/ci_configuration/sast/entity_input_type_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::Types::CiConfiguration::Sast::EntityInputType do + it { expect(described_class.graphql_name).to eq('SastCiConfigurationEntityInput') } + + it { expect(described_class.arguments.keys).to match_array(%w[field defaultValue value]) } +end diff --git a/spec/graphql/types/ci_configuration/sast/entity_type_spec.rb b/spec/graphql/types/ci_configuration/sast/entity_type_spec.rb new file mode 100644 index 00000000000..762798670a5 --- /dev/null +++ b/spec/graphql/types/ci_configuration/sast/entity_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['SastCiConfigurationEntity'] do + let(:fields) { %i[field label description type options default_value value size] } + + it { expect(described_class.graphql_name).to eq('SastCiConfigurationEntity') } + + it { expect(described_class).to have_graphql_fields(fields) } +end diff --git a/spec/graphql/types/ci_configuration/sast/input_type_spec.rb b/spec/graphql/types/ci_configuration/sast/input_type_spec.rb new file mode 100644 index 00000000000..9f9d1dea98f --- /dev/null +++ b/spec/graphql/types/ci_configuration/sast/input_type_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::Types::CiConfiguration::Sast::InputType do + it { expect(described_class.graphql_name).to eq('SastCiConfigurationInput') } + + it { expect(described_class.arguments.keys).to match_array(%w[global pipeline analyzers]) } +end diff --git a/spec/graphql/types/ci_configuration/sast/options_entity_spec.rb b/spec/graphql/types/ci_configuration/sast/options_entity_spec.rb new file mode 100644 index 00000000000..c60c8b9c84a --- /dev/null +++ b/spec/graphql/types/ci_configuration/sast/options_entity_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['SastCiConfigurationOptionsEntity'] do + let(:fields) { %i[label value] } + + it { expect(described_class.graphql_name).to eq('SastCiConfigurationOptionsEntity') } + + it { expect(described_class).to have_graphql_fields(fields) } +end diff --git a/spec/graphql/types/ci_configuration/sast/type_spec.rb b/spec/graphql/types/ci_configuration/sast/type_spec.rb new file mode 100644 index 00000000000..e7a8cd436e4 --- /dev/null +++ b/spec/graphql/types/ci_configuration/sast/type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['SastCiConfiguration'] do + let(:fields) { %i[global pipeline analyzers] } + + it { expect(described_class.graphql_name).to eq('SastCiConfiguration') } + + it { expect(described_class).to have_graphql_fields(fields) } +end diff --git a/spec/graphql/types/ci_configuration/sast/ui_component_size_enum_spec.rb b/spec/graphql/types/ci_configuration/sast/ui_component_size_enum_spec.rb new file mode 100644 index 00000000000..23184df809f --- /dev/null +++ b/spec/graphql/types/ci_configuration/sast/ui_component_size_enum_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::CiConfiguration::Sast::UiComponentSizeEnum do + specify { expect(described_class.graphql_name).to eq('SastUiComponentSize') } + + it 'exposes all sizes of ui components' do + expect(described_class.values.keys).to include(*%w[SMALL MEDIUM LARGE]) + end +end diff --git a/spec/graphql/types/container_repository_sort_enum_spec.rb b/spec/graphql/types/container_repository_sort_enum_spec.rb new file mode 100644 index 00000000000..eb936c6d3a1 --- /dev/null +++ b/spec/graphql/types/container_repository_sort_enum_spec.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['ContainerRepositorySort'] do + specify { expect(described_class.graphql_name).to eq('ContainerRepositorySort') } + + it_behaves_like 'common sort values' + + it 'exposes all the existing issue sort values' do + expect(described_class.values.keys).to include( + *%w[NAME_ASC NAME_DESC] + ) + end +end diff --git a/spec/graphql/types/event_type_spec.rb b/spec/graphql/types/event_type_spec.rb new file mode 100644 index 00000000000..10c3b5e18ca --- /dev/null +++ b/spec/graphql/types/event_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::EventType do + specify { expect(described_class.graphql_name).to eq('Event') } + + specify { expect(described_class).to require_graphql_authorizations(:read_event) } + + specify { expect(described_class).to have_graphql_fields(:id, :author, :action, :created_at, :updated_at) } +end diff --git a/spec/graphql/types/eventable_type_spec.rb b/spec/graphql/types/eventable_type_spec.rb new file mode 100644 index 00000000000..c1c7bf6d65a --- /dev/null +++ b/spec/graphql/types/eventable_type_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Types::EventableType do + it 'exposes events field' do + expect(described_class).to have_graphql_fields(:events) + end +end diff --git a/spec/graphql/types/group_type_spec.rb b/spec/graphql/types/group_type_spec.rb index de19e8b602a..bba702ba3e9 100644 --- a/spec/graphql/types/group_type_spec.rb +++ b/spec/graphql/types/group_type_spec.rb @@ -38,5 +38,7 @@ RSpec.describe GitlabSchema.types['Group'] do it { is_expected.to have_graphql_resolver(Resolvers::GroupMembersResolver) } end - it_behaves_like 'a GraphQL type with labels' + it_behaves_like 'a GraphQL type with labels' do + let(:labels_resolver_arguments) { [:search_term, :includeAncestorGroups, :includeDescendantGroups, :onlyGroupLabels] } + end end diff --git a/spec/graphql/types/merge_request_state_event_enum_spec.rb b/spec/graphql/types/merge_request_state_event_enum_spec.rb new file mode 100644 index 00000000000..94214b29755 --- /dev/null +++ b/spec/graphql/types/merge_request_state_event_enum_spec.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['MergeRequestNewState'] do + it 'has the appropriate values' do + expect(described_class.values).to contain_exactly( + ['OPEN', have_attributes(value: 'reopen')], + ['CLOSED', have_attributes(value: 'close')] + ) + end +end diff --git a/spec/graphql/types/packages/composer/details_type_spec.rb b/spec/graphql/types/packages/composer/details_type_spec.rb deleted file mode 100644 index 2e4cb965ded..00000000000 --- a/spec/graphql/types/packages/composer/details_type_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe GitlabSchema.types['PackageComposerDetails'] do - it { expect(described_class.graphql_name).to eq('PackageComposerDetails') } - - it 'includes all the package fields' do - expected_fields = %w[ - id name version created_at updated_at package_type tags project pipelines versions - ] - - expect(described_class).to include_graphql_fields(*expected_fields) - end - - it 'includes composer specific files' do - expected_fields = %w[ - composer_metadatum - ] - - expect(described_class).to include_graphql_fields(*expected_fields) - end -end diff --git a/spec/graphql/types/packages/composer/metadatum_type_spec.rb b/spec/graphql/types/packages/composer/metadatum_type_spec.rb index 0f47d8f1812..a950c10a41d 100644 --- a/spec/graphql/types/packages/composer/metadatum_type_spec.rb +++ b/spec/graphql/types/packages/composer/metadatum_type_spec.rb @@ -2,9 +2,7 @@ require 'spec_helper' -RSpec.describe GitlabSchema.types['PackageComposerMetadatumType'] do - it { expect(described_class.graphql_name).to eq('PackageComposerMetadatumType') } - +RSpec.describe GitlabSchema.types['ComposerMetadata'] do it 'includes composer metadatum fields' do expected_fields = %w[ target_sha composer_json diff --git a/spec/graphql/types/packages/package_type_enum_spec.rb b/spec/graphql/types/packages/package_type_enum_spec.rb index 407d5786f65..ccd91485e4b 100644 --- a/spec/graphql/types/packages/package_type_enum_spec.rb +++ b/spec/graphql/types/packages/package_type_enum_spec.rb @@ -4,6 +4,6 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['PackageTypeEnum'] do it 'exposes all package types' do - expect(described_class.values.keys).to contain_exactly(*%w[MAVEN NPM CONAN NUGET PYPI COMPOSER GENERIC GOLANG DEBIAN]) + expect(described_class.values.keys).to contain_exactly(*%w[MAVEN NPM CONAN NUGET PYPI COMPOSER GENERIC GOLANG DEBIAN RUBYGEMS]) end end diff --git a/spec/graphql/types/packages/package_type_spec.rb b/spec/graphql/types/packages/package_type_spec.rb index 7003a4d4d07..43289a019b3 100644 --- a/spec/graphql/types/packages/package_type_spec.rb +++ b/spec/graphql/types/packages/package_type_spec.rb @@ -3,11 +3,12 @@ require 'spec_helper' RSpec.describe GitlabSchema.types['Package'] do - it { expect(described_class.graphql_name).to eq('Package') } - it 'includes all the package fields' do expected_fields = %w[ - id name version created_at updated_at package_type tags project pipelines versions + id name version package_type + created_at updated_at + project + tags pipelines versions ] expect(described_class).to include_graphql_fields(*expected_fields) diff --git a/spec/graphql/types/packages/package_without_versions_type_spec.rb b/spec/graphql/types/packages/package_without_versions_type_spec.rb new file mode 100644 index 00000000000..faa79e588d5 --- /dev/null +++ b/spec/graphql/types/packages/package_without_versions_type_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['PackageWithoutVersions'] do + it 'includes all the package fields' do + expected_fields = %w[ + id name version created_at updated_at package_type tags project pipelines + ] + + expect(described_class).to include_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index 9d0d7a3918a..9579ef8b99b 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -31,12 +31,171 @@ RSpec.describe GitlabSchema.types['Project'] do container_expiration_policy service_desk_enabled service_desk_address issue_status_counts terraform_states alert_management_integrations container_repositories container_repositories_count - pipeline_analytics squash_read_only + pipeline_analytics squash_read_only sast_ci_configuration ] expect(described_class).to include_graphql_fields(*expected_fields) end + describe 'sast_ci_configuration' do + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } + + before do + stub_licensed_features(security_dashboard: true) + project.add_developer(user) + allow(project.repository).to receive(:blob_data_at).and_return(gitlab_ci_yml_content) + end + + include_context 'read ci configuration for sast enabled project' + + let(:query) do + %( + query { + project(fullPath: "#{project.full_path}") { + sastCiConfiguration { + global { + nodes { + type + options { + nodes { + label + value + } + } + field + label + defaultValue + value + size + } + } + pipeline { + nodes { + type + options { + nodes { + label + value + } + } + field + label + defaultValue + value + size + } + } + analyzers { + nodes { + name + label + enabled + } + } + } + } + } + ) + end + + subject { GitlabSchema.execute(query, context: { current_user: user }).as_json } + + it "returns the project's sast configuration for global variables" do + secure_analyzers_prefix = subject.dig('data', 'project', 'sastCiConfiguration', 'global', 'nodes').first + expect(secure_analyzers_prefix['type']).to eq('string') + expect(secure_analyzers_prefix['field']).to eq('SECURE_ANALYZERS_PREFIX') + expect(secure_analyzers_prefix['label']).to eq('Image prefix') + expect(secure_analyzers_prefix['defaultValue']).to eq('registry.gitlab.com/gitlab-org/security-products/analyzers') + expect(secure_analyzers_prefix['value']).to eq('registry.gitlab.com/gitlab-org/security-products/analyzers') + expect(secure_analyzers_prefix['size']).to eq('LARGE') + expect(secure_analyzers_prefix['options']).to be_nil + end + + it "returns the project's sast configuration for pipeline variables" do + pipeline_stage = subject.dig('data', 'project', 'sastCiConfiguration', 'pipeline', 'nodes').first + expect(pipeline_stage['type']).to eq('string') + expect(pipeline_stage['field']).to eq('stage') + expect(pipeline_stage['label']).to eq('Stage') + expect(pipeline_stage['defaultValue']).to eq('test') + expect(pipeline_stage['value']).to eq('test') + expect(pipeline_stage['size']).to eq('MEDIUM') + end + + it "returns the project's sast configuration for analyzer variables" do + analyzer = subject.dig('data', 'project', 'sastCiConfiguration', 'analyzers', 'nodes').first + expect(analyzer['name']).to eq('brakeman') + expect(analyzer['label']).to eq('Brakeman') + expect(analyzer['enabled']).to eq(true) + end + + context "with guest user" do + before do + project.add_guest(user) + end + + context 'when project is private' do + let(:project) { create(:project, :private, :repository) } + + it "returns no configuration" do + secure_analyzers_prefix = subject.dig('data', 'project', 'sastCiConfiguration') + expect(secure_analyzers_prefix).to be_nil + end + end + + context 'when project is public' do + let(:project) { create(:project, :public, :repository) } + + context 'when repository is accessible by everyone' do + it "returns the project's sast configuration for global variables" do + secure_analyzers_prefix = subject.dig('data', 'project', 'sastCiConfiguration', 'global', 'nodes').first + + expect(secure_analyzers_prefix['type']).to eq('string') + expect(secure_analyzers_prefix['field']).to eq('SECURE_ANALYZERS_PREFIX') + end + end + end + end + + context "with non-member user" do + before do + project.team.truncate + end + + context 'when project is private' do + let(:project) { create(:project, :private, :repository) } + + it "returns no configuration" do + secure_analyzers_prefix = subject.dig('data', 'project', 'sastCiConfiguration') + expect(secure_analyzers_prefix).to be_nil + end + end + + context 'when project is public' do + let(:project) { create(:project, :public, :repository) } + + context 'when repository is accessible by everyone' do + it "returns the project's sast configuration for global variables" do + secure_analyzers_prefix = subject.dig('data', 'project', 'sastCiConfiguration', 'global', 'nodes').first + expect(secure_analyzers_prefix['type']).to eq('string') + expect(secure_analyzers_prefix['field']).to eq('SECURE_ANALYZERS_PREFIX') + end + end + + context 'when repository is accessible only by team members' do + it "returns no configuration" do + project.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED, + builds_access_level: ProjectFeature::DISABLED, + repository_access_level: ProjectFeature::PRIVATE) + + secure_analyzers_prefix = subject.dig('data', 'project', 'sastCiConfiguration') + expect(secure_analyzers_prefix).to be_nil + end + end + end + end + end + describe 'issue field' do subject { described_class.fields['issue'] } @@ -159,6 +318,13 @@ RSpec.describe GitlabSchema.types['Project'] do it { is_expected.to have_graphql_type(Types::ContainerExpirationPolicyType) } end + describe 'terraform state field' do + subject { described_class.fields['terraformState'] } + + it { is_expected.to have_graphql_type(Types::Terraform::StateType) } + it { is_expected.to have_graphql_resolver(Resolvers::Terraform::StatesResolver.single) } + end + describe 'terraform states field' do subject { described_class.fields['terraformStates'] } @@ -166,7 +332,9 @@ RSpec.describe GitlabSchema.types['Project'] do it { is_expected.to have_graphql_resolver(Resolvers::Terraform::StatesResolver) } end - it_behaves_like 'a GraphQL type with labels' + it_behaves_like 'a GraphQL type with labels' do + let(:labels_resolver_arguments) { [:search_term, :includeAncestorGroups] } + end describe 'jira_imports' do subject { resolve_field(:jira_imports, project) } diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb index 3e716865e56..fea0a3bd37e 100644 --- a/spec/graphql/types/query_type_spec.rb +++ b/spec/graphql/types/query_type_spec.rb @@ -95,9 +95,9 @@ RSpec.describe GitlabSchema.types['Query'] do it { is_expected.to have_graphql_type(Types::ContainerRepositoryDetailsType) } end - describe 'package_composer_details field' do - subject { described_class.fields['packageComposerDetails'] } + describe 'package field' do + subject { described_class.fields['package'] } - it { is_expected.to have_graphql_type(Types::Packages::Composer::DetailsType) } + it { is_expected.to have_graphql_type(Types::Packages::PackageType) } end end diff --git a/spec/graphql/types/user_type_spec.rb b/spec/graphql/types/user_type_spec.rb index 0eff33bb25b..5b3662383d8 100644 --- a/spec/graphql/types/user_type_spec.rb +++ b/spec/graphql/types/user_type_spec.rb @@ -10,6 +10,7 @@ RSpec.describe GitlabSchema.types['User'] do it 'has the expected fields' do expected_fields = %w[ id + bot user_permissions snippets name |