Commit 3ebc63ca authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab master

parents 53785258 ef7b242c
...@@ -26,6 +26,7 @@ update-tests-metadata: ...@@ -26,6 +26,7 @@ update-tests-metadata:
- .test-metadata:rules:update-tests-metadata - .test-metadata:rules:update-tests-metadata
stage: post-test stage: post-test
dependencies: dependencies:
- retrieve-tests-metadata
- setup-test-env - setup-test-env
- rspec migration pg12 - rspec migration pg12
- rspec frontend_fixture - rspec frontend_fixture
......
...@@ -4,14 +4,10 @@ class AddStateToMembers < ActiveRecord::Migration[6.1] ...@@ -4,14 +4,10 @@ class AddStateToMembers < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers include Gitlab::Database::MigrationHelpers
def up def up
with_lock_retries do # no-op
add_column :members, :state, :integer, limit: 2, default: 0
end
end end
def down def down
with_lock_retries do # no-op
remove_column :members, :state
end
end end
end end
...@@ -14766,8 +14766,7 @@ CREATE TABLE members ( ...@@ -14766,8 +14766,7 @@ CREATE TABLE members (
expires_at date, expires_at date,
ldap boolean DEFAULT false NOT NULL, ldap boolean DEFAULT false NOT NULL,
override boolean DEFAULT false NOT NULL, override boolean DEFAULT false NOT NULL,
invite_email_success boolean DEFAULT true NOT NULL, invite_email_success boolean DEFAULT true NOT NULL
state smallint DEFAULT 0
); );
CREATE SEQUENCE members_id_seq CREATE SEQUENCE members_id_seq
...@@ -47,11 +47,13 @@ module EE ...@@ -47,11 +47,13 @@ module EE
# rubocop:enable Gitlab/ModuleWithInstanceVariables # rubocop:enable Gitlab/ModuleWithInstanceVariables
def auto_fix def auto_fix
service = ::Security::Configuration::SaveAutoFixService.new(project, auto_fix_params[:feature]) service = ::Security::Configuration::SaveAutoFixService
.new(project, auto_fix_params[:feature])
.execute(enabled: auto_fix_params[:enabled])
return respond_422 unless service.execute(enabled: auto_fix_params[:enabled]) return respond_422 unless service.success?
render status: :ok, json: auto_fix_settings render status: :ok, json: service.payload
end end
private private
...@@ -77,15 +79,6 @@ module EE ...@@ -77,15 +79,6 @@ module EE
render_404 if ::Feature.disabled?(:security_auto_fix, project) render_404 if ::Feature.disabled?(:security_auto_fix, project)
end end
def auto_fix_settings
setting = project.security_setting
{
dependency_scanning: setting.auto_fix_dependency_scanning,
container_scanning: setting.auto_fix_container_scanning
}
end
def security_dashboard_feature_enabled? def security_dashboard_feature_enabled?
vulnerable.feature_available?(:security_dashboard) vulnerable.feature_available?(:security_dashboard)
end end
......
...@@ -111,10 +111,6 @@ class SubscriptionsController < ApplicationController ...@@ -111,10 +111,6 @@ class SubscriptionsController < ApplicationController
Gitlab::SubscriptionPortal::Client Gitlab::SubscriptionPortal::Client
end end
def customer_portal_new_subscription_url
"#{EE::SUBSCRIPTIONS_URL}/subscriptions/new?plan_id=#{params[:plan_id]}&transaction=create_subscription"
end
def redirect_unauthenticated_user(from = action_name) def redirect_unauthenticated_user(from = action_name)
return if current_user return if current_user
......
...@@ -13,15 +13,32 @@ module Security ...@@ -13,15 +13,32 @@ module Security
end end
def execute(enabled:) def execute(enabled:)
return unless valid? return error("Auto fix is not available for #{feature} feature") unless valid?
return error("Project has no security setting") unless setting
project&.security_setting&.update(toggle_params(enabled)) if setting&.update(toggle_params(enabled))
success(updated_setting)
else
error('Error during updating the auto fix param')
end
end end
private private
attr_reader :enabled, :feature, :project attr_reader :enabled, :feature, :project
def error(message)
ServiceResponse.error(message: message)
end
def setting
@setting ||= project&.security_setting
end
def success(payload)
ServiceResponse.success(payload: payload)
end
def toggle_params(enabled) def toggle_params(enabled)
if feature == 'all' if feature == 'all'
{ {
...@@ -37,6 +54,13 @@ module Security ...@@ -37,6 +54,13 @@ module Security
end end
end end
def updated_setting
{
container_scanning: setting.auto_fix_container_scanning,
dependency_scanning: setting.auto_fix_dependency_scanning
}
end
def valid? def valid?
SUPPORTED_SCANNERS.include?(feature) SUPPORTED_SCANNERS.include?(feature)
end end
......
...@@ -15,5 +15,5 @@ ...@@ -15,5 +15,5 @@
'mr_settings_path': presenter.api_approval_settings_path, 'mr_settings_path': presenter.api_approval_settings_path,
'eligible_approvers_docs_path': help_page_path('user/project/merge_requests/approvals/rules', anchor: 'eligible-approvers'), 'eligible_approvers_docs_path': help_page_path('user/project/merge_requests/approvals/rules', anchor: 'eligible-approvers'),
'project_settings_path': presenter.api_project_approval_settings_path } } 'project_settings_path': presenter.api_project_approval_settings_path } }
= sprite_icon('spinner', size: 24, css_class: 'gl-spinner') = sprite_icon('spinner', size: 24, css_class: 'gl-spinner gl-mt-5')
= render 'projects/merge_requests/code_owner_approval_rules', merge_request: @mr_presenter = render 'projects/merge_requests/code_owner_approval_rules', merge_request: @mr_presenter
...@@ -140,20 +140,13 @@ RSpec.describe Projects::Security::ConfigurationController do ...@@ -140,20 +140,13 @@ RSpec.describe Projects::Security::ConfigurationController do
context 'with sufficient permissions' do context 'with sufficient permissions' do
let(:user) { maintainer } let(:user) { maintainer }
it 'shows auto fix disable for dependency scanning for json format' do
get :show, params: { namespace_id: project.namespace, project_id: project, format: :json }
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['auto_fix_enabled']).to include({ 'dependency_scanning' => false })
end
context 'with setup feature param' do context 'with setup feature param' do
let(:feature) { :dependency_scanning } let(:feature) { :dependency_scanning }
it 'processes request and updates setting' do it 'processes request and updates setting' do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(project.security_setting.reload.auto_fix_dependency_scanning).to be_falsey expect(project.security_setting.reload.auto_fix_dependency_scanning).to be_falsey
expect(response[:dependency_scanning]).to be_falsey expect(json_response['dependency_scanning']).to be(false)
end end
end end
...@@ -166,7 +159,8 @@ RSpec.describe Projects::Security::ConfigurationController do ...@@ -166,7 +159,8 @@ RSpec.describe Projects::Security::ConfigurationController do
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(setting.auto_fix_dependency_scanning).to be_falsey expect(setting.auto_fix_dependency_scanning).to be_falsey
expect(setting.auto_fix_dast).to be_falsey expect(setting.auto_fix_dast).to be_falsey
expect(response[:container_scanning]).to be_falsey expect(json_response['dependency_scanning']).to be(false)
expect(json_response['container_scanning']).to be(false)
end end
end end
......
...@@ -6,16 +6,21 @@ RSpec.describe Security::Configuration::SaveAutoFixService do ...@@ -6,16 +6,21 @@ RSpec.describe Security::Configuration::SaveAutoFixService do
describe '#execute' do describe '#execute' do
let_it_be_with_reload(:project) { create(:project) } let_it_be_with_reload(:project) { create(:project) }
subject(:service) { described_class.new(project, feature) } let(:service) { described_class.new(project, feature) }
before do subject(:response) { service.execute(enabled: false) }
service.execute(enabled: false)
end
context 'with supported scanner type' do context 'with supported scanner type' do
let(:feature) { 'dependency_scanning' } let(:feature) { 'dependency_scanning' }
it 'returns success status' do
expect(response).to be_success
expect(response.payload).to eq({ container_scanning: true, dependency_scanning: false })
end
it 'changes setting' do it 'changes setting' do
response
expect(project.security_setting.auto_fix_dependency_scanning).to be_falsey expect(project.security_setting.auto_fix_dependency_scanning).to be_falsey
end end
end end
...@@ -23,7 +28,13 @@ RSpec.describe Security::Configuration::SaveAutoFixService do ...@@ -23,7 +28,13 @@ RSpec.describe Security::Configuration::SaveAutoFixService do
context 'with all scanners' do context 'with all scanners' do
let(:feature) { 'all' } let(:feature) { 'all' }
it 'returns success status' do
expect(response).to be_success
end
it 'changes setting' do it 'changes setting' do
response
expect(project.security_setting.auto_fix_dependency_scanning).to be_falsey expect(project.security_setting.auto_fix_dependency_scanning).to be_falsey
expect(project.security_setting.auto_fix_container_scanning).to be_falsey expect(project.security_setting.auto_fix_container_scanning).to be_falsey
end end
...@@ -33,7 +44,8 @@ RSpec.describe Security::Configuration::SaveAutoFixService do ...@@ -33,7 +44,8 @@ RSpec.describe Security::Configuration::SaveAutoFixService do
let(:feature) { :dep_scan } let(:feature) { :dep_scan }
it 'does not change setting' do it 'does not change setting' do
expect(project.security_setting.auto_fix_dependency_scanning).to be_truthy expect(response).to be_error
expect(response.message).to eq('Auto fix is not available for dep_scan feature')
end end
end end
end end
......
...@@ -328,9 +328,6 @@ excluded_attributes: ...@@ -328,9 +328,6 @@ excluded_attributes:
- :release_id - :release_id
project_members: project_members:
- :source_id - :source_id
- :state
group_members:
- :state
metrics: metrics:
- :merge_request_id - :merge_request_id
- :pipeline_id - :pipeline_id
......
#!/usr/bin/env bash #!/usr/bin/env bash
function retrieve_tests_metadata() { function retrieve_tests_metadata() {
mkdir -p knapsack/ rspec_flaky/ rspec_profiling/ mkdir -p $(dirname "$KNAPSACK_RSPEC_SUITE_REPORT_PATH") $(dirname "$FLAKY_RSPEC_SUITE_REPORT_PATH") rspec_profiling/
# ${CI_DEFAULT_BRANCH} might not be master in other forks but we want to if [[ -z "${RETRIEVE_TESTS_METADATA_FROM_ARTIFACTS}" ]]; then
# always target the canonical project here, so the branch must be hardcoded if [[ ! -f "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" ]]; then
local project_path="gitlab-org/gitlab" curl --location -o "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" "https://gitlab-org.gitlab.io/gitlab/${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" || echo "{}" > "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}"
local artifact_branch="master" fi
local test_metadata_job_id
# Ruby if [[ ! -f "${FLAKY_RSPEC_SUITE_REPORT_PATH}" ]]; then
test_metadata_job_id=$(scripts/api/get_job_id.rb --project "${project_path}" -q "status=success" -q "ref=${artifact_branch}" -q "username=gitlab-bot" -Q "scope=success" --job-name "update-tests-metadata") curl --location -o "${FLAKY_RSPEC_SUITE_REPORT_PATH}" "https://gitlab-org.gitlab.io/gitlab/${FLAKY_RSPEC_SUITE_REPORT_PATH}" || echo "{}" > "${FLAKY_RSPEC_SUITE_REPORT_PATH}"
fi
else
# ${CI_DEFAULT_BRANCH} might not be master in other forks but we want to
# always target the canonical project here, so the branch must be hardcoded
local project_path="gitlab-org/gitlab"
local artifact_branch="master"
local test_metadata_job_id
if [[ ! -f "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" ]]; then # Ruby
scripts/api/download_job_artifact.rb --project "${project_path}" --job-id "${test_metadata_job_id}" --artifact-path "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" || echo "{}" > "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" test_metadata_job_id=$(scripts/api/get_job_id.rb --project "${project_path}" -q "status=success" -q "ref=${artifact_branch}" -q "username=gitlab-bot" -Q "scope=success" --job-name "update-tests-metadata")
fi
if [[ ! -f "${FLAKY_RSPEC_SUITE_REPORT_PATH}" ]]; then if [[ ! -f "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" ]]; then
scripts/api/download_job_artifact.rb --project "${project_path}" --job-id "${test_metadata_job_id}" --artifact-path "${FLAKY_RSPEC_SUITE_REPORT_PATH}" || echo "{}" > "${FLAKY_RSPEC_SUITE_REPORT_PATH}" scripts/api/download_job_artifact.rb --project "${project_path}" --job-id "${test_metadata_job_id}" --artifact-path "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}" || echo "{}" > "${KNAPSACK_RSPEC_SUITE_REPORT_PATH}"
fi
if [[ ! -f "${FLAKY_RSPEC_SUITE_REPORT_PATH}" ]]; then
scripts/api/download_job_artifact.rb --project "${project_path}" --job-id "${test_metadata_job_id}" --artifact-path "${FLAKY_RSPEC_SUITE_REPORT_PATH}" || echo "{}" > "${FLAKY_RSPEC_SUITE_REPORT_PATH}"
fi
fi fi
} }
...@@ -40,18 +50,24 @@ function update_tests_metadata() { ...@@ -40,18 +50,24 @@ function update_tests_metadata() {
} }
function retrieve_tests_mapping() { function retrieve_tests_mapping() {
mkdir -p crystalball/ mkdir -p $(dirname "$RSPEC_PACKED_TESTS_MAPPING_PATH")
# ${CI_DEFAULT_BRANCH} might not be master in other forks but we want to if [[ -z "${RETRIEVE_TESTS_METADATA_FROM_ARTIFACTS}" ]]; then
# always target the canonical project here, so the branch must be hardcoded if [[ ! -f "${RSPEC_PACKED_TESTS_MAPPING_PATH}" ]]; then
local project_path="gitlab-org/gitlab" (curl --location -o "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz" "https://gitlab-org.gitlab.io/gitlab/${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz" && gzip -d "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz") || echo "{}" > "${RSPEC_PACKED_TESTS_MAPPING_PATH}"
local artifact_branch="master" fi
local test_metadata_with_mapping_job_id else
# ${CI_DEFAULT_BRANCH} might not be master in other forks but we want to
# always target the canonical project here, so the branch must be hardcoded
local project_path="gitlab-org/gitlab"
local artifact_branch="master"
local test_metadata_with_mapping_job_id
test_metadata_with_mapping_job_id=$(scripts/api/get_job_id.rb --project "${project_path}" -q "status=success" -q "ref=${artifact_branch}" -q "username=gitlab-bot" -Q "scope=success" --job-name "update-tests-metadata" --artifact-path "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz") test_metadata_with_mapping_job_id=$(scripts/api/get_job_id.rb --project "${project_path}" -q "status=success" -q "ref=${artifact_branch}" -q "username=gitlab-bot" -Q "scope=success" --job-name "update-tests-metadata" --artifact-path "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz")
if [[ ! -f "${RSPEC_PACKED_TESTS_MAPPING_PATH}" ]]; then if [[ ! -f "${RSPEC_PACKED_TESTS_MAPPING_PATH}" ]]; then
(scripts/api/download_job_artifact.rb --project "${project_path}" --job-id "${test_metadata_with_mapping_job_id}" --artifact-path "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz" && gzip -d "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz") || echo "{}" > "${RSPEC_PACKED_TESTS_MAPPING_PATH}" (scripts/api/download_job_artifact.rb --project "${project_path}" --job-id "${test_metadata_with_mapping_job_id}" --artifact-path "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz" && gzip -d "${RSPEC_PACKED_TESTS_MAPPING_PATH}.gz") || echo "{}" > "${RSPEC_PACKED_TESTS_MAPPING_PATH}"
fi
fi fi
scripts/unpack-test-mapping "${RSPEC_PACKED_TESTS_MAPPING_PATH}" "${RSPEC_TESTS_MAPPING_PATH}" scripts/unpack-test-mapping "${RSPEC_PACKED_TESTS_MAPPING_PATH}" "${RSPEC_TESTS_MAPPING_PATH}"
......
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