diff --git a/test/acceptance/analysis/analysis-layers.js b/test/acceptance/analysis/analysis-layers.js index 7665849e..d78d0077 100644 --- a/test/acceptance/analysis/analysis-layers.js +++ b/test/acceptance/analysis/analysis-layers.js @@ -109,4 +109,26 @@ describe('analysis-layers', function() { }); }); }); + + it('should fail for non-authenticated requests', function(done) { + var useCase = useCases[0]; + + // No API key here + var testClient = new TestClient(useCase.mapConfig); + + var PERMISSION_DENIED_RESPONSE = { + status: 403, + headers: { + 'Content-Type': 'application/json; charset=utf-8' + } + }; + + testClient.getLayergroup(PERMISSION_DENIED_RESPONSE, function(err, layergroupResult) { + assert.ok(!err, err); + + assert.deepEqual(layergroupResult.errors, ["permission denied for relation cdb_tablemetadata"]); + + done(); + }); + }); }); diff --git a/test/support/test-client.js b/test/support/test-client.js index 02128e36..2f46c699 100644 --- a/test/support/test-client.js +++ b/test/support/test-client.js @@ -225,6 +225,53 @@ TestClient.prototype.getTile = function(z, x, y, params, callback) { ); }; +TestClient.prototype.getLayergroup = function(expectedResponse, callback) { + var self = this; + + if (!callback) { + callback = expectedResponse; + expectedResponse = { + status: 200, + headers: { + 'Content-Type': 'application/json; charset=utf-8' + } + }; + } + + var url = '/api/v1/map'; + + if (this.apiKey) { + url += '?' + qs.stringify({api_key: this.apiKey}); + } + + assert.response(server, + { + url: url, + method: 'POST', + headers: { + host: 'localhost', + 'Content-Type': 'application/json' + }, + data: JSON.stringify(self.mapConfig) + }, + expectedResponse, + function(res, err) { + if (err) { + return callback(err); + } + + var parsedBody = JSON.parse(res.body); + + if (parsedBody.layergroupid) { + self.keysToDelete['map_cfg|' + LayergroupToken.parse(parsedBody.layergroupId).token] = 0; + self.keysToDelete['user:localhost:mapviews:global'] = 5; + } + + return callback(null, parsedBody); + } + ); +}; + TestClient.prototype.drain = function(callback) { helper.deleteRedisKeys(this.keysToDelete, callback); };