From 1c50dd6b48f792a4916de22a292b0c725e46a68a Mon Sep 17 00:00:00 2001 From: Eneko Lakasta Date: Thu, 8 Feb 2018 12:34:24 +0100 Subject: [PATCH] add first tests for auth --- test/acceptance/auth/authorization.js | 57 +++++++++++++++++++++++++++ test/support/prepare_db.sh | 11 ++++++ test/support/sql/windshaft.test.sql | 50 +++++++++++++++++++++++ test/support/test_helper.js | 3 +- 4 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 test/acceptance/auth/authorization.js diff --git a/test/acceptance/auth/authorization.js b/test/acceptance/auth/authorization.js new file mode 100644 index 00000000..e5f493b4 --- /dev/null +++ b/test/acceptance/auth/authorization.js @@ -0,0 +1,57 @@ +require('../../support/test_helper'); + +const assert = require('../../support/assert'); +const TestClient = require('../../support/test-client'); + +describe('authorization', function() { + it('should create a layergroup with regular apikey token', function(done) { + const apikeyToken = 'regular1'; + const mapConfig = { + version: '1.7.0', + layers: [ + { + options: { + sql: 'select * FROM test_table_localhost_regular1', + cartocss: TestClient.CARTOCSS.POINTS, + cartocss_version: '2.3.0' + } + } + ] + }; + const testClient = new TestClient(mapConfig, apikeyToken); + + testClient.getLayergroup(function (err, layergroupResult) { + assert.ifError(err); + + assert.ok(layergroupResult.layergroupid); + + testClient.drain(done); + }); + }); + + it('should fail if apikey does not gran access to table', function (done) { + const mapConfig = { + version: '1.7.0', + layers: [ + { + options: { + sql: 'select * FROM test_table_localhost_regular1', + cartocss: TestClient.CARTOCSS.POINTS, + cartocss_version: '2.3.0' + } + } + ] + }; + const testClient = new TestClient(mapConfig); //no apikey provided, using default + + testClient.getLayergroup({response: {status:403}}, function (err, layergroupResult) { + assert.ifError(err); + + assert.ok(layergroupResult.hasOwnProperty('errors')); + assert.equal(layergroupResult.errors.length, 1); + assert.ok(layergroupResult.errors[0].match(/permission denied/), layergroupResult.errors[0]); + + testClient.drain(done); + }); + }); +}); diff --git a/test/support/prepare_db.sh b/test/support/prepare_db.sh index 8348347a..b2ac8688 100755 --- a/test/support/prepare_db.sh +++ b/test/support/prepare_db.sh @@ -160,6 +160,17 @@ cat <