Commit 54ae19fb authored by Sean McGivern's avatar Sean McGivern

Merge branch 'dast-site-profile-graphql-query' into 'master'

Add ability to fetch DastSiteProfile via GraphQL

See merge request gitlab-org/gitlab!38380
parents 76f0ff98 59ad8552
......@@ -11352,6 +11352,16 @@ type Project {
last: Int
): DastScannerProfileConnection
"""
DAST Site Profile associated with the project
"""
dastSiteProfile(
"""
ID of the site profile
"""
id: DastSiteProfileID!
): DastSiteProfile
"""
DAST Site Profiles associated with the project
"""
......
......@@ -33932,6 +33932,33 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "dastSiteProfile",
"description": "DAST Site Profile associated with the project",
"args": [
{
"name": "id",
"description": "ID of the site profile",
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "DastSiteProfileID",
"ofType": null
}
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "DastSiteProfile",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "dastSiteProfiles",
"description": "DAST Site Profiles associated with the project",
......@@ -1737,6 +1737,7 @@ Autogenerated return type of PipelineRetry
| `containerExpirationPolicy` | ContainerExpirationPolicy | The container expiration policy of the project |
| `containerRegistryEnabled` | Boolean | Indicates if the project stores Docker container images in a container registry |
| `createdAt` | Time | Timestamp of the project creation |
| `dastSiteProfile` | DastSiteProfile | DAST Site Profile associated with the project |
| `description` | String | Short description of the project |
| `descriptionHtml` | String | The GitLab Flavored Markdown rendering of `description` |
| `environment` | Environment | A single environment of the project |
......
......@@ -77,6 +77,16 @@ module EE
description: 'Find iterations',
resolver: ::Resolvers::IterationsResolver
field :dast_site_profile,
::Types::DastSiteProfileType,
null: true,
resolve: -> (obj, args, _ctx) do
DastSiteProfilesFinder.new(project_id: obj.id, id: args[:id].model_id).execute.first
end,
description: 'DAST Site Profile associated with the project' do
argument :id, ::Types::GlobalIDType[::DastSiteProfile], required: true, description: 'ID of the site profile'
end
field :dast_site_profiles,
::Types::DastSiteProfileType.connection_type,
null: true,
......
---
title: Add ability to fetch DastSiteProfile via GraphQL
merge_request: 38380
author:
type: added
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Query.project(fullPath).dastSiteProfile' do
include GraphqlHelpers
let_it_be(:dast_site_profile) { create(:dast_site_profile) }
let_it_be(:project) { dast_site_profile.project }
let_it_be(:current_user) { create(:user) }
let(:query) do
%(
query project($fullPath: ID!, $id: DastSiteProfileID!) {
project(fullPath: $fullPath) {
dastSiteProfile(id: $id) {
id
profileName
targetUrl
validationStatus
}
}
}
)
end
let(:project_response) { subject.dig('project') }
let(:dast_site_profile_response) { project_response.dig('dastSiteProfile') }
subject do
post_graphql(
query,
current_user: current_user,
variables: {
fullPath: project.full_path,
id: dast_site_profile.to_global_id.to_s
}
)
graphql_data
end
before do
stub_licensed_features(security_on_demand_scans: true)
end
context 'when a user does not have access to the project' do
it 'returns a null project' do
expect(project_response).to be_nil
end
end
context 'when a user does not have access to dast_site_profiles' do
it 'returns a null dast_site_profile' do
project.add_guest(current_user)
expect(dast_site_profile_response).to be_nil
end
end
context 'when a user has access to dast_site_profiles' do
before do
project.add_developer(current_user)
end
it 'returns a dast_site_profile' do
expect(dast_site_profile_response['id']).to eq(dast_site_profile.to_global_id.to_s)
end
context 'when the wrong type of global id is supplied' do
it 'returns a null dast_site_profile' do
post_graphql(
query,
current_user: current_user,
variables: {
fullPath: project.full_path,
id: project.to_global_id.to_s
}
)
expected_message = 'Variable $id of type DastSiteProfileID! was provided invalid value'
expect(graphql_errors[0]).to include('message' => expected_message)
end
end
context 'when on demand scan feature flag is disabled' do
it 'returns a null dast_site_profile' do
stub_feature_flags(security_on_demand_scans_feature_flag: false)
expect(dast_site_profile_response).to be_nil
end
end
context 'when on demand scan licensed feature is not available' do
it 'returns a null dast_site_profile' do
stub_licensed_features(security_on_demand_scans: false)
expect(dast_site_profile_response).to be_nil
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment