Comparing version
44
aws2.js
@@ -1,5 +0,5 @@ | ||
var aws2 = exports | ||
var url = require('url') | ||
var crypto = require('crypto') | ||
var querystring = require('querystring') | ||
var aws2 = exports, | ||
url = require('url'), | ||
crypto = require('crypto'), | ||
querystring = require('querystring') | ||
@@ -14,4 +14,4 @@ // http://docs.amazonwebservices.com/general/latest/gr/signature-version-2.html | ||
var headers = request.headers || {} | ||
, hostParts = this.matchHost(request.hostname || request.host || headers['Host']) | ||
var headers = request.headers || {}, | ||
hostParts = this.matchHost(request.hostname || request.host || headers.Host) | ||
@@ -45,8 +45,8 @@ this.request = request | ||
RequestSigner.prototype.sign = function() { | ||
var request = this.request | ||
, headers = request.headers = (request.headers || {}) | ||
, date = new Date(headers['Date'] || new Date) | ||
, pathParts = this.pathParts = (request.path || '/').split('?', 2) | ||
, query = request.body || pathParts[1] | ||
, params = this.params = querystring.parse(query) | ||
var request = this.request, | ||
headers = request.headers = (request.headers || {}), | ||
date = new Date(headers.Date || new Date), | ||
pathParts = this.pathParts = (request.path || '/').split('?', 2), | ||
query = request.body || pathParts[1], | ||
params = this.params = querystring.parse(query) | ||
@@ -56,6 +56,6 @@ if (!request.method && request.body) | ||
if (!headers['Host'] && !headers['host']) | ||
headers['Host'] = request.hostname || request.host || this.createHost() | ||
if (!headers.Host && !headers.host) | ||
headers.Host = request.hostname || request.host || this.createHost() | ||
if (!request.hostname && !request.host) | ||
request.hostname = headers['Host'] || headers['host'] | ||
request.hostname = headers.Host || headers.host | ||
@@ -67,12 +67,12 @@ if (request.body && !headers['Content-Type'] && !headers['content-type']) | ||
headers['X-Amz-Security-Token'] = this.credentials.sessionToken | ||
params['SecurityToken'] = this.credentials.sessionToken | ||
params.SecurityToken = this.credentials.sessionToken | ||
} | ||
params['Timestamp'] = date.toISOString() | ||
params['SignatureVersion'] = '2' | ||
params['SignatureMethod'] = 'HmacSHA256' | ||
params['AWSAccessKeyId'] = this.credentials.accessKeyId | ||
params.Timestamp = date.toISOString() | ||
params.SignatureVersion = '2' | ||
params.SignatureMethod = 'HmacSHA256' | ||
params.AWSAccessKeyId = this.credentials.accessKeyId | ||
delete params['Signature'] | ||
params['Signature'] = this.signature() | ||
if (params.Signature) delete params.Signature | ||
params.Signature = this.signature() | ||
@@ -79,0 +79,0 @@ query = querystring.stringify(params) |
@@ -1,4 +0,4 @@ | ||
var http = require('http') | ||
, https = require('https') | ||
, aws2 = require('aws2') | ||
var http = require('http'), | ||
https = require('https'), | ||
aws2 = require('aws2') | ||
@@ -5,0 +5,0 @@ // given an options object you could pass to http.request |
{ | ||
"name": "aws2", | ||
"version": "0.1.3", | ||
"version": "0.1.5", | ||
"description": "Signs and prepares requests using AWS Signature Version 2", | ||
@@ -15,3 +15,2 @@ "author": "Michael Hart <michael.hart.au@gmail.com> (http://github.com/mhart)", | ||
"importexport", | ||
"sns", | ||
"sdb", | ||
@@ -18,0 +17,0 @@ "simpledb" |
@@ -10,3 +10,2 @@ aws2 | ||
This signature is supported by a number of (older) Amazon services, including | ||
[SNS](http://docs.aws.amazon.com/sns/latest/api/), | ||
[EC2](http://docs.aws.amazon.com/AWSEC2/latest/APIReference/), | ||
@@ -13,0 +12,0 @@ [ElastiCache](http://docs.aws.amazon.com/AmazonElastiCache/latest/APIReference/), |
@@ -1,7 +0,7 @@ | ||
var should = require('should') | ||
, aws2 = require('../') | ||
, cred = { accessKeyId: 'ABCDEF', secretAccessKey: 'abcdef1234567890' } | ||
, date = 'Wed, 26 Dec 2012 06:10:30 GMT' | ||
, path = '/?Action=ListQueues&Version=2009-02-01' | ||
, sig = /Signature=DLYbFaqPn%2BgKVbpNrqA6feoGyczH%2B30nNmlFYGS18yk%3D/ | ||
require('should') | ||
var aws2 = require('../'), | ||
cred = { accessKeyId: 'ABCDEF', secretAccessKey: 'abcdef1234567890' }, | ||
date = 'Wed, 26 Dec 2012 06:10:30 GMT', | ||
path = '/?Action=ListQueues&Version=2009-02-01', | ||
sig = /Signature=DLYbFaqPn%2BgKVbpNrqA6feoGyczH%2B30nNmlFYGS18yk%3D/ | ||
@@ -42,4 +42,4 @@ describe('aws2', function() { | ||
it('should use passed in values', function() { | ||
var cred = { accessKeyId: 'A', secretAccessKey: 'B' } | ||
, opts = aws2.sign({ service: 'sqs', path: path, headers: { Date: date } }, cred) | ||
var cred = { accessKeyId: 'A', secretAccessKey: 'B' }, | ||
opts = aws2.sign({ service: 'sqs', path: path, headers: { Date: date } }, cred) | ||
opts.path.should.match(/Z0LJr9UHo%2FvePJ8fUhB5fMqog%2Fi6tNHib25%2BItMSfDY%3D/) | ||
@@ -53,3 +53,3 @@ }) | ||
opts.hostname.should.equal('sqs.us-east-1.amazonaws.com') | ||
opts.headers['Host'].should.equal('sqs.us-east-1.amazonaws.com') | ||
opts.headers.Host.should.equal('sqs.us-east-1.amazonaws.com') | ||
}) | ||
@@ -59,3 +59,3 @@ it('should add hostname and no region if service is regionless', function() { | ||
opts.hostname.should.equal('iam.amazonaws.com') | ||
opts.headers['Host'].should.equal('iam.amazonaws.com') | ||
opts.headers.Host.should.equal('iam.amazonaws.com') | ||
}) | ||
@@ -68,3 +68,3 @@ }) | ||
opts.hostname.should.equal('glacier.us-west-1.amazonaws.com') | ||
opts.headers['Host'].should.equal('glacier.us-west-1.amazonaws.com') | ||
opts.headers.Host.should.equal('glacier.us-west-1.amazonaws.com') | ||
}) | ||
@@ -71,0 +71,0 @@ }) |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
17298
-0.84%259
-0.77%174
-0.57%