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

echoecho

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

echoecho - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

Makefile

17

lib/scheme.js

@@ -18,4 +18,9 @@ /*

exports.status = function (code, res) {
var body = http.STATUS_CODES[code] || 'unknown';
var body = http.STATUS_CODES[code];
if (!body) {
code = 500;
body = 'Unknown Echo Status';
}
res.writeHead(code, 'HTTP/1.1 ' + body, headers);

@@ -28,3 +33,3 @@ res.end(body);

code = ((req.method === 'GET' || req.method === 'HEAD' || req.method === 'OPTIONS') ? 200 : 403);
res.writeHead(code, headers);

@@ -108,3 +113,3 @@ res.end(p.query || '');

json = (p.query ? JSON.stringify(qs.parse(p.query)) : '{ "echo": true }');
if (req.body) {

@@ -135,2 +140,6 @@ json = JSON.stringify(req.body);

query = req.body;
if (query.callback) {
callback = query.callback;
delete query.callback;
}
}

@@ -145,3 +154,3 @@

code = 403;
json = JSON.stringify('{ "echo": "error, no callback" }');
json = JSON.stringify({ "echo": "error, no callback" });
} else {

@@ -148,0 +157,0 @@ json = callback + '(' + JSON.stringify(content) + ');';

@@ -5,11 +5,12 @@ {

"author": "Dav Glass <davglass@gmail.com>",
"version": "0.0.6",
"version": "0.0.7",
"devDependencies": {
"vows": "*",
"yui-lint": "~0.1.1",
"jshint": "~0.9.0"
"jshint": "~0.9.0",
"istanbul": "*"
},
"scripts": {
"pretest": "jshint --config ./node_modules/yui-lint/jshint.json ./lib/*.js",
"test": "vows --spec ./tests/*.js"
"test": "istanbul test vows -- --spec ./tests/*.js"
},

@@ -16,0 +17,0 @@ "main": "./lib/echo.js",

@@ -21,2 +21,4 @@ EchoEcho

[Code Coverage Report](http://davglass.github.com/echoecho/)
Default Routes

@@ -23,0 +25,0 @@ --------------

@@ -11,7 +11,16 @@ var vows = require('vows'),

var server = http.createServer(function(req, res) {
if (echoecho.handle(req)) {
if (req.url.indexOf('-express') > -1) {
var p = parse(req.url);
req.url = req.url.replace('-express', '');
req.body = qs.parse(p.query);
echoecho.serve(req, res);
} else if (echoecho.handle(req)) {
echoecho.serve(req, res);
} else {
res.writeHead(200);
res.end('DEFAULT');
if (req.url.indexOf('skipthisrequest') > -1) {
echoecho.serve(req, res);
} else {
res.writeHead(200);
res.end('DEFAULT');
}
}

@@ -145,2 +154,50 @@ });

},
"and get status asdf": {
topic: function() {
fetch({
method: 'GET',
path: '/foo/bar/baz/echo/status/asdf'
}, this.callback);
},
"with Not Found body": function(topic) {
assert.equal(topic.code, 500);
assert.equal(topic.body, 'Unknown Echo Status');
}
},
"and get unknown scheme route": {
topic: function() {
fetch({
method: 'GET',
path: '/foo/bar/baz/echo/asdfasdf'
}, this.callback);
},
"with Not Found body": function(topic) {
assert.equal(topic.code, 404);
assert.equal(topic.body, 'Not Found');
}
},
"and get no scheme route": {
topic: function() {
fetch({
method: 'GET',
path: '/foo/bar/baz/echo/'
}, this.callback);
},
"with Not Found body": function(topic) {
assert.equal(topic.code, 404);
assert.equal(topic.body, 'Not Found');
}
},
"and get unknown scheme route that is unhandled": {
topic: function() {
fetch({
method: 'GET',
path: '/foo/bar/baz/echo/skipthisrequest'
}, this.callback);
},
"with Not Found body": function(topic) {
assert.equal(topic.code, 404);
assert.equal(topic.body, 'Not Found');
}
},
"and get query": {

@@ -158,2 +215,14 @@ topic: function() {

},
"and get no query": {
topic: function() {
fetch({
method: 'GET',
path: '/foo/bar/baz/echo/get'
}, this.callback);
},
"with query body": function(topic) {
assert.equal(topic.code, 200);
assert.equal(topic.body, '');
}
},
"and get mismatch": {

@@ -209,2 +278,14 @@ topic: function() {

},
"and delete with no query": {
topic: function() {
fetch({
method: 'DELETE',
path: '/foo/bar/baz/echo/delete'
}, this.callback);
},
"with query body": function(topic) {
assert.equal(topic.code, 200);
assert.equal(topic.body, '');
}
},
"and delete mismatch": {

@@ -295,10 +376,12 @@ topic: function() {

var self = this,
url = '/foo/bar/baz/echo/json?foo=bar&baz=world&do=not';
body = 'foo=bar&baz=world&do=not',
url = '/foo/bar/baz/echo/json?' + body;
fetch({
method: 'POST',
path: url
path: url,
body: body
}, function(err, data) {
var q = parse(url);
data.expected = JSON.stringify(qs.parse(q.query));
data.expected = JSON.stringify(qs.parse(body));
self.callback(err, data);

@@ -313,2 +396,24 @@ });

},
"and post custom json, express style": {
topic: function() {
var self = this,
body = 'foo=bar&baz=world&do=not',
url = '/foo/bar/baz/echo/json-express?' + body;
fetch({
method: 'POST',
path: url,
body: body
}, function(err, data) {
var q = parse(url);
data.expected = JSON.stringify(qs.parse(body));
self.callback(err, data);
});
},
"with query body": function(topic) {
assert.equal(topic.code, 200);
assert.equal(topic.headers['content-type'], 'application/json');
assert.equal(topic.body, topic.expected);
}
},
"and get default jsonp": {

@@ -326,2 +431,15 @@ topic: function() {

},
"and get default jsonp without callback": {
topic: function() {
fetch({
method: 'GET',
path: '/foo/bar/baz/echo/jsonp?baz'
}, this.callback);
},
"with query body": function(topic) {
assert.equal(topic.code, 403);
var b = JSON.parse(topic.body);
assert.equal(b.echo, 'error, no callback');
}
},
"and post default jsonp": {

@@ -385,2 +503,44 @@ topic: function() {

},
"and post custom jsonp, express style": {
topic: function() {
var self = this,
body = 'callback=yoyo&foo=bar&baz=world&do=not',
url = '/foo/bar/baz/echo/jsonp-express?' + body;
fetch({
method: 'POST',
path: url
}, function(err, data) {
var q = parse(url);
var payload = qs.parse(body);
var callback = payload.callback;
delete payload.callback;
data.expected = callback + '(' + JSON.stringify(payload) + ');';
self.callback(err, data);
});
},
"with query body": function(topic) {
assert.equal(topic.code, 200);
assert.equal(topic.headers['content-type'], 'application/json');
assert.equal(topic.body, topic.expected);
}
},
"and post custom jsonp, express style without callback": {
topic: function() {
var self = this,
body = 'foo=bar&baz=world&do=not',
url = '/foo/bar/baz/echo/jsonp-express?' + body;
fetch({
method: 'POST',
path: url
}, this.callback);
},
"with query body": function(topic) {
assert.equal(topic.code, 403);
assert.equal(topic.code, 403);
var b = JSON.parse(topic.body);
assert.equal(b.echo, 'error, no callback');
}
},
"and delay 3 seconds": {

@@ -402,2 +562,56 @@ topic: function() {

Object.keys(http.STATUS_CODES).forEach(function(code) {
var s = http.STATUS_CODES[code],
c = Number(code, 10);
if (c < 200) {
return;
}
var test = {
topic: function() {
fetch({
method: 'GET',
path: '/foo/bar/baz/echo/status/' + code
}, this.callback);
}
};
test["with " + s + " body"] = function(topic) {
assert.equal(topic.code, code);
assert.equal(topic.body, s);
};
tests["should be loaded"]['and should load paths']["get status " + code] = test;
});
tests["should be loaded"]['and should load paths']["should load custom scheme"] = {
topic: function() {
this.count = Object.keys(echoecho.scheme);
echoecho.load({
'davglass': function(req, res) {
res.writeHead(200, echoecho.scheme.headers);
res.end('DAVGLASS WAS HERE');
}
});
return echoecho;
},
"should have a new scheme": function(topic) {
assert.notEqual(this.count, Object.keys(echoecho.scheme));
assert.equal(this.count.length + 1, Object.keys(echoecho.scheme).length);
},
"and should use new scheme": {
topic: function() {
fetch({
method: 'GET',
path: '/foo/bar/baz/echo/davglass'
}, this.callback);
},
"custom scheme should respond": function(topic) {
assert.equal(topic.body, 'DAVGLASS WAS HERE');
}
}
};
vows.describe('echoecho').addBatch(tests).export(module);

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