Skip to content

Commit

Permalink
Add additional test coverage for CRC32 checks
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaManohar committed Dec 5, 2014
1 parent 74bdb41 commit 9d7c413
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions test/services/dynamodb.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,33 @@ describe 'AWS.DynamoDB', ->
expect(ddb().retryDelays()).to.eql(delays)

describe 'CRC32 check', ->
dynamo = null;
dynamo = null

beforeEach ->
dynamo = ddb(accessKeyId: 'AKID', secretAccessKey: 'SECRET', region: 'us-west-2')

if AWS.util.isNode()
it 'does not verify response checksum when streaming', ->
spy = helpers.spyOn(dynamo, 'crc32IsValid')
helpers.mockHttpResponse 200, {'x-amz-crc32': '1575962599'}, """{"TableNames":["mock-table"]}"""
helpers.mockHttpResponse 200, {'x-amz-crc32': '0'}, """{"TableNames":["mock-table"]}"""
request = dynamo.makeRequest('listTables')
s = request.createReadStream()
s.on 'end', ->
expect(spy.calls.length).to.eql(0)
expect(request.error).to.eql(null)

it 'does verify response checksum when not streaming', ->
spy = helpers.spyOn(dynamo, 'crc32IsValid').andCallThrough()
helpers.mockHttpResponse 200, {'x-amz-crc32': '1575962599'}, """{"TableNames":["mock-table"]}"""
request = dynamo.makeRequest('listTables')
request.send (err, data) ->
expect(spy.calls.length).to.eql(1)
expect(err).to.eql(null)

it 'does not verify response checksum when no [x-amz-crc32] header', ->
helpers.mockHttpResponse 200, {}, """{"TableNames":["mock-table"]}"""
request = dynamo.makeRequest('listTables')
request.send (err, data) ->
expect(err).to.eql(null)

it 'throws an error when response checksum does not match', ->
helpers.mockHttpResponse 200, {'x-amz-crc32': '0'}, """{"TableNames":["mock-table"]}"""
request = dynamo.makeRequest('listTables')
request.send (err, data) ->
expect(err.code).to.eql('CRC32CheckFailed')

0 comments on commit 9d7c413

Please sign in to comment.