Skip to content

Commit

Permalink
Improve aws tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simov committed Jan 26, 2016
1 parent 17d7cbc commit f871dfb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 39 deletions.
7 changes: 4 additions & 3 deletions request.js
Expand Up @@ -1232,7 +1232,7 @@ Request.prototype.aws = function (opts, now) {
}

if (opts.sign_version == 4 || opts.sign_version == '4') {
// Use aws-sign4
// use aws4
var options = {
host: self.uri.host,
path: self.uri.path,
Expand All @@ -1248,8 +1248,9 @@ Request.prototype.aws = function (opts, now) {
})
self.setHeader('authorization', signRes.headers.Authorization)
self.setHeader('x-amz-date', signRes.headers['X-Amz-Date'])
} else {
// Default behaviour -> use aws-sign2
}
else {
// default: use aws-sign2
var date = new Date()
self.setHeader('date', date.toUTCString())
var auth =
Expand Down
55 changes: 19 additions & 36 deletions tests/test-aws.js
@@ -1,11 +1,5 @@
'use strict'

if (process.env.running_under_istanbul) {
// test-agent.js modifies the process state
// causing these tests to fail when running under single process via tape
return
}

var request = require('../index')
, server = require('./server')
, tape = require('tape')
Expand All @@ -28,43 +22,32 @@ tape('setup', function(t) {
})

tape('default behaviour: aws-sign2 without sign_version key', function(t) {
var aws2_options = { aws: {} }
aws2_options.aws.key = 'my_key'
aws2_options.aws.secret = 'my_secret'
aws2_options.url = s.url + path
aws2_options.json = true

request(aws2_options, function(err, res, body) {
t.ok(body.authorization)
t.notOk(body['x-amz-date'])
t.end()
})
})

tape('aws-sign2 with sign_version key', function(t) {
var aws2_options = { aws: {} }
aws2_options.aws.key = 'my_key'
aws2_options.aws.secret = 'my_secret'
aws2_options.aws.sign_version = 2
aws2_options.url = s.url + path
aws2_options.json = true

request(aws2_options, function(err, res, body) {
var options = {
url: s.url + path,
aws: {
key: 'my_key',
secret: 'my_secret'
},
json: true
}
request(options, function(err, res, body) {
t.ok(body.authorization)
t.notOk(body['x-amz-date'])
t.end()
})
})

tape('aws-sign4 options', function(t) {
var aws2_options = { aws: {} }
aws2_options.aws.key = 'my_key'
aws2_options.aws.secret = 'my_secret'
aws2_options.aws.sign_version = 4
aws2_options.url = s.url + path
aws2_options.json = true

request(aws2_options, function(err, res, body) {
var options = {
url: s.url + path,
aws: {
key: 'my_key',
secret: 'my_secret',
sign_version: 4
},
json: true
}
request(options, function(err, res, body) {
t.ok(body.authorization)
t.ok(body['x-amz-date'])
t.end()
Expand Down

0 comments on commit f871dfb

Please sign in to comment.