Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aws4

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws4 - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

2

package.json
{
"name": "aws4",
"version": "0.1.1",
"version": "0.1.2",
"description": "Signs and prepares requests using AWS Signature Version 4",

@@ -5,0 +5,0 @@ "author": "Michael Hart <michael.hart.au@gmail.com> (http://github.com/mhart)",

@@ -12,15 +12,38 @@ var should = require('should')

// Ensure we restore process.env in case a test modifies it
var env = {
AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY: process.env.AWS_SECRET_ACCESS_KEY
}
// Save and ensure we restore process.env
var envAccessKeyId, envSecretAccessKey
before(function() {
envAccessKeyId = process.env.AWS_ACCESS_KEY_ID
envSecretAccessKey = process.env.AWS_SECRET_ACCESS_KEY
process.env.AWS_ACCESS_KEY_ID = cred.accessKeyId
process.env.AWS_SECRET_ACCESS_KEY = cred.secretAccessKey
})
after(function() {
process.env.AWS_ACCESS_KEY_ID = env.AWS_ACCESS_KEY_ID
process.env.AWS_SECRET_ACCESS_KEY = env.AWS_SECRET_ACCESS_KEY
process.env.AWS_ACCESS_KEY_ID = envAccessKeyId
process.env.AWS_SECRET_ACCESS_KEY = envSecretAccessKey
})
describe('#sign() with no credentials', function() {
it('should use process.env values', function() {
var opts = aws4.sign({ service: 'sqs', headers: { Date: date } })
opts.headers['Authorization'].should.equal(auth)
})
})
describe('#sign() with credentials', function() {
it('should use passed in values', function() {
var cred = { accessKeyId: 'A', secretAccessKey: 'B' }
var opts = aws4.sign({ service: 'sqs', headers: { Date: date } }, cred)
opts.headers['Authorization'].should.equal(
'AWS4-HMAC-SHA256 Credential=A/20121226/us-east-1/sqs/aws4_request, ' +
'SignedHeaders=date;host;x-amz-date, ' +
'Signature=5d8d587b6e3011935837d670e682646012977960d8a8d992503d852726af71b9')
})
})
describe('#sign() with no host or region', function() {
var opts = aws4.sign({ service: 'sqs', headers: { Date: date } }, cred)
it('should add hostname and default region', function() {
var opts = aws4.sign({ service: 'sqs', headers: { Date: date } })
opts.hostname.should.equal('sqs.us-east-1.amazonaws.com')

@@ -30,2 +53,3 @@ opts.headers['Host'].should.equal('sqs.us-east-1.amazonaws.com')

it('should populate AWS headers correctly', function() {
var opts = aws4.sign({ service: 'sqs', headers: { Date: date } })
opts.headers['X-Amz-Date'].should.equal(iso)

@@ -37,4 +61,4 @@ opts.headers['Authorization'].should.equal(auth)

describe('#sign() with no host, but with region', function() {
var opts = aws4.sign({ service: 'glacier', region: 'us-west-1' }, cred)
it('should add correct hostname', function() {
var opts = aws4.sign({ service: 'glacier', region: 'us-west-1' })
opts.hostname.should.equal('glacier.us-west-1.amazonaws.com')

@@ -46,4 +70,4 @@ opts.headers['Host'].should.equal('glacier.us-west-1.amazonaws.com')

describe('#sign() with hostname', function() {
var opts = aws4.sign({ hostname: 'sqs.us-east-1.amazonaws.com', headers: { Date: date } }, cred)
it('should populate AWS headers correctly', function() {
var opts = aws4.sign({ hostname: 'sqs.us-east-1.amazonaws.com', headers: { Date: date } })
opts.headers['X-Amz-Date'].should.equal(iso)

@@ -55,4 +79,4 @@ opts.headers['Authorization'].should.equal(auth)

describe('#sign() with host', function() {
var opts = aws4.sign({ host: 'sqs.us-east-1.amazonaws.com', headers: { Date: date } }, cred)
it('should populate AWS headers correctly', function() {
var opts = aws4.sign({ host: 'sqs.us-east-1.amazonaws.com', headers: { Date: date } })
opts.headers['X-Amz-Date'].should.equal(iso)

@@ -64,7 +88,8 @@ opts.headers['Authorization'].should.equal(auth)

describe('#sign() with body', function() {
var opts = aws4.sign({ body: 'SomeAction' }, cred)
it('should use POST', function() {
var opts = aws4.sign({ body: 'SomeAction' })
opts.method.should.equal('POST')
})
it('should set Content-Type', function() {
var opts = aws4.sign({ body: 'SomeAction' })
opts.headers['Content-Type'].should.equal('application/x-www-form-urlencoded')

@@ -74,25 +99,16 @@ })

describe('#sign() with no credentials', function() {
process.env.AWS_ACCESS_KEY_ID = cred.accessKeyId
process.env.AWS_SECRET_ACCESS_KEY = cred.secretAccessKey
var opts = aws4.sign({ service: 'sqs', headers: { Date: date } })
it('should use process.env values', function() {
opts.headers['Authorization'].should.equal(auth)
})
})
describe('#sign() with many different options', function() {
var opts = aws4.sign({
service: 'dynamodb',
region: 'ap-southeast-2',
method: 'DELETE',
path: '/Some/Path?param=key&param=otherKey',
body: 'SomeAction=SomeThing&Whatever=SomeThingElse',
headers: {
Date: date,
'Content-Type': 'application/x-amz-json-1.0',
'X-Amz-Target': 'DynamoDB_20111205.ListTables'
}
}, cred)
it('should populate AWS headers correctly', function() {
var opts = aws4.sign({
service: 'dynamodb',
region: 'ap-southeast-2',
method: 'DELETE',
path: '/Some/Path?param=key&param=otherKey',
body: 'SomeAction=SomeThing&Whatever=SomeThingElse',
headers: {
Date: date,
'Content-Type': 'application/x-amz-json-1.0',
'X-Amz-Target': 'DynamoDB_20111205.ListTables'
}
})
opts.headers['X-Amz-Date'].should.equal(iso)

@@ -99,0 +115,0 @@ opts.headers['Authorization'].should.equal(

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc