2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../../support/test-helper');
|
2018-02-08 19:34:24 +08:00
|
|
|
|
|
|
|
const assert = require('../../support/assert');
|
|
|
|
const TestClient = require('../../support/test-client');
|
2019-10-22 01:07:24 +08:00
|
|
|
const mapnik = require('windshaft').mapnik;
|
2018-02-08 19:34:24 +08:00
|
|
|
|
2018-02-10 02:19:18 +08:00
|
|
|
const PERMISSION_DENIED_RESPONSE = {
|
|
|
|
status: 403,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('authorization', function () {
|
|
|
|
it('should create a layergroup with regular apikey token', function (done) {
|
2018-02-08 19:34:24 +08:00
|
|
|
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);
|
|
|
|
|
2018-02-08 21:48:00 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-02-10 02:19:18 +08:00
|
|
|
it('should fail getting a named map tile with default apikey token', function (done) {
|
|
|
|
const apikeyTokenCreate = 'regular1';
|
|
|
|
const apikeyTokenGet = 'default_public';
|
|
|
|
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 testClientCreate = new TestClient(mapConfig, apikeyTokenCreate);
|
|
|
|
testClientCreate.getLayergroup(function (err, layergroupResult) {
|
|
|
|
assert.ifError(err);
|
|
|
|
const layergroupId = layergroupResult.layergroupid;
|
|
|
|
|
|
|
|
const testClientGet = new TestClient({}, apikeyTokenGet);
|
|
|
|
|
2018-02-10 02:26:52 +08:00
|
|
|
const params = {
|
|
|
|
layergroupid: layergroupId,
|
|
|
|
response: PERMISSION_DENIED_RESPONSE
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClientGet.getTile(0, 0, 0, params, function (err, res, body) {
|
2018-02-10 02:19:18 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
|
2019-10-22 05:33:27 +08:00
|
|
|
assert.ok(Object.prototype.hasOwnProperty.call(body, 'errors'));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(body.errors.length, 1);
|
2018-02-10 02:19:18 +08:00
|
|
|
assert.ok(body.errors[0].match(/permission denied/), body.errors[0]);
|
|
|
|
|
|
|
|
testClientGet.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-02-08 21:48:00 +08:00
|
|
|
it('should fail creating a layergroup with default apikey token', function (done) {
|
|
|
|
const apikeyToken = 'default_public';
|
|
|
|
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({ response: { status: 403 } }, function (err, layergroupResult) {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
2019-10-22 05:33:27 +08:00
|
|
|
assert.ok(Object.prototype.hasOwnProperty.call(layergroupResult, 'errors'));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layergroupResult.errors.length, 1);
|
2018-02-08 21:48:00 +08:00
|
|
|
assert.ok(layergroupResult.errors[0].match(/permission denied/), layergroupResult.errors[0]);
|
|
|
|
|
2018-02-08 21:50:17 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create a layergroup with default apikey token', function (done) {
|
|
|
|
const apikeyToken = 'default_public';
|
|
|
|
const mapConfig = {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select * FROM test_table',
|
|
|
|
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);
|
|
|
|
|
2018-02-08 19:34:24 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-02-10 02:19:18 +08:00
|
|
|
it('should create and get a tile with default apikey token', function (done) {
|
|
|
|
const apikeyToken = 'default_public';
|
|
|
|
const mapConfig = {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select * FROM test_table',
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const testClient = new TestClient(mapConfig, apikeyToken);
|
|
|
|
|
|
|
|
testClient.getTile(0, 0, 0, function (err, res, tile) {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200);
|
2018-02-10 02:19:18 +08:00
|
|
|
assert.ok(tile instanceof mapnik.Image);
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-02-08 21:43:12 +08:00
|
|
|
it('should fail if apikey does not grant access to table', function (done) {
|
2018-02-08 19:34:24 +08:00
|
|
|
const mapConfig = {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
options: {
|
|
|
|
sql: 'select * FROM test_table_localhost_regular1',
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2019-10-22 01:07:24 +08:00
|
|
|
const testClient = new TestClient(mapConfig); // no apikey provided, using default
|
2018-02-08 19:34:24 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getLayergroup({ response: { status: 403 } }, function (err, layergroupResult) { // TODO 401
|
2018-02-08 19:34:24 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
|
2019-10-22 05:33:27 +08:00
|
|
|
assert.ok(Object.prototype.hasOwnProperty.call(layergroupResult, 'errors'));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layergroupResult.errors.length, 1);
|
2018-02-08 19:34:24 +08:00
|
|
|
assert.ok(layergroupResult.errors[0].match(/permission denied/), layergroupResult.errors[0]);
|
2018-04-06 21:26:11 +08:00
|
|
|
|
2018-02-08 19:34:24 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2018-02-08 20:07:25 +08:00
|
|
|
|
|
|
|
it('should forbide access to API if API key does not grant access', function (done) {
|
|
|
|
const apikeyToken = 'regular2';
|
|
|
|
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({ response: { status: 403 } }, function (err, layergroupResult) {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
2019-10-22 05:33:27 +08:00
|
|
|
assert.ok(Object.prototype.hasOwnProperty.call(layergroupResult, 'errors'));
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(layergroupResult.errors.length, 1);
|
2018-02-08 20:07:25 +08:00
|
|
|
assert.ok(layergroupResult.errors[0].match(/Forbidden/), layergroupResult.errors[0]);
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2018-02-08 22:20:43 +08:00
|
|
|
|
|
|
|
it('should create a layergroup with a source analysis using a default apikey token', function (done) {
|
|
|
|
const apikeyToken = 'default_public';
|
|
|
|
const mapConfig = {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD'
|
|
|
|
},
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
analyses: [
|
|
|
|
{
|
|
|
|
id: 'HEAD',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from populated_places_simple_reduced'
|
2018-04-06 21:26:11 +08:00
|
|
|
}
|
2018-02-08 22:20:43 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const testClient = new TestClient(mapConfig, apikeyToken);
|
|
|
|
|
|
|
|
testClient.getLayergroup(function (err, layergroupResult) {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.ok(layergroupResult.layergroupid);
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create a layergroup with a source analysis using a regular apikey token', function (done) {
|
|
|
|
const apikeyToken = 'regular1';
|
|
|
|
const mapConfig = {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD'
|
|
|
|
},
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
analyses: [
|
|
|
|
{
|
|
|
|
id: 'HEAD',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from test_table_localhost_regular1'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const testClient = new TestClient(mapConfig, apikeyToken);
|
|
|
|
|
|
|
|
testClient.getLayergroup(function (err, layergroupResult) {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.ok(layergroupResult.layergroupid);
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2018-02-09 01:54:14 +08:00
|
|
|
|
2018-02-09 02:01:58 +08:00
|
|
|
// Warning: TBA
|
2018-02-09 01:54:14 +08:00
|
|
|
it('should create a layergroup with a buffer analysis using a regular apikey token', function (done) {
|
|
|
|
const apikeyToken = 'regular1';
|
|
|
|
const mapConfig = {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD1'
|
|
|
|
},
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
analyses: [
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'HEAD1',
|
|
|
|
type: 'buffer',
|
2018-02-09 01:54:14 +08:00
|
|
|
params: {
|
|
|
|
source: {
|
|
|
|
id: 'HEAD2',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: 'select * from test_table_localhost_regular1'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
radius: 50000
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
const testClient = new TestClient(mapConfig, apikeyToken);
|
|
|
|
|
|
|
|
testClient.getLayergroup(function (err, layergroupResult) {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.ok(layergroupResult.layergroupid);
|
|
|
|
|
|
|
|
testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2018-04-12 23:41:07 +08:00
|
|
|
|
|
|
|
describe('Named maps', function () {
|
2018-04-12 22:22:56 +08:00
|
|
|
describe('LIST Named maps', function () {
|
|
|
|
it('should fail while listing named maps with a regular apikey token', function (done) {
|
|
|
|
const apikeyToken = 'regular1';
|
2018-02-09 19:33:33 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClient = new TestClient({}, apikeyToken);
|
2018-04-06 21:26:11 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClient.getNamedMapList({ response: { status: 403 } }, function (err, res, body) {
|
|
|
|
assert.ifError(err);
|
2018-04-06 21:26:11 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 403);
|
2018-04-06 21:26:11 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(body.errors.length, 1);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(body.errors[0].match(/Forbidden/), body.errors[0]);
|
2018-04-06 21:26:11 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
2018-04-11 18:26:09 +08:00
|
|
|
});
|
2018-04-06 21:26:11 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
it('should fail while listing named maps with the default apikey token', function (done) {
|
|
|
|
const apikeyToken = 'default_public';
|
2018-04-06 21:26:11 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClient = new TestClient({}, apikeyToken);
|
2018-04-06 21:26:11 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClient.getNamedMapList({ response: { status: 403 } }, function (err, res, body) {
|
|
|
|
assert.ifError(err);
|
2018-04-06 21:26:11 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 403);
|
2018-04-06 21:26:11 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(body.errors.length, 1);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(body.errors[0].match(/Forbidden/), body.errors[0]);
|
2018-04-11 18:26:09 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
2018-04-11 18:26:09 +08:00
|
|
|
});
|
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
it('should fail while listing named maps with non-existent apikey token', function (done) {
|
|
|
|
const apikeyToken = 'wadus-wadus';
|
2018-04-11 18:26:09 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClient = new TestClient({}, apikeyToken);
|
2018-04-11 18:26:09 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClient.getNamedMapList({ response: { status: 401 } }, function (err, res, body) {
|
|
|
|
assert.ifError(err);
|
2018-04-11 18:26:09 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 401);
|
2018-04-11 18:26:09 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(body.errors.length, 1);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(body.errors[0].match(/Unauthorized/), body.errors[0]);
|
2018-04-11 18:26:09 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
2018-04-11 18:26:09 +08:00
|
|
|
});
|
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
it('should list named maps with master apikey token', function (done) {
|
|
|
|
const apikeyToken = 1234;
|
2018-04-11 18:26:09 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClient = new TestClient({}, apikeyToken);
|
2018-04-11 18:26:09 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClient.getNamedMapList({}, function (err, res, body) {
|
|
|
|
assert.ifError(err);
|
2018-04-11 18:26:09 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(Array.isArray(body.template_ids));
|
2018-04-11 18:26:09 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
2018-04-11 18:26:09 +08:00
|
|
|
});
|
2018-04-06 21:26:11 +08:00
|
|
|
});
|
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
describe('CREATE Named Map', function () {
|
|
|
|
const template = {
|
|
|
|
version: '0.0.1',
|
|
|
|
name: 'auth-api-template',
|
|
|
|
placeholders: {
|
|
|
|
buffersize: {
|
|
|
|
type: 'number',
|
|
|
|
default: 0
|
2018-02-09 19:33:33 +08:00
|
|
|
}
|
2018-04-12 22:22:56 +08:00
|
|
|
},
|
|
|
|
layergroup: {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: [{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table_localhost_regular1',
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss_version: '2.3.0'
|
2018-04-12 22:22:56 +08:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
};
|
2018-02-09 19:33:33 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
it('should create and get a named map tile using the master apikey token', function (done) {
|
|
|
|
const apikeyToken = 1234;
|
2018-02-09 19:33:33 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClient = new TestClient(template, apikeyToken);
|
2018-02-09 19:33:33 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClient.getTile(0, 0, 0, function (err, res, tile) {
|
|
|
|
assert.ifError(err);
|
2018-02-09 19:33:33 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(tile instanceof mapnik.Image);
|
2018-04-12 18:43:41 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
2018-04-12 18:43:41 +08:00
|
|
|
});
|
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
it('should fail creating a named map using a regular apikey token', function (done) {
|
|
|
|
const apikeyToken = 'regular1';
|
2018-04-12 18:43:41 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClient = new TestClient(template, apikeyToken);
|
2018-04-12 18:43:41 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClient.createTemplate({ response: { status: 403 } }, function (err, res, response) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 18:43:41 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 403);
|
2018-04-12 18:43:41 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(response.errors.length, 1);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(response.errors[0].match(/Forbidden/), response.errors[0]);
|
2018-04-12 18:43:41 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
2018-04-12 18:43:41 +08:00
|
|
|
});
|
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
it('should fail creating a named map using the default apikey token', function (done) {
|
|
|
|
const apikeyToken = 'default_public';
|
2018-04-12 18:43:41 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClient = new TestClient(template, apikeyToken);
|
2018-04-12 18:43:41 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClient.createTemplate({ response: { status: 403 } }, function (err, res, response) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 18:43:41 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 403);
|
2018-04-12 18:43:41 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(response.errors.length, 1);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(response.errors[0].match(/Forbidden/), response.errors[0]);
|
2018-04-12 18:43:41 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
2018-04-12 18:43:41 +08:00
|
|
|
});
|
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
it('should fail creating a named map using a non-existent apikey token', function (done) {
|
|
|
|
const apikeyToken = 'wadus-wadus';
|
2018-04-12 18:43:41 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClient = new TestClient(template, apikeyToken);
|
2018-04-12 18:43:41 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClient.createTemplate({ response: { status: 401 } }, function (err, res, response) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 18:43:41 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 401);
|
2018-04-12 18:43:41 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(response.errors.length, 1);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(response.errors[0].match(/Unauthorized/), response.errors[0]);
|
2018-04-12 18:43:41 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClient.drain(done);
|
|
|
|
});
|
2018-04-12 18:43:41 +08:00
|
|
|
});
|
|
|
|
});
|
2018-02-09 19:33:33 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
describe('DELETE Named Map', function () {
|
|
|
|
const templateBase = {
|
|
|
|
version: '0.0.1',
|
|
|
|
name: 'auth-api-template',
|
|
|
|
placeholders: {
|
|
|
|
buffersize: {
|
|
|
|
type: 'number',
|
|
|
|
default: 0
|
2018-04-12 20:46:08 +08:00
|
|
|
}
|
2018-04-12 22:22:56 +08:00
|
|
|
},
|
|
|
|
layergroup: {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: [{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table_localhost_regular1',
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss_version: '2.3.0'
|
2018-04-12 22:22:56 +08:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
};
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
it('should delete a named map using the master apikey token', function (done) {
|
|
|
|
const apikeyTokenCreate = 1234;
|
|
|
|
const apikeyTokenDelete = 1234;
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const template = Object.assign({}, templateBase, { name: templateBase.name + '-delete-master' });
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientCreate = new TestClient(template, apikeyTokenCreate);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClientCreate.createTemplate({}, function (err, res, template) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientDelete = new TestClient(template, apikeyTokenDelete);
|
|
|
|
testClientDelete.deleteTemplate(
|
|
|
|
{
|
|
|
|
templateId: template.template_id,
|
|
|
|
response: { status: 204 }
|
|
|
|
},
|
|
|
|
function (err, res) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 204);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClientDelete.drain(done);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-04-12 20:46:08 +08:00
|
|
|
});
|
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
it('should fail deleting a named map using a regular apikey token', function (done) {
|
|
|
|
const apikeyTokenCreate = 1234;
|
|
|
|
const apikeyTokenDelete = 'regular1';
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const template = Object.assign({}, templateBase, { name: templateBase.name + '-delete-regular' });
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientCreate = new TestClient(template, apikeyTokenCreate);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClientCreate.createTemplate({}, function (err, res, template) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientDelete = new TestClient({}, apikeyTokenDelete);
|
|
|
|
testClientDelete.deleteTemplate(
|
|
|
|
{
|
|
|
|
templateId: template.template_id,
|
|
|
|
response: { status: 403 }
|
|
|
|
},
|
|
|
|
function (err, res, response) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 403);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(response.errors.length, 1);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(response.errors[0].match(/Forbidden/), response.errors[0]);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClientDelete.drain(done);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-04-12 20:46:08 +08:00
|
|
|
});
|
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
it('should fail deleting a named map using the default apikey token', function (done) {
|
|
|
|
const apikeyTokenCreate = 1234;
|
|
|
|
const apikeyTokenDelete = 'default_public';
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const template = Object.assign({}, templateBase, { name: templateBase.name + '-delete-default' });
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientCreate = new TestClient(template, apikeyTokenCreate);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClientCreate.createTemplate({}, function (err, res, template) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientDelete = new TestClient(template, apikeyTokenDelete);
|
|
|
|
testClientDelete.deleteTemplate(
|
|
|
|
{
|
|
|
|
templateId: template.template_id,
|
|
|
|
response: { status: 403 }
|
|
|
|
},
|
|
|
|
function (err, res, response) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 403);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(response.errors.length, 1);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(response.errors[0].match(/Forbidden/), response.errors[0]);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClientDelete.drain(done);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-04-12 20:46:08 +08:00
|
|
|
});
|
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
it('should fail deleting a named map using a non-existent apikey token', function (done) {
|
|
|
|
const apikeyTokenCreate = 1234;
|
|
|
|
const apikeyTokenDelete = 'wadus';
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const template = Object.assign({}, templateBase, { name: templateBase.name + '-delete-wadus' });
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientCreate = new TestClient(template, apikeyTokenCreate);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClientCreate.createTemplate({}, function (err, res, template) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientDelete = new TestClient(template, apikeyTokenDelete);
|
|
|
|
testClientDelete.deleteTemplate(
|
|
|
|
{
|
|
|
|
templateId: template.template_id,
|
|
|
|
response: { status: 401 }
|
|
|
|
},
|
|
|
|
function (err, res, response) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 401);
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(response.errors.length, 1);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(response.errors[0].match(/Unauthorized/), response.errors[0]);
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClientDelete.drain(done);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-04-12 22:03:02 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
describe('GET Named Map', function () {
|
|
|
|
const templateBase = {
|
|
|
|
version: '0.0.1',
|
|
|
|
name: 'auth-api-template',
|
|
|
|
placeholders: {
|
|
|
|
buffersize: {
|
|
|
|
type: 'number',
|
|
|
|
default: 0
|
2018-04-12 22:03:02 +08:00
|
|
|
}
|
2018-04-12 22:22:56 +08:00
|
|
|
},
|
|
|
|
layergroup: {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: [{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table_localhost_regular1',
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss_version: '2.3.0'
|
2018-04-12 22:22:56 +08:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
};
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
it('should get a named map using the master apikey token', function (done) {
|
|
|
|
const apikeyTokenCreate = 1234;
|
|
|
|
const apikeyTokenGet = 1234;
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const template = Object.assign({}, templateBase, { name: templateBase.name + '-get-master' });
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientCreate = new TestClient(template, apikeyTokenCreate);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClientCreate.createTemplate({}, function (err, res, template) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientDelete = new TestClient({}, apikeyTokenGet);
|
|
|
|
testClientDelete.getTemplate(
|
|
|
|
{
|
|
|
|
templateId: template.template_id,
|
|
|
|
response: { status: 200 }
|
|
|
|
},
|
|
|
|
function (err, res) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200);
|
2018-04-12 22:22:56 +08:00
|
|
|
|
|
|
|
testClientDelete.drain(done);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-04-12 22:03:02 +08:00
|
|
|
});
|
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
it('should fail getting a named map using a regular apikey token', function (done) {
|
|
|
|
const apikeyTokenCreate = 1234;
|
|
|
|
const apikeyTokenGet = 'regular1';
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const template = Object.assign({}, templateBase, { name: templateBase.name + '-get-regular' });
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientCreate = new TestClient(template, apikeyTokenCreate);
|
|
|
|
|
|
|
|
testClientCreate.createTemplate({}, function (err, res, template) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientGet = new TestClient({}, apikeyTokenGet);
|
|
|
|
testClientGet.getTemplate(
|
|
|
|
{
|
|
|
|
templateId: template.template_id,
|
|
|
|
response: { status: 403 }
|
|
|
|
},
|
|
|
|
function (err, res, response) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 403);
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(response.errors.length, 1);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(response.errors[0].match(/Forbidden/), response.errors[0]);
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClientGet.drain(done);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-04-12 22:03:02 +08:00
|
|
|
});
|
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
it('should fail getting a named map using the default apikey token', function (done) {
|
|
|
|
const apikeyTokenCreate = 1234;
|
|
|
|
const apikeyTokenGet = 'default_public';
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const template = Object.assign({}, templateBase, { name: templateBase.name + '-get-default' });
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientCreate = new TestClient(template, apikeyTokenCreate);
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClientCreate.createTemplate({}, function (err, res, template) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientGet = new TestClient(template, apikeyTokenGet);
|
|
|
|
testClientGet.getTemplate(
|
|
|
|
{
|
|
|
|
templateId: template.template_id,
|
|
|
|
response: { status: 403 }
|
|
|
|
},
|
|
|
|
function (err, res, response) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 403);
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(response.errors.length, 1);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(response.errors[0].match(/Forbidden/), response.errors[0]);
|
|
|
|
|
|
|
|
testClientGet.drain(done);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-04-12 22:03:02 +08:00
|
|
|
});
|
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
it('should fail getting a named map using a non-existent apikey token', function (done) {
|
|
|
|
const apikeyTokenCreate = 1234;
|
|
|
|
const apikeyTokenGet = 'wadus';
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const template = Object.assign({}, templateBase, { name: templateBase.name + '-get-wadus' });
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientCreate = new TestClient(template, apikeyTokenCreate);
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClientCreate.createTemplate({}, function (err, res, template) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientGet = new TestClient(template, apikeyTokenGet);
|
|
|
|
testClientGet.getTemplate(
|
|
|
|
{
|
|
|
|
templateId: template.template_id,
|
|
|
|
response: { status: 401 }
|
|
|
|
},
|
|
|
|
function (err, res, response) {
|
|
|
|
assert.ifError(err);
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 401);
|
2018-04-12 22:03:02 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(response.errors.length, 1);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(response.errors[0].match(/Unauthorized/), response.errors[0]);
|
|
|
|
|
|
|
|
testClientGet.drain(done);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-04-12 20:46:08 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
describe('UPDATE Named Map', function () {
|
|
|
|
const templateBase = {
|
|
|
|
version: '0.0.1',
|
|
|
|
name: 'auth-api-template',
|
|
|
|
placeholders: {
|
|
|
|
buffersize: {
|
|
|
|
type: 'number',
|
|
|
|
default: 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
layergroup: {
|
|
|
|
version: '1.7.0',
|
|
|
|
layers: [{
|
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table_localhost_regular1',
|
|
|
|
cartocss: TestClient.CARTOCSS.POINTS,
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss_version: '2.3.0'
|
2018-04-12 22:22:56 +08:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
};
|
2018-04-12 20:46:08 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
it('should update a named map using the master apikey token', function (done) {
|
|
|
|
const apikeyTokenCreate = 1234;
|
|
|
|
const apikeyTokenUpdate = 1234;
|
2018-02-09 19:33:33 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const template = Object.assign({}, templateBase, { name: templateBase.name + '-update-master' });
|
|
|
|
const templateUpdate = Object.assign({}, template, { zoom: 3 });
|
|
|
|
const testClientCreate = new TestClient(template, apikeyTokenCreate);
|
2018-02-09 19:33:33 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClientCreate.createTemplate({}, function (err, res, template) {
|
|
|
|
assert.ifError(err);
|
2018-02-09 19:33:33 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
const testClientDelete = new TestClient({}, apikeyTokenUpdate);
|
|
|
|
testClientDelete.updateTemplate(
|
|
|
|
{
|
|
|
|
templateId: template.template_id,
|
|
|
|
templateData: templateUpdate,
|
|
|
|
response: { status: 200 }
|
|
|
|
},
|
|
|
|
function (err, res) {
|
|
|
|
assert.ifError(err);
|
2018-02-09 19:33:33 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 200);
|
2018-02-09 19:33:33 +08:00
|
|
|
|
2018-04-12 22:22:56 +08:00
|
|
|
testClientDelete.drain(done);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail updating a named map using a regular apikey token', function (done) {
|
|
|
|
const apikeyTokenCreate = 1234;
|
|
|
|
const apikeyTokenUpdate = 'regular1';
|
|
|
|
|
|
|
|
const template = Object.assign({}, templateBase, { name: templateBase.name + '-update-regular' });
|
|
|
|
const templateUpdate = Object.assign({}, template, { zoom: 3 });
|
|
|
|
const testClientCreate = new TestClient(template, apikeyTokenCreate);
|
|
|
|
|
|
|
|
testClientCreate.createTemplate({}, function (err, res, template) {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
const testClientDelete = new TestClient({}, apikeyTokenUpdate);
|
|
|
|
testClientDelete.updateTemplate(
|
|
|
|
{
|
|
|
|
templateId: template.template_id,
|
|
|
|
templateData: templateUpdate,
|
|
|
|
response: { status: 403 }
|
|
|
|
},
|
|
|
|
function (err, res, response) {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 403);
|
2018-04-12 22:22:56 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(response.errors.length, 1);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(response.errors[0].match(/Forbidden/), response.errors[0]);
|
|
|
|
|
|
|
|
testClientDelete.drain(done);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail updating a named map using the default apikey token', function (done) {
|
|
|
|
const apikeyTokenCreate = 1234;
|
|
|
|
const apikeyTokenUpdate = 'default_public';
|
|
|
|
|
|
|
|
const template = Object.assign({}, templateBase, { name: templateBase.name + '-update-default' });
|
|
|
|
const templateUpdate = Object.assign({}, template, { zoom: 3 });
|
|
|
|
const testClientCreate = new TestClient(template, apikeyTokenCreate);
|
|
|
|
|
|
|
|
testClientCreate.createTemplate({}, function (err, res, template) {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
const testClientDelete = new TestClient({}, apikeyTokenUpdate);
|
|
|
|
testClientDelete.updateTemplate(
|
|
|
|
{
|
|
|
|
templateId: template.template_id,
|
|
|
|
templateData: templateUpdate,
|
|
|
|
response: { status: 403 }
|
|
|
|
},
|
|
|
|
function (err, res, response) {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 403);
|
2018-04-12 22:22:56 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(response.errors.length, 1);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(response.errors[0].match(/Forbidden/), response.errors[0]);
|
|
|
|
|
|
|
|
testClientDelete.drain(done);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail updating a named map using a non-existent apikey token', function (done) {
|
|
|
|
const apikeyTokenCreate = 1234;
|
|
|
|
const apikeyTokenUpdate = 'wadus';
|
|
|
|
|
|
|
|
const template = Object.assign({}, templateBase, { name: templateBase.name + '-update-wadus' });
|
|
|
|
const templateUpdate = Object.assign({}, template, { zoom: 3 });
|
|
|
|
const testClientCreate = new TestClient(template, apikeyTokenCreate);
|
|
|
|
|
|
|
|
testClientCreate.createTemplate({}, function (err, res, template) {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
const testClientDelete = new TestClient({}, apikeyTokenUpdate);
|
|
|
|
testClientDelete.updateTemplate(
|
|
|
|
{
|
|
|
|
templateId: template.template_id,
|
|
|
|
templateData: templateUpdate,
|
|
|
|
response: { status: 401 }
|
|
|
|
},
|
|
|
|
function (err, res, response) {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(res.statusCode, 401);
|
2018-04-12 22:22:56 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(response.errors.length, 1);
|
2018-04-12 22:22:56 +08:00
|
|
|
assert.ok(response.errors[0].match(/Unauthorized/), response.errors[0]);
|
|
|
|
|
|
|
|
testClientDelete.drain(done);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-10-24 00:39:02 +08:00
|
|
|
});
|
2018-02-09 19:33:33 +08:00
|
|
|
});
|
2018-02-08 19:34:24 +08:00
|
|
|
});
|