New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

s3proxy

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

s3proxy - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

Makefile

17

package.json
{
"name": "s3proxy",
"version": "1.0.0",
"version": "1.1.0",
"description": "Front AWS S3 with a web server that you control",
"main": "s3proxy.js",
"dependencies": {},
"dependencies": {
"aws-sdk": "^2.118.0"
},
"devDependencies": {
"chai": "^4.1.2",
"eslint": "^4.7.0",
"eslint-config-airbnb-base": "^12.0.0",
"eslint-plugin-import": "^2.7.0",
"mocha": "^3.5.3",

@@ -13,7 +18,7 @@ "sinon": "^3.2.1"

"scripts": {
"test": "mocha"
"test": "make -j test"
},
"repository": {
"type": "git",
"url": "git+https://github.com/gmoon/s3front.git"
"url": "git+https://github.com/gmoon/s3proxy.git"
},

@@ -31,5 +36,5 @@ "keywords": [

"bugs": {
"url": "https://github.com/gmoon/s3front/issues"
"url": "https://github.com/gmoon/s3proxy/issues"
},
"homepage": "https://github.com/gmoon/s3front#readme"
"homepage": "https://github.com/gmoon/s3proxy#readme"
}

@@ -1,14 +0,60 @@

'use strict';
/* jslint node: true, esversion: 6 */
const EventEmitter = require('events');
const AWS = require('aws-sdk');
module.exports = class s3front extends EventEmitter {
constructor() {
super();
};
init() {
this.emit('init');
}
class UserException extends Error {
constructor(code, message) {
super(message);
this.code = code;
}
}
module.exports = class s3proxy extends EventEmitter {
constructor(p) {
super();
if (!p) {
throw new UserException('InvalidParameterList', 'constructor parameters are required');
}
if (!p.bucket) {
throw new UserException('InvalidParameterList', 'bucket parameter is required');
}
this.bucket = p.bucket;
}
init(done) {
const params = {};
params.apiVersion = '2006-03-01';
this.credentials = new AWS.SharedIniFileCredentials();
AWS.config.credentials = this.credentials;
this.s3 = new AWS.S3(params);
this.s3.headBucket({ Bucket: this.bucket }, (error, data) => {
if (error) {
if (typeof done === 'undefined') {
this.emit('error', error);
}
} else {
this.emit('init', data);
}
if (typeof done === 'function') { done(error, data); }
});
}
createReadStream(key) {
this.isInitialized();
const params = { Bucket: this.bucket, Key: s3proxy.stripLeadingSlash(key) };
const s3request = this.s3.getObject(params);
const s3stream = s3request.createReadStream();
s3request.on('httpHeaders', (statusCode, headers) => {
s3stream.emit('httpHeaders', statusCode, headers);
});
return s3stream;
}
isInitialized() {
if (!this.s3) {
const error = new UserException('UninitializedError', 'S3Proxy is uninitialized (call s3proxy.init)');
throw error;
}
}
static stripLeadingSlash(str) {
return str.replace(/^\/+/, '');
}
};

@@ -1,22 +0,89 @@

var expect = require('chai').expect
, s3proxy = require('./s3proxy.js')
, proxy = new s3proxy();
/* eslint-env mocha, node, es6 */
describe('s3front', function() {
describe('constructor', function() {
it('should be an object', function() {
expect(proxy).to.be.an('object');
const chai = require('chai');
const S3Proxy = require('./s3proxy.js');
const { expect } = chai;
describe('s3proxy', () => {
describe('constructor', () => {
it('should return an object', () => {
const proxy = new S3Proxy({ bucket: 'codeassist-repo' });
expect(proxy).to.be.an('object');
});
});
describe('initialization', () => {
const proxy = new S3Proxy({ bucket: 'codeassist-repo' });
it('should throw an exception if it is not initialized', (done) => {
try {
proxy.isInitialized();
} catch (e) {
expect(e.code).to.equal('UninitializedError');
done();
}
});
it("should emit an 'init' event", (done) => {
proxy.on('init', () => {
done();
});
});
describe('initialization', function() {
it("should emit an 'init' event", function(done) {
proxy.on('init', () => {
done();
});
proxy.init();
proxy.init();
});
});
describe('invalid bucket', () => {
let proxy;
beforeEach(() => {
proxy = new S3Proxy({ bucket: '.Bucket.name.cannot.start.with.a.period' });
});
it('should return NotFound error via callback', (done) => {
proxy.init((error) => {
expect(error.code).to.equal('NotFound');
done();
});
});
});
it('should return NotFound error via event emitter', (done) => {
proxy.on('error', (error) => {
expect(error.code).to.equal('NotFound');
done();
});
proxy.init();
});
});
describe('createReadStream error codes', () => {
const proxy = new S3Proxy({ bucket: 'codeassist-repo' });
before((done) => {
proxy.init(done);
});
it('should return error code NoSuchKey for nonexistent key', (done) => {
const stream = proxy.createReadStream('small.txt');
stream.on('error', (error) => {
expect(error.code).to.equal('NoSuchKey');
done();
});
});
});
describe('createReadStream', () => {
const proxy = new S3Proxy({ bucket: 'codeassist-repo' });
const page = {};
before((done) => {
proxy.init();
const stream = proxy.createReadStream('index.html');
page.length = 0;
stream.on('data', (chunk) => {
page.length += chunk.length;
});
stream.on('httpHeaders', (statusCode, headers) => {
page.headers = headers;
page.statusCode = statusCode;
});
stream.on('end', () => {
done();
});
});
it('should have headers', () => {
expect(page.headers).to.have.keys(['accept-ranges', 'content-length', 'content-type', 'date', 'etag', 'last-modified', 'server', 'x-amz-id-2', 'x-amz-request-id']);
});
it('should have length of 58', () => {
expect(page.length).to.equal(58);
});
});
});
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