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

express-interceptor

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-interceptor - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

tests/multibyte_characters.test.js

6

index.js

@@ -35,3 +35,3 @@ function validateParams(methods){

if(chunk){
chunks.push(chunk.toString(typeof encoding === 'string' ? encoding : 'utf-8'));
chunks.push(chunk);
}

@@ -63,6 +63,6 @@ if(typeof cb === 'function'){

debug('end called');
var args = Array.prototype.slice.call(arguments, 1);
var args = Array.prototype.slice.call(arguments);
if( intercept(chunk,encoding) ){
isIntercepting = false;
var oldBody = chunks.join('');
var oldBody = Buffer.concat(chunks).toString('utf-8');
if (methods.intercept){

@@ -69,0 +69,0 @@ if(typeof methods.intercept !== 'function'){

{
"name": "express-interceptor",
"version": "1.0.1",
"version": "1.1.0",
"description": "A tiny interceptor for Express responses",

@@ -44,9 +44,11 @@ "main": "index.js",

"devDependencies": {
"chai": "^2.3.0",
"cheerio": "^0.19.0",
"express": "^4.12.4",
"jade": "^1.10.0",
"magicpen-media": "1.5.0",
"messy": "6.5.0",
"mocha": "^2.2.5",
"morgan": "^1.5.3",
"supertest": "^1.0.1"
"unexpected": "9.2.1",
"unexpected-express": "7.3.0",
"unexpected-messy": "4.6.0"
},

@@ -53,0 +55,0 @@ "dependencies": {

@@ -84,3 +84,3 @@ # express-interceptor

See [more examples](https://github.com/axiomzen/express-interceptor/tree/master/examples).
See [more examples](https://github.com/axiomzen/express-interceptor/tree/master/examples). Also, you can debug express-interceptor actions using [debug](https://github.com/visionmedia/debug) env variable `DEBUG=express-interceptor`.

@@ -87,0 +87,0 @@ ## API

@@ -1,6 +0,12 @@

var request = require('supertest');
var expect = require('chai').expect;
var fs = require('fs');
var app = require('../examples/afterSend');
var expect = require('unexpected')
.clone()
.installPlugin(require('unexpected-express'))
.addAssertion('to yield response', function (expect, subject, value) {
return expect(app, 'to yield exchange', {
request: subject,
response: value
});
});

@@ -21,14 +27,10 @@ function cleanupLog(done){

it('should intercept the generated .html and respond with the same .html', function(done) {
request(app)
.get('/README.md')
.expect(200)
.end(done);
it('should intercept the generated .html and respond with the same .html', function() {
return expect('/README.md', 'to yield response', 200);
});
it('verify log file exist', function(done) {
fs.exists('body.log', function(exist) {
expect(exist).to.equal(true);
done();
});
it('verify log file exist', function() {
return expect(function (cb) {
fs.open('body.log', 'r', cb);
}, 'to call the callback without error');
});

@@ -35,0 +37,0 @@

@@ -1,45 +0,48 @@

var request = require('supertest');
var expect = require('chai').expect;
var fs = require('fs');
var app = require('../examples/json');
var expect = require('unexpected')
.clone()
.installPlugin(require('unexpected-express'))
.addAssertion('to yield response', function (expect, subject, value) {
return expect(app, 'to yield exchange', {
request: subject,
response: value
});
});
describe('JSON wrapping a response', function() {
it('should get a .json file and respond with a .json wraping that file', function(done) {
request(app)
.get('/package.json')
.expect(200)
.end(function(err,res) {
expect(res.headers['content-type']).to.equal('application/json');
var package_json = fs.readFileSync(__dirname + '/../package.json');
expect(res.body.json).to.equal(package_json.toString('utf8'));
done(err);
});
it('should get a .json file and respond with a .json wraping that file', function() {
return expect('/package.json', 'to yield response', {
headers: {
'Content-Type': 'application/json'
},
body: {
json: fs.readFileSync(__dirname + '/../package.json', 'utf-8')
}
});
});
it('should get a .html file and respond with a .json wraping that file', function(done) {
request(app)
.get('/examples/static/index.html')
.expect(200)
.end(function(err,res) {
expect(res.headers['content-type']).to.equal('application/json');
var index = fs.readFileSync(__dirname + '/../examples/static/index.html');
expect(res.body.json).to.equal(index.toString('utf8'));
done(err);
});
it('should get a .html file and respond with a .json wraping that file', function() {
return expect('/examples/static/index.html', 'to yield response', {
headers: {
'Content-Type': 'application/json'
},
body: {
json: fs.readFileSync(__dirname + '/../examples/static/index.html', 'utf-8')
}
});
});
it('should get a .md file and respond with a .json wraping that file', function(done) {
request(app)
.get('/README.md')
.expect(200)
.end(function(err,res) {
expect(res.headers['content-type']).to.equal('application/json');
var readme = fs.readFileSync(__dirname + '/../README.md');
expect(res.body.json).to.equal(readme.toString('utf8'));
done(err);
});
it('should get a .md file and respond with a .json wraping that file', function() {
return expect('/README.md', 'to yield response', {
headers: {
'Content-Type': 'application/json'
},
body: {
json: fs.readFileSync(__dirname + '/../README.md', 'utf-8')
}
});
});
});

@@ -1,62 +0,51 @@

var request = require('supertest');
var expect = require('chai').expect;
var fs = require('fs');
var app = require('../examples/mirror');
var fs = require('fs');
var expect = require('unexpected')
.clone()
.installPlugin(require('unexpected-express'))
.addAssertion('to yield response', function (expect, subject, value) {
return expect(app, 'to yield exchange', {
request: subject,
response: value
});
})
.addAssertion('to mirror the file on disk', function (expect, subject) {
var fileName = subject.replace(/^\//, '');
var pathToFileOnDisk = require('path').resolve(__dirname, '..', fileName);
var fileContent = fs.readFileSync(pathToFileOnDisk, 'utf-8')
if (/\.json$/.test(fileName)) {
fileContent = JSON.parse(fileContent);
}
return expect(app, 'to yield exchange', {
request: subject,
response: {
body: fileContent
}
});
});
describe('Mirroring the response', function() {
it('should intercept a .json and respond with the same .json', function(done) {
request(app)
.get('/package.json')
.expect(200)
.end(function(err, res) {
expect(res.body).to.deep.equal(require('../package.json'));
done(err);
});
it('should intercept a .json and respond with the same .json', function() {
return expect('/package.json', 'to mirror the file on disk');
});
it('should intercept a .html and respond with the same .html', function(done) {
request(app)
.get('/examples/static/index.html')
.expect(200)
.end(function(err, res) {
var index = fs.readFileSync(__dirname + '/../examples/static/index.html');
expect(res.text).to.equal(index.toString('utf8'));
done(err);
});
it('should intercept a .html and respond with the same .html', function() {
return expect('/examples/static/index.html', 'to mirror the file on disk');
});
it('should intercept a .md and respond with the same .md', function(done) {
request(app)
.get('/README.md')
.expect(200)
.end(function(err, res) {
var readme = fs.readFileSync(__dirname + '/../README.md');
expect(res.text).to.equal(readme.toString('utf8'));
done(err);
});
it('should intercept a .md and respond with the same .md', function() {
return expect('/README.md', 'to mirror the file on disk');
});
it('should intercept a .js and respond with the same .js', function(done) {
request(app)
.get('/index.js')
.expect(200)
.end(function(err, res) {
var index = fs.readFileSync(__dirname + '/../index.js');
expect(res.text).to.equal(index.toString('utf8'));
done(err);
});
it('should intercept a .js and respond with the same .js', function() {
return expect('/index.js', 'to mirror the file on disk');
});
it('should intercept 404 and respond with the same 404', function(done) {
request(app)
.get('/not-here.json')
.expect(404)
.end(function(err, res) {
expect(res.text).to.equal('Cannot GET /not-here.json\n');
done(err);
});
it('should intercept 404 and respond with the same 404', function() {
return expect('/not-here.json', 'to yield response', 404);
});
});

@@ -1,42 +0,33 @@

var request = require('supertest');
var expect = require('chai').expect;
var fs = require('fs');
var fs = require('fs');
var app = require('../examples/modify_html');
var expect = require('unexpected')
.clone()
.installPlugin(require('unexpected-express'))
.addAssertion('to yield response', function (expect, subject, value) {
return expect(app, 'to yield exchange', {
request: subject,
response: value
});
});
describe('Expecting only html responses', function() {
it('should intercept the generated .html (after template engine) and respond with a modified html', function(done) {
request(app)
.get('/index')
.expect(200)
.end(function(err, res) {
var index = '<html><head></head><body><p>&quot;Hello world&quot; from interceptor!</p></body></html>';
expect(res.text).to.equal(index);
done(err);
});
it('should intercept the generated .html (after template engine) and respond with a modified html', function() {
var index = '<html><head></head><body><p>&quot;Hello world&quot; from interceptor!</p></body></html>';
return expect('/index', 'to yield response', index);
});
it('should intercept the .html (from a static file) and respond with a modified html', function(done) {
request(app)
.get('/')
.expect(200)
.end(function(err, res) {
var index = '<html><head></head><body><p>&quot;Hello world&quot; from interceptor!</p></body></html>';
expect(res.text).to.equal(index);
done(err);
});
it('should intercept the .html (from a static file) and respond with a modified html', function() {
var index = '<html><head></head><body><p>&quot;Hello world&quot; from interceptor!</p></body></html>';
return expect('/index', 'to yield response', index);
});
it('should intercept the .json (from a static file) and return it without modification', function(done) {
request(app)
.get('/index.json')
.expect(200)
.end(function(err, res) {
var indexJson = fs.readFileSync(__dirname + '/../examples/static/index.json');
expect(res.text).to.equal(indexJson.toString('utf8'));
done(err);
});
it('should intercept the .json (from a static file) and return it without modification', function() {
var indexJson = fs.readFileSync(__dirname + '/../examples/static/index.json', 'utf-8');
return expect('/index.json', 'to yield response', {
body: JSON.parse(indexJson)
});
});
});

@@ -1,17 +0,17 @@

var request = require('supertest');
var expect = require('chai').expect;
var fs = require('fs');
var app = require('../examples/template_engine');
var expect = require('unexpected')
.clone()
.installPlugin(require('unexpected-express'))
.addAssertion('to yield response', function (expect, subject, value) {
return expect(app, 'to yield exchange', {
request: subject,
response: value
});
});
describe('Using a template engine (Jade)', function() {
it('should intercept the generated .html and respond with the same .html', function(done) {
request(app)
.get('/index')
.expect(200)
.end(function(err, res) {
var hack = '<script>alert("you were intercepted!")</script>';
expect(res.text).to.contain(hack);
done(err);
it('should intercept the generated .html and respond with the same .html', function() {
return expect('/index', 'to yield response', {
body: expect.it('to contain', '<script>alert("you were intercepted!")</script>')
});

@@ -18,0 +18,0 @@ });

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