diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-01 00:10:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-01 00:10:43 +0300 |
commit | d9115c777949c14b7e12332f85fe99b100af2aeb (patch) | |
tree | 34f094a0bdb519787adafa54d58075188a30b7b5 /spec/lib | |
parent | 34d6e7c91beed4420759ce5a8e1e9607db8f9c45 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
8 files changed, 129 insertions, 41 deletions
diff --git a/spec/lib/backup/manager_spec.rb b/spec/lib/backup/manager_spec.rb index 2cc1bf41d18..32eea82cfdf 100644 --- a/spec/lib/backup/manager_spec.rb +++ b/spec/lib/backup/manager_spec.rb @@ -432,6 +432,77 @@ RSpec.describe Backup::Manager do end end + context 'with AWS with server side encryption' do + let(:connection) { ::Fog::Storage.new(Gitlab.config.backup.upload.connection.symbolize_keys) } + let(:encryption_key) { nil } + let(:encryption) { nil } + let(:storage_options) { nil } + + before do + stub_backup_setting( + upload: { + connection: { + provider: 'AWS', + aws_access_key_id: 'AWS_ACCESS_KEY_ID', + aws_secret_access_key: 'AWS_SECRET_ACCESS_KEY' + }, + remote_directory: 'directory', + multipart_chunk_size: Gitlab.config.backup.upload.multipart_chunk_size, + encryption: encryption, + encryption_key: encryption_key, + storage_options: storage_options, + storage_class: nil + } + ) + + connection.directories.create(key: Gitlab.config.backup.upload.remote_directory) + end + + context 'with SSE-S3 without using storage_options' do + let(:encryption) { 'AES256' } + + it 'sets encryption attributes' do + result = subject.upload + + expect(result.key).to be_present + expect(result.encryption).to eq('AES256') + expect(result.encryption_key).to be_nil + expect(result.kms_key_id).to be_nil + end + end + + context 'with SSE-C (customer-provided keys) options' do + let(:encryption) { 'AES256' } + let(:encryption_key) { SecureRandom.hex } + + it 'sets encryption attributes' do + result = subject.upload + + expect(result.key).to be_present + expect(result.encryption).to eq(encryption) + expect(result.encryption_key).to eq(encryption_key) + expect(result.kms_key_id).to be_nil + end + end + + context 'with SSE-KMS options' do + let(:storage_options) do + { + server_side_encryption: 'aws:kms', + server_side_encryption_kms_key_id: 'arn:aws:kms:12345' + } + end + + it 'sets encryption attributes' do + result = subject.upload + + expect(result.key).to be_present + expect(result.encryption).to eq('aws:kms') + expect(result.kms_key_id).to eq('arn:aws:kms:12345') + end + end + end + context 'with Google provider' do before do stub_backup_setting( diff --git a/spec/lib/banzai/filter/references/design_reference_filter_spec.rb b/spec/lib/banzai/filter/references/design_reference_filter_spec.rb index cb1f3d520a4..d616aabea45 100644 --- a/spec/lib/banzai/filter/references/design_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/references/design_reference_filter_spec.rb @@ -90,11 +90,8 @@ RSpec.describe Banzai::Filter::References::DesignReferenceFilter do [ ['simple.png'], ['SIMPLE.PNG'], - ['has spaces.png'], ['has-hyphen.jpg'], - ['snake_case.svg'], - ['has "quotes".svg'], - ['has <special> characters [o].svg'] + ['snake_case.svg'] ] end @@ -138,40 +135,25 @@ RSpec.describe Banzai::Filter::References::DesignReferenceFilter do end end - context 'a design with a quoted filename' do - let(:filename) { %q{A "very" good file.png} } - let(:design) { create(:design, :with_versions, issue: issue, filename: filename) } - - it 'links to the design' do - expect(doc.css('a').first.attr('href')) - .to eq url_for_design(design) - end - end - context 'internal reference' do it_behaves_like 'a reference containing an element node' - context 'the reference is valid' do - it_behaves_like 'a good link reference' + it_behaves_like 'a good link reference' - context 'the filename needs to be escaped' do - where(:filename) do - [ - ['with some spaces.png'], - ['with <script>console.log("pwded")<%2Fscript>.png'] - ] - end + context 'the filename contains invalid characters' do + where(:filename) do + [ + ['with some spaces.png'], + ['with <script>console.log("pwded")<%2Fscript>.png'], + ['foo"bar.png'], + ['A "very" good file.png'] + ] + end - with_them do - let(:design) { create(:design, :with_versions, filename: filename, issue: issue) } - let(:link) { doc.css('a').first } + with_them do + let(:design) { create(:design, :with_versions, filename: filename, issue: issue) } - it 'replaces the content with the reference, but keeps the link', :aggregate_failures do - expect(doc.text).to eq(CGI.unescapeHTML("Added #{design.to_reference}")) - expect(link.attr('title')).to eq(design.filename) - expect(link.attr('href')).to eq(design_url) - end - end + it_behaves_like 'a no-op filter' end end diff --git a/spec/lib/gitlab/import_export/base/relation_factory_spec.rb b/spec/lib/gitlab/import_export/base/relation_factory_spec.rb index 6a7ff33465d..bd8873fe20e 100644 --- a/spec/lib/gitlab/import_export/base/relation_factory_spec.rb +++ b/spec/lib/gitlab/import_export/base/relation_factory_spec.rb @@ -102,7 +102,7 @@ RSpec.describe Gitlab::ImportExport::Base::RelationFactory do "updated_at" => "2016-11-18T09:29:42.634Z", "user" => { "id" => 999, - "email" => new_user.email, + "public_email" => new_user.email, "username" => new_user.username } } diff --git a/spec/lib/gitlab/import_export/group/legacy_tree_saver_spec.rb b/spec/lib/gitlab/import_export/group/legacy_tree_saver_spec.rb index 9e1571ae3d8..e075c5acfea 100644 --- a/spec/lib/gitlab/import_export/group/legacy_tree_saver_spec.rb +++ b/spec/lib/gitlab/import_export/group/legacy_tree_saver_spec.rb @@ -83,11 +83,12 @@ RSpec.describe Gitlab::ImportExport::Group::LegacyTreeSaver do let(:user2) { create(:user, email: 'group@member.com') } let(:member_emails) do saved_group_json['members'].map do |pm| - pm['user']['email'] + pm['user']['public_email'] end end before do + user2.update(public_email: user2.email) group.add_developer(user2) end diff --git a/spec/lib/gitlab/import_export/members_mapper_spec.rb b/spec/lib/gitlab/import_export/members_mapper_spec.rb index 04c27b6f8ad..847d6b5d1ed 100644 --- a/spec/lib/gitlab/import_export/members_mapper_spec.rb +++ b/spec/lib/gitlab/import_export/members_mapper_spec.rb @@ -24,7 +24,7 @@ RSpec.describe Gitlab::ImportExport::MembersMapper do "user" => { "id" => exported_user_id, - "email" => user2.email, + "public_email" => user2.email, "username" => 'test' }, "user_id" => 19 @@ -122,7 +122,7 @@ RSpec.describe Gitlab::ImportExport::MembersMapper do "user" => { "id" => exported_user_id, - "email" => user2.email, + "public_email" => user2.email, "username" => 'test' }, "user_id" => 19 @@ -157,6 +157,37 @@ RSpec.describe Gitlab::ImportExport::MembersMapper do expect(members_mapper.map[exported_user_id]).to eq(user2.id) end end + + context 'when user has email exported' do + let(:exported_members) do + [ + { + "id" => 2, + "access_level" => 40, + "source_id" => 14, + "source_type" => source_type, + "notification_level" => 3, + "created_at" => "2016-03-11T10:21:44.822Z", + "updated_at" => "2016-03-11T10:21:44.822Z", + "created_by_id" => nil, + "invite_email" => nil, + "invite_token" => nil, + "invite_accepted_at" => nil, + "user" => + { + "id" => exported_user_id, + "email" => user2.email, + "username" => 'test' + }, + "user_id" => 19 + } + ] + end + + it 'maps a member' do + expect(members_mapper.map[exported_user_id]).to eq(user2.id) + end + end end context 'when importable is Project' do @@ -212,7 +243,7 @@ RSpec.describe Gitlab::ImportExport::MembersMapper do before do group.add_users([user, user2], GroupMember::DEVELOPER) - user.update(email: 'invite@test.com') + user.update(public_email: 'invite@test.com') end it 'maps the importer' do diff --git a/spec/lib/gitlab/import_export/project/relation_factory_spec.rb b/spec/lib/gitlab/import_export/project/relation_factory_spec.rb index 38e700e8f9e..88bd71d3d64 100644 --- a/spec/lib/gitlab/import_export/project/relation_factory_spec.rb +++ b/spec/lib/gitlab/import_export/project/relation_factory_spec.rb @@ -119,7 +119,7 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory, :use_clean_rails_ "updated_at" => "2016-11-18T09:29:42.634Z", "user" => { "id" => admin.id, - "email" => admin.email, + "public_email" => admin.email, "username" => admin.username } } @@ -187,7 +187,7 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory, :use_clean_rails_ "updated_at" => "2016-11-18T09:29:42.634Z", "user" => { "id" => admin.id, - "email" => admin.email, + "public_email" => admin.email, "username" => admin.username } } diff --git a/spec/lib/gitlab/import_export/project/tree_saver_spec.rb b/spec/lib/gitlab/import_export/project/tree_saver_spec.rb index bee7c59cab0..374d688576e 100644 --- a/spec/lib/gitlab/import_export/project/tree_saver_spec.rb +++ b/spec/lib/gitlab/import_export/project/tree_saver_spec.rb @@ -299,12 +299,13 @@ RSpec.describe Gitlab::ImportExport::Project::TreeSaver do let(:member_emails) do emails = subject.map do |pm| - pm['user']['email'] + pm['user']['public_email'] end emails end before do + user2.update(public_email: user2.email) group.add_developer(user2) end diff --git a/spec/lib/object_storage/config_spec.rb b/spec/lib/object_storage/config_spec.rb index 0ead2a1d269..21b8a44b3d6 100644 --- a/spec/lib/object_storage/config_spec.rb +++ b/spec/lib/object_storage/config_spec.rb @@ -188,6 +188,7 @@ RSpec.describe ObjectStorage::Config do end context 'with SSE-KMS enabled' do + it { expect(subject.aws_server_side_encryption_enabled?).to be true } it { expect(subject.server_side_encryption).to eq('AES256') } it { expect(subject.server_side_encryption_kms_key_id).to eq('arn:aws:12345') } it { expect(subject.fog_attributes.keys).to match_array(%w(x-amz-server-side-encryption x-amz-server-side-encryption-aws-kms-key-id)) } @@ -196,6 +197,7 @@ RSpec.describe ObjectStorage::Config do context 'with only server side encryption enabled' do let(:storage_options) { { server_side_encryption: 'AES256' } } + it { expect(subject.aws_server_side_encryption_enabled?).to be true } it { expect(subject.server_side_encryption).to eq('AES256') } it { expect(subject.server_side_encryption_kms_key_id).to be_nil } it { expect(subject.fog_attributes).to eq({ 'x-amz-server-side-encryption' => 'AES256' }) } @@ -204,6 +206,7 @@ RSpec.describe ObjectStorage::Config do context 'without encryption enabled' do let(:storage_options) { {} } + it { expect(subject.aws_server_side_encryption_enabled?).to be false } it { expect(subject.server_side_encryption).to be_nil } it { expect(subject.server_side_encryption_kms_key_id).to be_nil } it { expect(subject.fog_attributes).to eq({}) } @@ -215,6 +218,5 @@ RSpec.describe ObjectStorage::Config do end it { expect(subject.enabled?).to be false } - it { expect(subject.fog_attributes).to eq({}) } end end |