From f871dfb9b732caa745f74cc799788368dfdd79a3 Mon Sep 17 00:00:00 2001 From: simov Date: Tue, 26 Jan 2016 12:09:30 +0200 Subject: [PATCH] Improve aws tests --- request.js | 7 +++--- tests/test-aws.js | 55 ++++++++++++++++------------------------------- 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/request.js b/request.js index 4ef403ff6..8dc900569 100644 --- a/request.js +++ b/request.js @@ -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, @@ -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 = diff --git a/tests/test-aws.js b/tests/test-aws.js index b3200cbaa..be4314349 100644 --- a/tests/test-aws.js +++ b/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') @@ -28,28 +22,15 @@ 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() @@ -57,14 +38,16 @@ tape('aws-sign2 with sign_version key', function(t) { }) 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()