Commit 2877fb0f authored by James Fargher's avatar James Fargher

Merge branch '222536-improve-tests' into 'master'

Add import/export tests for security_setting

Closes #222536

See merge request gitlab-org/gitlab!34772
parents 73e7f976 c822bbbf
......@@ -3,5 +3,9 @@
FactoryBot.define do
factory :project_security_setting do
project
auto_fix_container_scanning { true }
auto_fix_dast { true }
auto_fix_dependency_scanning { true }
auto_fix_sast { true }
end
end
{
"description": "Nisi et repellendus ut enim quo accusamus vel magnam.",
"import_type": "gitlab_project",
"creator_id": 123,
"visibility_level": 10,
"archived": false,
"project_members": [
{
"id": 36,
"access_level": 40,
"source_id": 5,
"source_type": "Project",
"user_id": 16,
"notification_level": 3,
"created_at": "2016-06-14T15:02:03.834Z",
"updated_at": "2016-06-14T15:02:03.834Z",
"created_by_id": null,
"invite_email": null,
"invite_token": null,
"invite_accepted_at": null,
"requested_at": null,
"user": {
"id": 16,
"email": "bernard_willms@gitlabexample.com",
"username": "bernard_willms"
}
}
],
"security_setting": {
"auto_fix_container_scanning": true,
"auto_fix_dast": true,
"auto_fix_dependency_scanning": false,
"auto_fix_sast": false
}
}
{"security_setting": {"auto_fix_container_scanning": true,"auto_fix_dast": true,"auto_fix_dependency_scanning": false,"auto_fix_sast": false}}
{"auto_fix_container_scanning": true,"auto_fix_dast": true,"auto_fix_dependency_scanning": false,"auto_fix_sast": false}
......@@ -4,11 +4,11 @@ require 'spec_helper'
RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
include ImportExport::CommonUtil
subject(:restored_project_json) { project_tree_restorer.restore }
let(:shared) { project.import_export_shared }
let(:project_tree_restorer) { described_class.new(user: user, shared: shared, project: project) }
subject(:restored_project_json) { project_tree_restorer.restore }
describe 'epics' do
let_it_be(:user) { create(:user)}
......@@ -17,8 +17,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
end
context 'with group' do
let(:issue) { project.issues.find_by_title('Issue with Epic') }
let!(:project) do
let_it_be(:project) do
create(:project,
:builds_disabled,
:issues_disabled,
......@@ -27,8 +26,10 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
group: create(:group, :private))
end
let(:issue) { project.issues.find_by_title('Issue with Epic') }
context 'with pre-existing epic' do
let!(:epic) { create(:epic, title: 'An epic', group: project.group) }
let_it_be(:epic) { create(:epic, title: 'An epic', group: project.group) }
it 'associates epics' do
project = Project.find_by_path('project')
......@@ -54,7 +55,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
end
context 'with personal namespace' do
let!(:project) do
let_it_be(:project) do
create(:project,
:builds_disabled,
:issues_disabled,
......@@ -94,4 +95,21 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
end
end
end
describe 'security_settings' do
let_it_be(:project) { create(:project, name: 'project', path: 'project') }
let(:user) { create(:user)}
before do
setup_import_export_config('complex', 'ee')
end
it 'creates security setting' do
project = Project.find_by_path('project')
expect { restored_project_json }.to change { ProjectSecuritySetting.count }.from(0).to(1)
expect(project.security_setting.auto_fix_dependency_scanning).to be_falsey
expect(project.security_setting.auto_fix_container_scanning).to be_truthy
end
end
end
......@@ -15,6 +15,8 @@ RSpec.describe Gitlab::ImportExport::Project::TreeSaver do
let_it_be(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec_ee" }
let_it_be(:security_setting) { create(:project_security_setting, project: project, auto_fix_dast: false) }
after :all do
FileUtils.rm_rf(export_path)
end
......@@ -64,6 +66,18 @@ RSpec.describe Gitlab::ImportExport::Project::TreeSaver do
expect(issue_json['epic_issue']['issue_id']).to be_nil
end
end
context 'security setting' do
let(:security_json) do
json = get_json(full_path, exportable_path, :security_setting, ndjson_enabled)
ndjson_enabled ? json.first : json
end
it 'has security settings' do
expect(security_json['auto_fix_dast']).to be_falsey
expect(security_json['auto_fix_dependency_scanning']).to be_truthy
end
end
end
context 'with JSON' do
......
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