From 414f4b6c3e6ac33f11813477e5f87413437ce215 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Mon, 6 May 2013 18:21:22 +0200 Subject: [PATCH] Do not request caching of TRUNCATE queries --- NEWS.md | 1 + app/controllers/app.js | 2 +- test/acceptance/app.test.js | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 59d9844f..a6b942dc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ 1.3.9 ----- * Do not choke on multiple `skipfields` parameter +* Do not request caching of TRUNCATE queries 1.3.8 ----- diff --git a/app/controllers/app.js b/app/controllers/app.js index b390bd08..aeceeb14 100755 --- a/app/controllers/app.js +++ b/app/controllers/app.js @@ -63,7 +63,7 @@ app.get('/api/v1/cachestatus', function(req, res) { handleCacheStatus(req, res) // function queryMayWrite(sql) { var mayWrite = false; - var pattern = RegExp("(alter|insert|update|delete|create|drop)", "i"); + var pattern = RegExp("(alter|insert|update|delete|create|drop|truncate)", "i"); if ( pattern.test(sql) ) { mayWrite = true; } diff --git a/test/acceptance/app.test.js b/test/acceptance/app.test.js index 3c07b475..1b60dfa9 100644 --- a/test/acceptance/app.test.js +++ b/test/acceptance/app.test.js @@ -445,6 +445,39 @@ test('multistatement insert, alter, select, begin, commit', function(done){ }); }); +test('TRUNCATE TABLE with GET and auth', function(done){ + assert.response(app, { + url: "/api/v1/sql?" + querystring.stringify({ + q: 'TRUNCATE TABLE test_table', + api_key: 1234 + }), + headers: {host: 'vizzuality.cartodb.com'}, + method: 'GET' + },{}, function(res) { + assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); + assert.equal(res.headers['x-cache-channel'], 'NONE'); + assert.equal(res.headers['cache-control'], expected_cache_control); + var pbody = JSON.parse(res.body); + assert.equal(pbody.rows.length, 0); + assert.response(app, { + url: "/api/v1/sql?" + querystring.stringify({ + q: 'SELECT count(*) FROM test_table', + api_key: 1234 + }), + headers: {host: 'vizzuality.cartodb.com'}, + method: 'GET' + },{}, function(res) { + assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body); + assert.equal(res.headers['x-cache-channel'], 'cartodb_test_user_1_db:test_table'); + assert.equal(res.headers['cache-control'], expected_cache_control); + var pbody = JSON.parse(res.body); + assert.equal(pbody.total_rows, 1); + assert.equal(pbody.rows[0]['count'], 0); + done(); + }); + }); +}); + test('DROP TABLE with GET and auth', function(done){ assert.response(app, { url: "/api/v1/sql?" + querystring.stringify({