Skip to content

Commit

Permalink
Update specs
Browse files Browse the repository at this point in the history
  • Loading branch information
atyndall committed Aug 18, 2021
1 parent 97505b9 commit 2c79ca0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
12 changes: 6 additions & 6 deletions spec/kms_rails/active_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
subject { FirstArgEncryptedJob }

it 'calls the encryption routine once' do
expect_any_instance_of(KmsRails::Aws::KMS::Client).to receive(:generate_data_key)
expect(KmsRails.configuration.kms_client).to receive(:generate_data_key)
.once
.with(hash_including(key_id: 'alias/q', key_spec: 'AES_256'))
.and_call_original
Expand All @@ -24,7 +24,7 @@
end

it 'doesn\'t double encrypt an already encrypted value' do
expect_any_instance_of(KmsRails::Aws::KMS::Client).to_not receive(:generate_data_key)
expect(KmsRails.configuration.kms_client).to_not receive(:generate_data_key)

subject.new(
{'key' => 'YmF6', 'iv' => 'Zm9v', 'blob' => 'YmFy'},
Expand All @@ -34,7 +34,7 @@
end

it 'doesn\'t encrypt nil' do
expect_any_instance_of(KmsRails::Aws::KMS::Client).to_not receive(:generate_data_key)
expect(KmsRails.configuration.kms_client).to_not receive(:generate_data_key)

subject.new(
nil,
Expand All @@ -48,7 +48,7 @@
subject { SecondThirdArgEncryptedJob }

it 'calls the encryption routine twice' do
expect_any_instance_of(KmsRails::Aws::KMS::Client).to receive(:generate_data_key)
expect(KmsRails.configuration.kms_client).to receive(:generate_data_key)
.twice
.with(hash_including(key_id: 'alias/r', key_spec: 'AES_256'))
.and_call_original
Expand All @@ -71,7 +71,7 @@
subject { FirstArgMsgPackEncryptedJob }

it 'calls the encryption routine once' do
expect_any_instance_of(KmsRails::Aws::KMS::Client).to receive(:generate_data_key)
expect(KmsRails.configuration.kms_client).to receive(:generate_data_key)
.once
.with(hash_including(key_id: 'alias/s', key_spec: 'AES_256'))
.and_call_original
Expand All @@ -93,7 +93,7 @@
subject { SecondThirdArgMsgPackEncryptedJob }

it 'calls the encryption routine twice' do
expect_any_instance_of(KmsRails::Aws::KMS::Client).to receive(:generate_data_key)
expect(KmsRails.configuration.kms_client).to receive(:generate_data_key)
.twice
.with(hash_including(key_id: 'alias/t', key_spec: 'AES_256'))
.and_call_original
Expand Down
18 changes: 9 additions & 9 deletions spec/kms_rails/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
end

it 'calls KMS' do
expect_any_instance_of(KmsRails::Aws::KMS::Client).to receive(:generate_data_key)
expect(KmsRails.configuration.kms_client).to receive(:generate_data_key)
.once
.with(hash_including(key_id: 'alias/a', key_spec: 'AES_256'))
.and_call_original
Expand All @@ -203,7 +203,7 @@
it 'decrypts the value and calls kms' do
subject.the_secret = 'foo'

expect_any_instance_of(KmsRails::Aws::KMS::Client).to receive(:decrypt)
expect(KmsRails.configuration.kms_client).to receive(:decrypt)
.once
.and_call_original

Expand Down Expand Up @@ -234,7 +234,7 @@

context 'retain off' do
it 'decrypts every time when retain is disabled' do
expect_any_instance_of(KmsRails::Aws::KMS::Client).to receive(:decrypt)
expect(KmsRails.configuration.kms_client).to receive(:decrypt)
.twice
.and_call_original

Expand All @@ -247,7 +247,7 @@
let(:model) { NormalModelRetain }

it 'doesn\'t decrypt when it has already been set' do
expect_any_instance_of(KmsRails::Aws::KMS::Client).not_to receive(:decrypt)
expect(KmsRails.configuration.kms_client).not_to receive(:decrypt)

expect(subject.the_secret).to eq('bar')
expect(subject.the_secret).to eq('bar')
Expand All @@ -256,7 +256,7 @@
it 'decrypts only once when cleared' do
subject.the_secret_clear

expect_any_instance_of(KmsRails::Aws::KMS::Client).to receive(:decrypt)
expect(KmsRails.configuration.kms_client).to receive(:decrypt)
.once
.and_call_original

Expand Down Expand Up @@ -334,12 +334,12 @@
subject { ContextStringModel.new }

it 'encrypts and decrypts with same context' do
expect_any_instance_of(KmsRails::Aws::KMS::Client).to receive(:generate_data_key)
expect(KmsRails.configuration.kms_client).to receive(:generate_data_key)
.once
.with(hash_including(encryption_context: {'foo' => 'bar'}))
.and_call_original

expect_any_instance_of(KmsRails::Aws::KMS::Client).to receive(:decrypt)
expect(KmsRails.configuration.kms_client).to receive(:decrypt)
.once
.with(hash_including(encryption_context: {'foo' => 'bar'}))
.and_call_original
Expand All @@ -366,12 +366,12 @@
subject { ContextProcModel.new }

it 'encrypts and decrypts with same context' do
expect_any_instance_of(KmsRails::Aws::KMS::Client).to receive(:generate_data_key)
expect(KmsRails.configuration.kms_client).to receive(:generate_data_key)
.once
.with(hash_including(encryption_context: {'nerpsnerp' => 'borpnorp'}))
.and_call_original

expect_any_instance_of(KmsRails::Aws::KMS::Client).to receive(:decrypt)
expect(KmsRails.configuration.kms_client).to receive(:decrypt)
.once
.with(hash_including(encryption_context: {'nerpsnerp' => 'borpnorp'}))
.and_call_original
Expand Down
12 changes: 6 additions & 6 deletions spec/kms_rails/kms_client_mock_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe KmsRails::Aws::KMS::Client do
subject { KmsRails::Aws::KMS::Client.new }
describe KmsRails::KmsClientMock do
subject { described_class.new }

it 'encrypts and decrypts a string correct' do
data_key = subject.generate_data_key(key_id: 'a', key_spec: 'AES_256')
Expand All @@ -12,7 +12,7 @@
it 'raises error when decrypting malformed text' do
expect {
subject.decrypt(ciphertext_blob: 't8hvosdjdlqegohqevnsLCKsz')
}.to raise_error(::Aws::KMS::Errors::InvalidCiphertextException)
}.to raise_error(Aws::KMS::Errors::InvalidCiphertextException)
end

it 'allows inspect' do
Expand All @@ -35,23 +35,23 @@

expect {
subject.decrypt(ciphertext_blob: data_key.ciphertext_blob, encryption_context: {'foo' => 'norp'})
}.to raise_error(::Aws::KMS::Errors::InvalidCiphertextException)
}.to raise_error(Aws::KMS::Errors::InvalidCiphertextException)
end

it 'fails with undeclared generate' do
data_key = subject.generate_data_key(key_id: 'a', key_spec: 'AES_256')

expect {
subject.decrypt(ciphertext_blob: data_key.ciphertext_blob, encryption_context: {'foo' => 'norp'})
}.to raise_error(::Aws::KMS::Errors::InvalidCiphertextException)
}.to raise_error(Aws::KMS::Errors::InvalidCiphertextException)
end

it 'fails with undeclared decrpt' do
data_key = subject.generate_data_key(key_id: 'a', key_spec: 'AES_256', encryption_context: {'foo' => 'bar'})

expect {
subject.decrypt(ciphertext_blob: data_key.ciphertext_blob)
}.to raise_error(::Aws::KMS::Errors::InvalidCiphertextException)
}.to raise_error(Aws::KMS::Errors::InvalidCiphertextException)
end
end
end

0 comments on commit 2c79ca0

Please sign in to comment.