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

knox-ec2-role

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knox-ec2-role - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

25

index.js
var AWS = require('aws-sdk')
, debug = require('debug')('knox-ec2-role')
, knox = require('knox')
, Promise = require('bluebird')
module.exports = {
authenticate: function (conf, httpOptions) {
return new Promise(function (resolve, reject) {
if (!conf) {
conf = {}
}
Object.assign(AWS.config.httpOptions, httpOptions)
var metadata = new AWS.MetadataService()
debug('loading credentials from aws metadata')
metadata.loadCredentials(function (err, creds) {
if (err) {
debug('error: ', err)
reject(err)
return
}
conf = conf || {}
var metadata = new AWS.MetadataService()
Object.assign(AWS.config.httpOptions, httpOptions)
return metadata.loadCredentials().promise()
.then(function (creds) {
debug('loading credentials from aws metadata')
debug(creds)

@@ -25,11 +17,10 @@ Object.assign(conf, {key: creds.AccessKeyId, secret: creds.SecretAccessKey, token: creds.Token})

var client = knox.createClient(conf)
resolve(client)
return Promise.resolve(client)
} catch (e) {
debug(e)
debug(e.stack)
reject(e)
return Promise.reject(e)
}
})
})
}
}

@@ -9,7 +9,5 @@ {

],
"version": "0.0.2",
"version": "0.0.3",
"dependencies": {
"aws-sdk": "^2.28.0",
"bluebird": "^3.5.0",
"chai": "^3.5.0",
"knox": "^0.9.2"

@@ -30,2 +28,4 @@ },

"aws-sdk-mock": "^1.6.1",
"chai-as-promised": "^6.0.0",
"chai": "^3.5.0",
"dotenv": "^4.0.0",

@@ -32,0 +32,0 @@ "eslint": "^1.4.1",

@@ -0,1 +1,2 @@

'use strict'
var chai = require('chai')

@@ -5,14 +6,19 @@ , expect = chai.expect

, AWS = require('aws-sdk-mock')
, knoxec2
chai.use(require('chai-as-promised'))
AWS.mock('MetadataService', 'loadCredentials', function (callback) {
callback(null, {AccessKeyId: process.env.ACCESS_KEY_ID
, SecretAccessKey: process.env.SECRET_ACCESS_KEY})
})
knoxec2 = proxyquire('../index.js', { 'AWS': AWS })
describe('knox-ec2-role', function () {
describe('uploading files', function () {
let knoxec2
before(function () {
AWS.mock('MetadataService', 'loadCredentials', function (callback) {
callback(null, {AccessKeyId: process.env.ACCESS_KEY_ID
, SecretAccessKey: process.env.SECRET_ACCESS_KEY})
})
knoxec2 = proxyquire('../index.js', { 'AWS': AWS })
})
after(function () {
knoxec2 = null
AWS.restore('MetadataService')
})
it('should upload file', function (done) {
var defaultConf = {bucket: process.env.K2_BUCKET}
knoxec2.authenticate(defaultConf, {timeout: 5000})
knoxec2.authenticate({bucket: process.env.K2_BUCKET}, {timeout: 5000})
.then(function (client) {

@@ -31,7 +37,37 @@ var object = { foo: 'bar' }

})
.catch(function (e) {
expect(e).to.not.be.true
done()
})
it('should fail to upload with a bad bucket', function (done) {
knoxec2.authenticate({bucket: process.env.K2_BUCKET + 'xxx'}, {timeout: 5000})
.then(function (client) {
var object = { foo: 'bar' }
, string = JSON.stringify(object)
, req = client.put('/test/obj.json', {
'Content-Length': Buffer.byteLength(string)
, 'Content-Type': 'application/json'
})
req.on('response', function (res) {
expect(res.statusCode).to.equal(404)
done()
})
req.end(string)
})
})
})
describe('failed metadata test', function () {
let knoxec2
before(function () {
AWS.mock('MetadataService', 'loadCredentials', function (callback) {
// force error
callback(true)
})
knoxec2 = proxyquire('../index.js', { 'AWS': AWS })
})
after(function () {
knoxec2 = null
AWS.restore('MetadataService')
})
it('should reject a broken promise', function () {
return expect(knoxec2.authenticate({bucket: process.env.K2_BUCKET}, {timeout: 5000})).to.be.rejected
})
})

Sorry, the diff of this file is not supported yet

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