diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-27 15:07:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-27 15:07:43 +0300 |
commit | 39fa7d1eeb2dba52f0601128f3ac91f57d19866e (patch) | |
tree | da042d34ff762dd1957e51666a34202295a081b9 /spec/uploaders/terraform/state_uploader_spec.rb | |
parent | 6ac4a6713ed3196af899011f7e18658e16ebaac0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/uploaders/terraform/state_uploader_spec.rb')
-rw-r--r-- | spec/uploaders/terraform/state_uploader_spec.rb | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/spec/uploaders/terraform/state_uploader_spec.rb b/spec/uploaders/terraform/state_uploader_spec.rb new file mode 100644 index 00000000000..4577a2c4738 --- /dev/null +++ b/spec/uploaders/terraform/state_uploader_spec.rb @@ -0,0 +1,82 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Terraform::StateUploader do + subject { terraform_state.file } + + let(:terraform_state) { create(:terraform_state, file: fixture_file_upload('spec/fixtures/terraform/terraform.tfstate')) } + + before do + stub_terraform_state_object_storage + end + + describe '#filename' do + it 'contains the ID of the terraform state record' do + expect(subject.filename).to include(terraform_state.id.to_s) + end + end + + describe '#store_dir' do + it 'contains the ID of the project' do + expect(subject.store_dir).to include(terraform_state.project_id.to_s) + end + end + + describe '#key' do + it 'creates a digest with a secret key and the project id' do + expect(OpenSSL::HMAC) + .to receive(:digest) + .with('SHA256', Gitlab::Application.secrets.db_key_base, terraform_state.project_id.to_s) + .and_return('digest') + + expect(subject.key).to eq('digest') + end + end + + describe 'encryption' do + it 'encrypts the stored file' do + expect(subject.file.read).not_to eq(fixture_file('terraform/terraform.tfstate')) + end + + it 'decrypts the file when reading' do + expect(subject.read).to eq(fixture_file('terraform/terraform.tfstate')) + end + end + + describe '.direct_upload_enabled?' do + it 'returns false' do + expect(described_class.direct_upload_enabled?).to eq(false) + end + end + + describe '.background_upload_enabled?' do + it 'returns false' do + expect(described_class.background_upload_enabled?).to eq(false) + end + end + + describe '.proxy_download_enabled?' do + it 'returns true' do + expect(described_class.proxy_download_enabled?).to eq(true) + end + end + + describe '.default_store' do + context 'when object storage is enabled' do + it 'returns REMOTE' do + expect(described_class.default_store).to eq(ObjectStorage::Store::REMOTE) + end + end + + context 'when object storage is disabled' do + before do + stub_terraform_state_object_storage(enabled: false) + end + + it 'returns LOCAL' do + expect(described_class.default_store).to eq(ObjectStorage::Store::LOCAL) + end + end + end +end |