Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix for handling duplicate routes with different query params #291

Merged
merged 4 commits into from
Feb 22, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Feb 21, 2012
* Bug fix for https://github.com/ql-io/ql.io/issues/286 for 0.3

## Feb 14, 2012
* XSS issue for 404 response fixed.

Expand Down
14 changes: 10 additions & 4 deletions modules/console/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,16 @@ var Console = module.exports = function(config) {
collectHttpQueryParams(req, holder, false);

// find a route (i.e. associated cooked script)
var route = _.detect(verbRouteVariants, function(verbRouteVariant) {
return _.isEqual(_.intersection(_.keys(holder.params), _.keys(verbRouteVariant.query)),
_.keys(verbRouteVariant.query));
});
var route = _(verbRouteVariants).chain()
.filter(function (verbRouteVariant) {
return _.isEqual(_.intersection(_.keys(holder.params), _.keys(verbRouteVariant.query)),
_.keys(verbRouteVariant.query))
})
.reduce(function (match, route) {
return match == null ?
route : route.length > match.length ? route : match;
}, null)
.value();

if (!route) {
res.writeHead(400, 'Bad input', {
Expand Down
2 changes: 1 addition & 1 deletion modules/console/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "ql.io",
"name": "ql.io-console",
"version": "0.3.6",
"version": "0.3.7",
"repository": {
"type": "git",
"url": "https://github.com/ql-io/ql.io"
Expand Down
13 changes: 13 additions & 0 deletions modules/console/test/routes/a-useritems-withDelete.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- Type ql script here - all keywords must be in lower case
item = select * from ebay.shopping.singleitem where itemId = '260852758792';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need all these statements in the test script?

profile = select * from ebay.shopping.userprofile where includeSelector = "{selector}" and userId = "260852758792";
tradingItem = select * from ebay.trading.getitem where itemId = '260852758792';
bidders = select * from ebay.trading.getallbidders where itemId = '260852758792';
bestOffers = select * from ebay.trading.bestoffers where itemId = '260852758792';
return {
"user" : "{profile}",
"item" : "{item}",
"tradingItem" : "{tradingItem}",
"bidders" : "{bidders}",
"bestOffers" : "{bestOffers}"
} via route "/del/foo/bar/{selector}?userid={userId}" using method delete;
49 changes: 48 additions & 1 deletion modules/console/test/test-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var _ = require('underscore'),
url = require('url');

module.exports = {
'check delete call' : function(test) {
'check delete /del/foo/bar/{selector}?userid={userId}&itemid={itemId}' : function(test) {
var c = new Console({
tables : __dirname + '/tables',
routes : __dirname + '/routes/',
Expand Down Expand Up @@ -71,6 +71,53 @@ module.exports = {
});
})
},
'check delete /del/foo/bar/{selector}?userid={userId}' : function(test) {
var c = new Console({
tables : __dirname + '/tables',
routes : __dirname + '/routes/',
config : __dirname + '/config/dev.json',
'enable console' : false,
connection : 'close'
});
c.app.listen(3000, function() {
var testHttpapp = express.createServer();
testHttpapp.post('/ping/pong', function(req, res) {
var data = '';
req.on('data', function(chunk) {
data += chunk;
});
req.on('end', function() {
res.send(data);
});
});

testHttpapp.listen(80126, function() {
var options = {
host : 'localhost',
port : 3000,
path : '/del/foo/bar/Details?userid=sallamar',
method : 'DELETE'
};
var req = http.request(options);
req.addListener('response', function(resp) {
var data = '';
resp.addListener('data', function(chunk) {
data += chunk;
});
resp.addListener('end', function() {
var json = JSON.parse(data);
test.ok(json.user, 'missing user data');
test.ok(json.user.Ack, 'missing user Ack');
test.equal(json.user.Ack, 'Success');
c.app.close();
testHttpapp.close();
test.done();
});
});
req.end();
});
})
},
'check post json call' : function(test) {
var c = new Console({
tables : __dirname + '/tables',
Expand Down