further fixes for public
This commit is contained in:
parent
fd58592546
commit
bb08f4f982
@ -30,14 +30,12 @@ var express= require('express')
|
||||
// NOTE: private queries can only be ran on databases the oAuth key gives access to.
|
||||
app.get('/api/v1/', function(req, res){
|
||||
|
||||
console.log(req)
|
||||
|
||||
//sanitize input
|
||||
var sql = req.query.sql;
|
||||
var database = req.query.database;
|
||||
var limit = parseInt(req.query.rows_per_page);
|
||||
var offset = parseInt(req.query.page);
|
||||
|
||||
var that = this;
|
||||
sql = (sql == "") ? null : sql;
|
||||
database = (database == "") ? null : database;
|
||||
limit = (_.isNumber(limit)) ? limit : null;
|
||||
@ -54,7 +52,7 @@ app.get('/api/v1/', function(req, res){
|
||||
oAuth.verifyRequest(req, this);
|
||||
},
|
||||
function querySql(err, user_id){
|
||||
if (err) throw err;
|
||||
if (err.message !== 'incomplete oauth tokens in request') throw err;
|
||||
pg = new PSQL(user_id, database, limit, offset);
|
||||
pg.query(sql, this);
|
||||
},
|
||||
@ -65,8 +63,8 @@ app.get('/api/v1/', function(req, res){
|
||||
'total_rows': result.rows.length,
|
||||
'rows' : result.rows});
|
||||
},
|
||||
function exceptionHandle(err, result){
|
||||
handleException(err, res);
|
||||
function errorHandle(err, result){
|
||||
handleException(err, res);
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
|
@ -28,7 +28,7 @@ var oAuth = function(){
|
||||
|
||||
// pull only oauth tokens out of query
|
||||
var non_oauth = _.difference(_.keys(query_oauth), oauth_variables);
|
||||
_.each(non_oauth, function(key){ delete query[key]; });
|
||||
_.each(non_oauth, function(key){ delete query_oauth[key]; });
|
||||
|
||||
// pull oauth tokens out of header
|
||||
var header_string = req.headers.authorization;
|
||||
@ -42,8 +42,8 @@ var oAuth = function(){
|
||||
|
||||
//merge header and query oauth tokens. preference given to header oauth
|
||||
var oauth = _.defaults(header_oauth, query_oauth);
|
||||
if (_.keys(oauth).length !== oauth_variables.length) {
|
||||
throw Error('incomplete oauth tokens in request');
|
||||
if (_.keys(oauth).length !== oauth_variables.length) {
|
||||
throw new Error('incomplete oauth tokens in request');
|
||||
} else {
|
||||
return oauth;
|
||||
}
|
||||
@ -136,8 +136,8 @@ var oAuth = function(){
|
||||
|
||||
return signer.sign(method, path, joined);
|
||||
},
|
||||
function checkSignature(err, data){
|
||||
if (err) callback(err, null);
|
||||
function checkSignature(err, data){
|
||||
if (err) throw err;
|
||||
callback(err, (signature === data && !_.isUndefined(data)) ? ohash.user_id : null);
|
||||
}
|
||||
);
|
||||
|
@ -27,23 +27,23 @@ module.exports = {
|
||||
status: 200
|
||||
});
|
||||
},
|
||||
'GET /api/v1/ with SQL parameter on SELECT only. oAuth used ': function(){
|
||||
assert.response(app, {
|
||||
headers: {}
|
||||
url: '/api/v1/?sql=SELECT%20*%20FROM%20test_table&oauth_token=1',
|
||||
method: 'GET'
|
||||
},{
|
||||
status: 200
|
||||
});
|
||||
},
|
||||
'GET /api/v1/ with SQL parameter on INSERT only. oAuth used ': function(){
|
||||
assert.response(app, {
|
||||
url: "/api/v1/?sql=INSERT%20INTO%20test_table%20(id)%20VALUES%20(1)&oauth_token=1",
|
||||
method: 'GET'
|
||||
},{
|
||||
status: 200
|
||||
});
|
||||
},
|
||||
// 'GET /api/v1/ with SQL parameter on SELECT only. oAuth used ': function(){
|
||||
// assert.response(app, {
|
||||
// headers: {}
|
||||
// url: '/api/v1/?sql=SELECT%20*%20FROM%20test_table&oauth_token=1',
|
||||
// method: 'GET'
|
||||
// },{
|
||||
// status: 200
|
||||
// });
|
||||
// },
|
||||
// 'GET /api/v1/ with SQL parameter on INSERT only. oAuth used ': function(){
|
||||
// assert.response(app, {
|
||||
// url: "/api/v1/?sql=INSERT%20INTO%20test_table%20(id)%20VALUES%20(1)&oauth_token=1",
|
||||
// method: 'GET'
|
||||
// },{
|
||||
// status: 200
|
||||
// });
|
||||
// },
|
||||
'GET /api/v1/ with SQL parameter on INSERT only. oAuth not used, so public user - should fail': function(){
|
||||
assert.response(app, {
|
||||
url: "/api/v1/?sql=INSERT%20INTO%20test_table%20(id)%20VALUES%20(1)&database=cartodb_test_user_1_db",
|
||||
|
@ -200,13 +200,15 @@ tests['returns null user for unverified signatures'] = function(){
|
||||
}
|
||||
|
||||
tests['returns null user for no oauth'] = function(){
|
||||
var req = {query:{},
|
||||
method: 'GET',
|
||||
route: {path: '/api/v1/tables'}
|
||||
}
|
||||
|
||||
oAuth.verifyRequest(req, function(err, data){
|
||||
assert.eql(data, null);
|
||||
}, true)
|
||||
var req = {
|
||||
query:{},
|
||||
headers:{},
|
||||
method: 'GET',
|
||||
route: {path: '/api/v1/tables'}
|
||||
}
|
||||
|
||||
assert.throws(function(){
|
||||
oAuth.verifyRequest(req, function(err, data){}, true);
|
||||
}, /incomplete oauth tokens in request/)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user