Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Commit

Permalink
Added integration tests for Aws::S3::Encryption::Client.
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorrowe committed Dec 16, 2014
1 parent 5b58955 commit a056f35
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
21 changes: 21 additions & 0 deletions aws-sdk-resources/features/s3/client_side_encryption.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# language: en
@s3 @client-side-encryption
Feature: S3 Objects

Background:
Given I create a bucket

Scenario: Encrypting client-side with GET and PUT
Given I have an encryption client
When I perform an encrypted PUT of the value "secret"
And I GET the object with a non-encyrption client
Then the object data should be encrypted
When I GET the object with an encryption client
Then the object data should be "secret"

Scenario: Using instruction file for storing the encryption envelope
Given I have an encryption client configured for :instruction_file
When I perform an encrypted PUT of the value "secret"
Then the instruction file should exist
When I GET the object with an encryption client
Then the object data should be "secret"
45 changes: 45 additions & 0 deletions aws-sdk-resources/features/s3/step_definitions.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'base64'

Before("@s3") do
@s3 = Aws::S3::Resource.new
@created_buckets = []
Expand Down Expand Up @@ -37,3 +39,46 @@
Then(/^the file should have been uploaded as a multipart upload$/) do
expect(ApiCallTracker.called_operations).to include('create_multipart_upload')
end

Given(/^I have an encryption client$/) do
@cse = Aws::S3::Encryption::Client.new({
client: @s3.client,
encryption_key: Base64.decode64("w1WLio3agRWRTSJK/Ouh8NHoqRQ6fn5WbSXDTHjXMSo="),
})
end

Given(/^I have an encryption client configured for :instruction_file$/) do
@cse = Aws::S3::Encryption::Client.new({
client: @s3.client,
encryption_key: Base64.decode64("w1WLio3agRWRTSJK/Ouh8NHoqRQ6fn5WbSXDTHjXMSo="),
envelope_location: :instruction_file,
})
end

When(/^I perform an encrypted PUT of the value "(.*?)"$/) do |value|
@key = 'encrypted'
@plain_text = value
@cse.put_object(bucket: @bucket_name, key: @key, body: @plain_text)
end

When(/^I GET the object with a non\-encyrption client$/) do
@cipher_text = @s3.client.get_object(bucket: @bucket_name, key: @key).body.read
end

Then(/^the object data should be encrypted$/) do
expect(@cipher_text).not_to eq(@plaint_text)
end

When(/^I GET the object with an encryption client$/) do
@plain_text = @cse.get_object(bucket: @bucket_name, key: @key).body.read
end

Then(/^the object data should be "(.*?)"$/) do |value|
expect(@plain_text).to eq(value)
end

Then(/^the instruction file should exist$/) do
expect {
@s3.client.head_object(bucket: @bucket_name, key: @key + '.instruction')
}.not_to raise_error
end

4 comments on commit a056f35

@sariyamelody
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this supposed to be @plain_text? (Apologies for pedantry if not)

@trevorrowe
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skyhighwings Can you clarify what line you are referencing?

@trevorrowe
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skyhighwings If you are referencing line 65, then no. This line is using a vanilla, non-encryption client to get the encrypted data, e.g. the cipher text.

@sariyamelody
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trevorrowe
Nope, line 69! + expect(@cipher_text).not_to eq(@plaint_text).

I feel like I clicked on that and GitHub somehow failed to attach it to the correct line number.

Please sign in to comment.