Commit 342186c7 authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'philipcunningham-rename-read-permission-301137' into 'master'

Rename DAST on-demand read policy for consistency

See merge request gitlab-org/gitlab!69813
parents 8ff5f6af d7413f28
...@@ -5,7 +5,7 @@ module Projects ...@@ -5,7 +5,7 @@ module Projects
include SecurityAndCompliancePermissions include SecurityAndCompliancePermissions
include API::Helpers::GraphqlHelpers include API::Helpers::GraphqlHelpers
before_action :authorize_read_on_demand_scans!, only: :index before_action :authorize_read_on_demand_dast_scan!, only: :index
before_action :authorize_create_on_demand_dast_scan!, only: [:new, :edit] before_action :authorize_create_on_demand_dast_scan!, only: [:new, :edit]
before_action do before_action do
......
...@@ -6,7 +6,7 @@ module Projects ...@@ -6,7 +6,7 @@ module Projects
include SecurityAndCompliancePermissions include SecurityAndCompliancePermissions
before_action do before_action do
authorize_read_on_demand_scans! authorize_read_on_demand_dast_scan!
push_frontend_feature_flag(:dast_failed_site_validations, @project, default_enabled: :yaml) push_frontend_feature_flag(:dast_failed_site_validations, @project, default_enabled: :yaml)
end end
......
...@@ -5,7 +5,7 @@ module Projects ...@@ -5,7 +5,7 @@ module Projects
class DastScannerProfilesController < Projects::ApplicationController class DastScannerProfilesController < Projects::ApplicationController
include SecurityAndCompliancePermissions include SecurityAndCompliancePermissions
before_action :authorize_read_on_demand_scans! before_action :authorize_read_on_demand_dast_scan!
feature_category :dynamic_application_security_testing feature_category :dynamic_application_security_testing
......
...@@ -7,7 +7,7 @@ module Projects ...@@ -7,7 +7,7 @@ module Projects
include API::Helpers::GraphqlHelpers include API::Helpers::GraphqlHelpers
before_action do before_action do
authorize_read_on_demand_scans! authorize_read_on_demand_dast_scan!
end end
feature_category :dynamic_application_security_testing feature_category :dynamic_application_security_testing
......
...@@ -6,7 +6,7 @@ module Types ...@@ -6,7 +6,7 @@ module Types
graphql_name 'DastProfileBranch' graphql_name 'DastProfileBranch'
description 'Represents a DAST Profile Branch' description 'Represents a DAST Profile Branch'
authorize :read_on_demand_scans authorize :read_on_demand_dast_scan
field :name, GraphQL::Types::String, null: true, field :name, GraphQL::Types::String, null: true,
description: 'Name of the branch.', description: 'Name of the branch.',
......
...@@ -6,7 +6,7 @@ module Types ...@@ -6,7 +6,7 @@ module Types
graphql_name 'DastProfileSchedule' graphql_name 'DastProfileSchedule'
description 'Represents a DAST profile schedule.' description 'Represents a DAST profile schedule.'
authorize :read_on_demand_scans authorize :read_on_demand_dast_scan
field :id, ::Types::GlobalIDType[::Dast::ProfileSchedule], null: false, field :id, ::Types::GlobalIDType[::Dast::ProfileSchedule], null: false,
description: 'ID of the DAST profile schedule.' description: 'ID of the DAST profile schedule.'
......
...@@ -6,7 +6,7 @@ module Types ...@@ -6,7 +6,7 @@ module Types
graphql_name 'DastProfile' graphql_name 'DastProfile'
description 'Represents a DAST Profile' description 'Represents a DAST Profile'
authorize :read_on_demand_scans authorize :read_on_demand_dast_scan
field :id, ::Types::GlobalIDType[::Dast::Profile], null: false, field :id, ::Types::GlobalIDType[::Dast::Profile], null: false,
description: 'ID of the profile.' description: 'ID of the profile.'
......
...@@ -8,7 +8,7 @@ module Types ...@@ -8,7 +8,7 @@ module Types
present_using ::Dast::SiteProfilePresenter present_using ::Dast::SiteProfilePresenter
authorize :read_on_demand_scans authorize :read_on_demand_dast_scan
field :enabled, GraphQL::Types::Boolean, field :enabled, GraphQL::Types::Boolean,
null: true, null: true,
......
...@@ -5,7 +5,7 @@ module Types ...@@ -5,7 +5,7 @@ module Types
graphql_name 'DastScannerProfile' graphql_name 'DastScannerProfile'
description 'Represents a DAST scanner profile' description 'Represents a DAST scanner profile'
authorize :read_on_demand_scans authorize :read_on_demand_dast_scan
field :id, ::Types::GlobalIDType[::DastScannerProfile], null: false, field :id, ::Types::GlobalIDType[::DastScannerProfile], null: false,
description: 'ID of the DAST scanner profile.' description: 'ID of the DAST scanner profile.'
......
...@@ -9,7 +9,7 @@ module Types ...@@ -9,7 +9,7 @@ module Types
present_using ::Dast::SiteProfilePresenter present_using ::Dast::SiteProfilePresenter
authorize :read_on_demand_scans authorize :read_on_demand_dast_scan
expose_permissions Types::PermissionTypes::DastSiteProfile expose_permissions Types::PermissionTypes::DastSiteProfile
......
...@@ -5,7 +5,7 @@ module Types ...@@ -5,7 +5,7 @@ module Types
graphql_name 'DastSiteValidation' graphql_name 'DastSiteValidation'
description 'Represents a DAST Site Validation' description 'Represents a DAST Site Validation'
authorize :read_on_demand_scans authorize :read_on_demand_dast_scan
field :id, ::Types::GlobalIDType[::DastSiteValidation], null: false, field :id, ::Types::GlobalIDType[::DastSiteValidation], null: false,
description: 'Global ID of the site validation.' description: 'Global ID of the site validation.'
......
...@@ -62,7 +62,7 @@ class DastSiteProfile < ApplicationRecord ...@@ -62,7 +62,7 @@ class DastSiteProfile < ApplicationRecord
def secret_ci_variables(user) def secret_ci_variables(user)
collection = ::Gitlab::Ci::Variables::Collection.new collection = ::Gitlab::Ci::Variables::Collection.new
return collection unless Ability.allowed?(user, :read_on_demand_scans, self) return collection unless Ability.allowed?(user, :read_on_demand_dast_scan, self)
collection.concat(secret_variables) collection.concat(secret_variables)
end end
......
...@@ -209,7 +209,7 @@ module EE ...@@ -209,7 +209,7 @@ module EE
end end
rule { on_demand_scans_enabled & can?(:developer_access) }.policy do rule { on_demand_scans_enabled & can?(:developer_access) }.policy do
enable :read_on_demand_scans enable :read_on_demand_dast_scan
enable :create_on_demand_dast_scan enable :create_on_demand_dast_scan
end end
......
...@@ -41,7 +41,7 @@ module AppSec ...@@ -41,7 +41,7 @@ module AppSec
profile = yield(name).execute.first profile = yield(name).execute.first
unless can?(current_user, :read_on_demand_scans, profile) unless can?(current_user, :read_on_demand_dast_scan, profile)
errors.push("DAST profile not found: #{name}") errors.push("DAST profile not found: #{name}")
return return
end end
......
...@@ -87,7 +87,7 @@ module EE ...@@ -87,7 +87,7 @@ module EE
end end
def on_demand_scans_menu_item def on_demand_scans_menu_item
unless can?(context.current_user, :read_on_demand_scans, context.project) unless can?(context.current_user, :read_on_demand_dast_scan, context.project)
return ::Sidebars::NilMenuItem.new(item_id: :on_demand_scans) return ::Sidebars::NilMenuItem.new(item_id: :on_demand_scans)
end end
......
...@@ -6,7 +6,7 @@ RSpec.describe GitlabSchema.types['DastProfileBranch'] do ...@@ -6,7 +6,7 @@ RSpec.describe GitlabSchema.types['DastProfileBranch'] do
include GraphqlHelpers include GraphqlHelpers
specify { expect(described_class.graphql_name).to eq('DastProfileBranch') } specify { expect(described_class.graphql_name).to eq('DastProfileBranch') }
specify { expect(described_class).to require_graphql_authorizations(:read_on_demand_scans) } specify { expect(described_class).to require_graphql_authorizations(:read_on_demand_dast_scan) }
it { expect(described_class).to have_graphql_field(:name, calls_gitaly?: true) } it { expect(described_class).to have_graphql_field(:name, calls_gitaly?: true) }
it { expect(described_class).to have_graphql_field(:exists, calls_gitaly?: true) } it { expect(described_class).to have_graphql_field(:exists, calls_gitaly?: true) }
......
...@@ -11,7 +11,7 @@ RSpec.describe GitlabSchema.types['DastProfile'] do ...@@ -11,7 +11,7 @@ RSpec.describe GitlabSchema.types['DastProfile'] do
let_it_be(:fields) { %i[id name description dastSiteProfile dastScannerProfile dastProfileSchedule branch editPath] } let_it_be(:fields) { %i[id name description dastSiteProfile dastScannerProfile dastProfileSchedule branch editPath] }
specify { expect(described_class.graphql_name).to eq('DastProfile') } specify { expect(described_class.graphql_name).to eq('DastProfile') }
specify { expect(described_class).to require_graphql_authorizations(:read_on_demand_scans) } specify { expect(described_class).to require_graphql_authorizations(:read_on_demand_dast_scan) }
before do before do
stub_licensed_features(security_on_demand_scans: true) stub_licensed_features(security_on_demand_scans: true)
......
...@@ -15,7 +15,7 @@ RSpec.describe GitlabSchema.types['DastSiteProfileAuth'] do ...@@ -15,7 +15,7 @@ RSpec.describe GitlabSchema.types['DastSiteProfileAuth'] do
end end
specify { expect(described_class.graphql_name).to eq('DastSiteProfileAuth') } specify { expect(described_class.graphql_name).to eq('DastSiteProfileAuth') }
specify { expect(described_class).to require_graphql_authorizations(:read_on_demand_scans) } specify { expect(described_class).to require_graphql_authorizations(:read_on_demand_dast_scan) }
it { expect(described_class).to have_graphql_fields(fields) } it { expect(described_class).to have_graphql_fields(fields) }
......
...@@ -29,7 +29,7 @@ RSpec.describe GitlabSchema.types['DastScannerProfile'] do ...@@ -29,7 +29,7 @@ RSpec.describe GitlabSchema.types['DastScannerProfile'] do
end end
specify { expect(described_class.graphql_name).to eq('DastScannerProfile') } specify { expect(described_class.graphql_name).to eq('DastScannerProfile') }
specify { expect(described_class).to require_graphql_authorizations(:read_on_demand_scans) } specify { expect(described_class).to require_graphql_authorizations(:read_on_demand_dast_scan) }
it { expect(described_class).to have_graphql_fields(fields) } it { expect(described_class).to have_graphql_fields(fields) }
......
...@@ -16,7 +16,7 @@ RSpec.describe GitlabSchema.types['DastSiteProfile'] do ...@@ -16,7 +16,7 @@ RSpec.describe GitlabSchema.types['DastSiteProfile'] do
end end
specify { expect(described_class.graphql_name).to eq('DastSiteProfile') } specify { expect(described_class.graphql_name).to eq('DastSiteProfile') }
specify { expect(described_class).to require_graphql_authorizations(:read_on_demand_scans) } specify { expect(described_class).to require_graphql_authorizations(:read_on_demand_dast_scan) }
specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::DastSiteProfile) } specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::DastSiteProfile) }
it { expect(described_class).to have_graphql_fields(fields) } it { expect(described_class).to have_graphql_fields(fields) }
......
...@@ -26,7 +26,7 @@ RSpec.describe GitlabSchema.types['DastSiteValidation'] do ...@@ -26,7 +26,7 @@ RSpec.describe GitlabSchema.types['DastSiteValidation'] do
end end
specify { expect(described_class.graphql_name).to eq('DastSiteValidation') } specify { expect(described_class.graphql_name).to eq('DastSiteValidation') }
specify { expect(described_class).to require_graphql_authorizations(:read_on_demand_scans) } specify { expect(described_class).to require_graphql_authorizations(:read_on_demand_dast_scan) }
it { expect(described_class).to have_graphql_fields(fields) } it { expect(described_class).to have_graphql_fields(fields) }
......
...@@ -278,11 +278,11 @@ RSpec.describe DastSiteProfile, type: :model do ...@@ -278,11 +278,11 @@ RSpec.describe DastSiteProfile, type: :model do
end end
it 'works with policy' do it 'works with policy' do
expect(Ability.allowed?(user, :read_on_demand_scans, subject)).to be_truthy expect(Ability.allowed?(user, :read_on_demand_dast_scan, subject)).to be_truthy
end end
it 'checks the policy' do it 'checks the policy' do
expect(Ability).to receive(:allowed?).with(user, :read_on_demand_scans, subject).and_call_original expect(Ability).to receive(:allowed?).with(user, :read_on_demand_dast_scan, subject).and_call_original
subject.secret_ci_variables(user) subject.secret_ci_variables(user)
end end
......
...@@ -12,7 +12,7 @@ RSpec.shared_examples 'a dast on-demand scan policy' do ...@@ -12,7 +12,7 @@ RSpec.shared_examples 'a dast on-demand scan policy' do
end end
describe 'dast on-demand policies' do describe 'dast on-demand policies' do
let(:policies) { [:create_on_demand_dast_scan, :read_on_demand_scans] } let(:policies) { [:create_on_demand_dast_scan, :read_on_demand_dast_scan] }
context 'when a user does not have access to the project' do context 'when a user does not have access to the project' do
it { is_expected.to be_disallowed(*policies) } it { is_expected.to be_disallowed(*policies) }
......
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