Commit c822bbbf authored by Tetiana Chupryna's avatar Tetiana Chupryna

Add security_setting import/export test

Add additional fixtures for ee
Add test for security_setting model
parent df51e59c
...@@ -3,5 +3,9 @@ ...@@ -3,5 +3,9 @@
FactoryBot.define do FactoryBot.define do
factory :project_security_setting do factory :project_security_setting do
project project
auto_fix_container_scanning { true }
auto_fix_dast { true }
auto_fix_dependency_scanning { true }
auto_fix_sast { true }
end end
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' ...@@ -4,11 +4,11 @@ require 'spec_helper'
RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
include ImportExport::CommonUtil include ImportExport::CommonUtil
subject(:restored_project_json) { project_tree_restorer.restore }
let(:shared) { project.import_export_shared } let(:shared) { project.import_export_shared }
let(:project_tree_restorer) { described_class.new(user: user, shared: shared, project: project) } let(:project_tree_restorer) { described_class.new(user: user, shared: shared, project: project) }
subject(:restored_project_json) { project_tree_restorer.restore }
describe 'epics' do describe 'epics' do
let_it_be(:user) { create(:user)} let_it_be(:user) { create(:user)}
...@@ -17,8 +17,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do ...@@ -17,8 +17,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
end end
context 'with group' do context 'with group' do
let(:issue) { project.issues.find_by_title('Issue with Epic') } let_it_be(:project) do
let!(:project) do
create(:project, create(:project,
:builds_disabled, :builds_disabled,
:issues_disabled, :issues_disabled,
...@@ -27,8 +26,10 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do ...@@ -27,8 +26,10 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
group: create(:group, :private)) group: create(:group, :private))
end end
let(:issue) { project.issues.find_by_title('Issue with Epic') }
context 'with pre-existing epic' do 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 it 'associates epics' do
project = Project.find_by_path('project') project = Project.find_by_path('project')
...@@ -54,7 +55,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do ...@@ -54,7 +55,7 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
end end
context 'with personal namespace' do context 'with personal namespace' do
let!(:project) do let_it_be(:project) do
create(:project, create(:project,
:builds_disabled, :builds_disabled,
:issues_disabled, :issues_disabled,
...@@ -94,4 +95,21 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do ...@@ -94,4 +95,21 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do
end end
end 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 end
...@@ -15,6 +15,8 @@ RSpec.describe Gitlab::ImportExport::Project::TreeSaver do ...@@ -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(: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 after :all do
FileUtils.rm_rf(export_path) FileUtils.rm_rf(export_path)
end end
...@@ -64,6 +66,18 @@ RSpec.describe Gitlab::ImportExport::Project::TreeSaver do ...@@ -64,6 +66,18 @@ RSpec.describe Gitlab::ImportExport::Project::TreeSaver do
expect(issue_json['epic_issue']['issue_id']).to be_nil expect(issue_json['epic_issue']['issue_id']).to be_nil
end end
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 end
context 'with JSON' do 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