2012-07-09 22:49:31 +08:00
|
|
|
var assert = require('../support/assert');
|
2011-09-05 07:00:41 +08:00
|
|
|
var tests = module.exports = {};
|
|
|
|
var _ = require('underscore');
|
|
|
|
var querystring = require('querystring');
|
2012-07-18 17:00:24 +08:00
|
|
|
require(__dirname + '/../support/test_helper');
|
2011-09-05 07:00:41 +08:00
|
|
|
|
2011-10-13 19:17:00 +08:00
|
|
|
var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/cartodb_windshaft');
|
2012-07-10 01:20:49 +08:00
|
|
|
var serverOptions = require(__dirname + '/../../lib/cartodb/server_options');
|
2011-10-13 19:17:00 +08:00
|
|
|
var server = new CartodbWindshaft(serverOptions);
|
2012-07-10 03:06:45 +08:00
|
|
|
server.setMaxListeners(0);
|
2011-09-05 07:00:41 +08:00
|
|
|
|
2012-07-09 22:49:31 +08:00
|
|
|
suite('server', function() {
|
2012-08-14 21:06:04 +08:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// GET UNSUPPORTED
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2012-07-09 22:49:31 +08:00
|
|
|
|
2012-08-14 21:13:23 +08:00
|
|
|
// TODO: I guess this should be a 404 instead...
|
2012-07-09 22:49:31 +08:00
|
|
|
test("get call to server returns 200", function(done){
|
|
|
|
assert.response(server, {
|
|
|
|
url: '/',
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
status: 200
|
|
|
|
}, function() { done(); });
|
|
|
|
});
|
2012-08-14 21:06:04 +08:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// GET STYLE
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2012-07-09 22:49:31 +08:00
|
|
|
|
|
|
|
test("get'ing blank style returns default style", function(done){
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/my_table/style',
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
status: 200,
|
|
|
|
body: '{"style":"#my_table {marker-fill: #FF6600;marker-opacity: 1;marker-width: 8;marker-line-color: white;marker-line-width: 3;marker-line-opacity: 0.9;marker-placement: point;marker-type: ellipse;marker-allow-overlap: true;}"}'
|
|
|
|
}, function() { done(); });
|
|
|
|
});
|
2012-08-14 21:06:04 +08:00
|
|
|
|
2012-08-15 01:26:40 +08:00
|
|
|
// See https://github.com/Vizzuality/Windshaft-cartodb/issues/43
|
2012-08-14 21:32:36 +08:00
|
|
|
test("get'ing style of private table should fail when unauthenticated",
|
|
|
|
function(done) {
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/test_table_private_1/style',
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
}, function(res) {
|
2012-09-06 02:16:55 +08:00
|
|
|
// FIXME: should be 401 Unauthorized
|
2012-08-14 21:32:36 +08:00
|
|
|
assert.equal(res.statusCode, 500, res.body);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("get'ing style of private table should succeed when authenticated",
|
|
|
|
function(done) {
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/test_table_private_1/style?map_key=1234',
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
}, function(res) {
|
|
|
|
assert.equal(res.statusCode, 200, res.body);
|
|
|
|
assert.deepEqual(res.body, '{"style":"#test_table_private_1 {marker-fill: #FF6600;marker-opacity: 1;marker-width: 8;marker-line-color: white;marker-line-width: 3;marker-line-opacity: 0.9;marker-placement: point;marker-type: ellipse;marker-allow-overlap: true;}"}');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-08-14 21:06:04 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// POST STYLE
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2012-07-09 22:49:31 +08:00
|
|
|
|
|
|
|
test("post'ing no style returns 400 with errors", function(done){
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/my_table/style',
|
|
|
|
method: 'POST'
|
|
|
|
},{
|
|
|
|
status: 400,
|
|
|
|
body: '{"error":"must send style information"}'
|
|
|
|
}, function() { done(); });
|
|
|
|
});
|
|
|
|
|
|
|
|
test("post'ing bad style returns 400 with error", function(done){
|
|
|
|
assert.response(server, {
|
2012-08-14 22:15:41 +08:00
|
|
|
url: '/tiles/my_table3/style?map_key=1234',
|
2012-07-09 22:49:31 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: {host: 'vizzuality.localhost.lan', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
data: querystring.stringify({style: '#my_table3{backgxxxxxround-color:#fff;}'})
|
|
|
|
},{
|
2012-09-06 02:16:55 +08:00
|
|
|
status: 500, // FIXME: should be 400 !
|
2012-07-09 22:49:31 +08:00
|
|
|
body: JSON.stringify(['style.mss:1:11 Unrecognized rule: backgxxxxxround-color'])
|
|
|
|
}, function() { done(); });
|
|
|
|
});
|
|
|
|
|
|
|
|
test("post'ing multiple bad styles returns 400 with error array", function(done){
|
|
|
|
assert.response(server, {
|
2012-08-14 22:15:41 +08:00
|
|
|
url: '/tiles/my_table4/style?map_key=1234',
|
2012-07-09 22:49:31 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: {host: 'vizzuality.localhost.lan', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
data: querystring.stringify({style: '#my_table4{backgxxxxxround-color:#fff;foo:bar}'})
|
|
|
|
},{
|
2012-09-06 02:16:55 +08:00
|
|
|
status: 500, // FIXME: should be 400 !
|
2012-07-09 22:49:31 +08:00
|
|
|
body: JSON.stringify([ 'style.mss:1:11 Unrecognized rule: backgxxxxxround-color', 'style.mss:1:38 Unrecognized rule: foo' ])
|
|
|
|
}, function() { done(); });
|
|
|
|
});
|
2012-08-07 23:10:15 +08:00
|
|
|
|
2012-07-09 22:49:31 +08:00
|
|
|
test("post'ing good style returns 200", function(done){
|
|
|
|
assert.response(server, {
|
2012-08-07 23:10:15 +08:00
|
|
|
url: '/tiles/my_table5/style?map_key=1234',
|
2012-07-09 22:49:31 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: {host: 'vizzuality.localhost.lan', 'Content-Type': 'application/x-www-form-urlencoded' },
|
2012-07-10 03:06:45 +08:00
|
|
|
data: querystring.stringify({style: 'Map {background-color:#fff;}'})
|
2012-07-09 22:49:31 +08:00
|
|
|
},{
|
2012-07-10 03:06:45 +08:00
|
|
|
}, function(res) {
|
|
|
|
assert.equal(res.statusCode, 200, res.body);
|
|
|
|
done();
|
|
|
|
});
|
2012-07-09 22:49:31 +08:00
|
|
|
});
|
2012-08-07 23:10:15 +08:00
|
|
|
|
|
|
|
test("post'ing good style with no authentication returns an error", function(done){
|
|
|
|
assert.response(server, {
|
|
|
|
url: '/tiles/my_table5/style',
|
|
|
|
method: 'POST',
|
|
|
|
headers: {host: 'vizzuality.localhost.lan', 'Content-Type': 'application/x-www-form-urlencoded' },
|
2012-08-14 22:15:41 +08:00
|
|
|
data: querystring.stringify({style: 'Map {background-color:#aaa;}'})
|
2012-08-07 23:10:15 +08:00
|
|
|
},{}, function(res) {
|
2012-09-06 02:16:55 +08:00
|
|
|
// FIXME: should be 401 Unauthorized
|
2012-08-07 23:10:15 +08:00
|
|
|
assert.equal(res.statusCode, 500, res.body);
|
2012-08-14 22:15:41 +08:00
|
|
|
assert.ok(res.body.indexOf('map state cannot be changed by unauthenticated request') != -1, res.body);
|
|
|
|
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/my_table5/style',
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
status: 200,
|
|
|
|
body: JSON.stringify({style: 'Map {background-color:#fff;}'})
|
|
|
|
}, function() { done(); });
|
|
|
|
|
2012-08-07 23:10:15 +08:00
|
|
|
});
|
|
|
|
});
|
2012-07-10 03:06:45 +08:00
|
|
|
|
2012-07-09 22:49:31 +08:00
|
|
|
test("post'ing good style returns 200 then getting returns original style", function(done){
|
2012-07-10 03:06:45 +08:00
|
|
|
var style = 'Map {background-color:#fff;}';
|
2012-07-09 22:49:31 +08:00
|
|
|
assert.response(server, {
|
2012-08-07 23:10:15 +08:00
|
|
|
url: '/tiles/my_table5/style?map_key=1234',
|
2012-07-09 22:49:31 +08:00
|
|
|
method: 'POST',
|
|
|
|
headers: {host: 'vizzuality.localhost.lan', 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
|
|
data: querystring.stringify({style: style})
|
|
|
|
},{
|
2012-07-10 03:06:45 +08:00
|
|
|
}, function(res) {
|
|
|
|
|
|
|
|
assert.equal(res.statusCode, 200, res.body);
|
2012-07-09 22:49:31 +08:00
|
|
|
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/my_table5/style',
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
status: 200,
|
|
|
|
body: JSON.stringify({style: style})
|
|
|
|
}, function() { done(); });
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2012-08-07 20:02:42 +08:00
|
|
|
|
2012-08-14 21:06:04 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// DELETE STYLE
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-08-07 23:10:15 +08:00
|
|
|
// Test that unauthenticated DELETE should fail
|
2012-08-07 20:02:42 +08:00
|
|
|
// See https://github.com/Vizzuality/cartodb-management/issues/155
|
2012-08-07 23:10:15 +08:00
|
|
|
test("delete'ing style with no authentication returns an error", function(done){
|
|
|
|
assert.response(server, {
|
|
|
|
url: '/tiles/my_table5/style',
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: {host: 'vizzuality'},
|
|
|
|
},{}, function(res) {
|
2012-09-06 02:16:55 +08:00
|
|
|
// FIXME: should be 401 Unauthorized
|
2012-08-07 23:10:15 +08:00
|
|
|
assert.equal(res.statusCode, 500, res.body);
|
2012-08-14 22:15:41 +08:00
|
|
|
assert.ok(res.body.indexOf('map state cannot be changed by unauthenticated request') != -1, res.body);
|
|
|
|
// check that the style wasn't really deleted !
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality'},
|
|
|
|
url: '/tiles/my_table5/style?map_key=1234',
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
status: 200,
|
|
|
|
body: JSON.stringify({style: 'Map {background-color:#fff;}'})
|
|
|
|
}, function() { done(); });
|
2012-08-07 23:10:15 +08:00
|
|
|
});
|
|
|
|
});
|
2012-08-07 20:02:42 +08:00
|
|
|
|
|
|
|
test("delete'ing style returns 200 then getting returns default style", function(done){
|
|
|
|
// this is the default style
|
|
|
|
var style = '#my_table5 {marker-fill: #FF6600;marker-opacity: 1;marker-width: 8;marker-line-color: white;marker-line-width: 3;marker-line-opacity: 0.9;marker-placement: point;marker-type: ellipse;marker-allow-overlap: true;}'
|
|
|
|
assert.response(server, {
|
|
|
|
url: '/tiles/my_table5/style?map_key=1234',
|
|
|
|
method: 'DELETE',
|
2012-08-07 23:10:15 +08:00
|
|
|
headers: {host: 'vizzuality'},
|
2012-08-07 20:02:42 +08:00
|
|
|
},{}, function(res) {
|
|
|
|
assert.equal(res.statusCode, 200, res.body);
|
|
|
|
|
|
|
|
// Retrive style with authenticated request
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'localhost'},
|
|
|
|
url: '/tiles/my_table5/style?map_key=1234',
|
|
|
|
method: 'GET'
|
|
|
|
},{}, function(res) {
|
|
|
|
assert.equal(res.statusCode, 200, res.body);
|
|
|
|
assert.deepEqual(JSON.parse(res.body).style, style);
|
|
|
|
|
|
|
|
// Now retrive style with unauthenticated request
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'localhost'},
|
|
|
|
url: '/tiles/my_table5/style',
|
|
|
|
method: 'GET'
|
|
|
|
}, {}, function(res) {
|
|
|
|
assert.equal(res.statusCode, 200, res.body);
|
|
|
|
assert.deepEqual(JSON.parse(res.body).style, style);
|
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2012-08-14 21:06:04 +08:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// GET INFOWINDOW
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
2012-07-09 22:49:31 +08:00
|
|
|
|
|
|
|
test("get'ing blank infowindow returns blank", function(done){
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/my_tablez/infowindow',
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
status: 200,
|
|
|
|
body: '{"infowindow":null}'
|
|
|
|
}, function() { done(); });
|
|
|
|
});
|
|
|
|
|
|
|
|
test("get'ing blank infowindow with callback returns blank with callback", function(done){
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/my_tablez/infowindow?callback=simon',
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
status: 200,
|
|
|
|
body: 'simon({"infowindow":null});'
|
|
|
|
}, function() { done(); });
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test("get'ing completed infowindow with callback returns information with callback", function(done){
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/my_table/infowindow?callback=simon',
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
status: 200,
|
|
|
|
body: 'simon({"infowindow":"this, that, the other"});'
|
|
|
|
}, function() { done(); });
|
|
|
|
});
|
2012-08-14 21:06:04 +08:00
|
|
|
|
2012-08-15 02:01:32 +08:00
|
|
|
test("get'ing infowindow of private table should fail when unauthenticated",
|
|
|
|
function(done) {
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/test_table_private_1/infowindow',
|
|
|
|
method: 'GET'
|
|
|
|
},{}, function(res) {
|
2012-09-06 02:16:55 +08:00
|
|
|
// FIXME: should be 401 Unauthorized
|
2012-08-15 02:01:32 +08:00
|
|
|
assert.equal(res.statusCode, 500, res.body);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("get'ing infowindow of private table should succeed when authenticated",
|
|
|
|
function(done) {
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/test_table_private_1/infowindow?map_key=1234',
|
|
|
|
method: 'GET'
|
|
|
|
},{}, function(res) {
|
|
|
|
assert.equal(res.statusCode, 200, res.body);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-08-14 21:06:04 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// GET GRID
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
test("get'ing a json with default style should return an grid", function(done){
|
2012-07-09 22:49:31 +08:00
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
2012-08-14 21:06:04 +08:00
|
|
|
url: '/tiles/gadm4/6/31/24.grid.json',
|
2012-07-09 22:49:31 +08:00
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
status: 200,
|
2012-08-14 21:06:04 +08:00
|
|
|
headers: { 'Content-Type': 'text/javascript; charset=utf-8; charset=utf-8' }
|
2012-07-09 22:49:31 +08:00
|
|
|
}, function() { done(); });
|
|
|
|
});
|
|
|
|
|
|
|
|
test("get'ing a json with default style should return an grid", function(done){
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/gadm4/6/31/24.grid.json',
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
status: 200,
|
|
|
|
headers: { 'Content-Type': 'text/javascript; charset=utf-8; charset=utf-8' }
|
|
|
|
}, function() { done(); });
|
|
|
|
});
|
|
|
|
|
|
|
|
test("get'ing a json with default style and sql should return a constrained grid", function(done){
|
|
|
|
var sql = querystring.stringify({sql: "SELECT * FROM gadm4 WHERE codineprov = '08'"})
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/gadm4/6/31/24.grid.json?' + sql,
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
status: 200,
|
|
|
|
headers: { 'Content-Type': 'text/javascript; charset=utf-8; charset=utf-8' }
|
|
|
|
}, function() { done(); });
|
|
|
|
});
|
2012-08-14 21:31:58 +08:00
|
|
|
|
|
|
|
test("get'ing the grid of a private table should fail when unauthenticated",
|
|
|
|
function(done) {
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/test_table_private_1/6/31/24.grid.json',
|
|
|
|
method: 'GET'
|
|
|
|
},{}, function(res) {
|
2012-09-06 02:16:55 +08:00
|
|
|
// 401 Unauthorized
|
|
|
|
assert.equal(res.statusCode, 401, res.statusCode + ': ' + res.body);
|
2012-08-14 21:31:58 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test("get'ing the grid of a private table should succeed when authenticated",
|
|
|
|
function(done) {
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/test_table_private_1/6/31/24.grid.json?map_key=1234',
|
|
|
|
method: 'GET'
|
|
|
|
},{}, function(res) {
|
|
|
|
assert.equal(res.statusCode, 200, res.body);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2012-07-09 22:49:31 +08:00
|
|
|
|
2012-08-14 21:06:04 +08:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// GET TILE
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
test("get'ing a tile with default style should return an image", function(done){
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/gadm4/6/31/24.png?geom_type=polygon',
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
status: 200,
|
|
|
|
headers: { 'Content-Type': 'image/png' }
|
|
|
|
}, function() { done(); });
|
|
|
|
});
|
2012-07-09 22:49:31 +08:00
|
|
|
|
|
|
|
test("get'ing a tile with default style and sql should return a constrained image", function(done){
|
|
|
|
var sql = querystring.stringify({sql: "SELECT * FROM gadm4 WHERE codineprov = '08'"});
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/gadm4/6/31/24.png?' + sql,
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
status: 200,
|
|
|
|
headers: { 'Content-Type': 'image/png' }
|
|
|
|
}, function() { done(); });
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test("get'ing a tile with default style and complex sql should return a constrained image", function(done){
|
|
|
|
var sql = querystring.stringify({sql: "SELECT * FROM gadm4 WHERE codineprov = '08' AND codccaa > 60"})
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/gadm4/6/31/24.png?' + sql,
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
status: 200,
|
|
|
|
headers: { 'Content-Type': 'image/png' }
|
|
|
|
}, function() { done(); });
|
|
|
|
});
|
2012-07-18 17:00:24 +08:00
|
|
|
|
|
|
|
test("get'ing a tile with data from private table should succeed when authenticated", function(done){
|
|
|
|
// NOTE: may fail if grainstore < 0.3.0 is used by Windshaft
|
|
|
|
var sql = querystring.stringify({sql: "SELECT * FROM test_table_private_1", map_key: 1234})
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
2012-08-14 21:31:58 +08:00
|
|
|
// NOTE: we encode a public table in the URL !
|
2012-07-18 17:00:24 +08:00
|
|
|
url: '/tiles/gadm4/6/31/24.png?' + sql,
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
|
|
|
status: 200,
|
|
|
|
headers: { 'Content-Type': 'image/png' }
|
|
|
|
}, function() { done(); });
|
|
|
|
});
|
|
|
|
|
|
|
|
test("get'ing a tile with data from private table should fail when unauthenticated", function(done){
|
|
|
|
var sql = querystring.stringify({
|
|
|
|
sql: "SELECT * FROM test_table_private_1",
|
|
|
|
cache_buster:2 // this is to avoid getting the cached response
|
|
|
|
});
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/gadm4/6/31/24.png?' + sql,
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
2012-09-06 01:55:50 +08:00
|
|
|
}, function(res) {
|
|
|
|
// 401 Unauthorized
|
|
|
|
assert.equal(res.statusCode, 401, res.statusCode + ': ' + res.body);
|
|
|
|
done();
|
|
|
|
});
|
2012-07-18 17:00:24 +08:00
|
|
|
});
|
|
|
|
|
2012-08-02 17:17:53 +08:00
|
|
|
test("get'ing a tile with data from private table should fail when unauthenticated (uses old redis key)", function(done){
|
|
|
|
var sql = querystring.stringify({
|
|
|
|
sql: "SELECT * FROM test_table_private_1",
|
|
|
|
cache_buster:3,
|
|
|
|
// 1235 is written in rails:users:vizzuality:map_key SET
|
|
|
|
// See https://github.com/Vizzuality/Windshaft-cartodb/issues/39
|
|
|
|
map_key: 1235
|
|
|
|
});
|
|
|
|
assert.response(server, {
|
|
|
|
headers: {host: 'vizzuality.localhost.lan'},
|
|
|
|
url: '/tiles/gadm4/6/31/24.png?' + sql,
|
|
|
|
method: 'GET'
|
|
|
|
},{
|
2012-09-06 01:55:50 +08:00
|
|
|
}, function(res) {
|
|
|
|
// 401 Unauthorized
|
|
|
|
assert.equal(res.statusCode, 401, res.statusCode + ': ' + res.body);
|
|
|
|
done();
|
|
|
|
});
|
2012-08-02 17:17:53 +08:00
|
|
|
});
|
|
|
|
|
2012-07-09 22:49:31 +08:00
|
|
|
});
|
2012-06-06 22:24:44 +08:00
|
|
|
|