2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 17:29:07 +08:00
|
|
|
require('../../support/test-helper');
|
2017-03-23 01:58:37 +08:00
|
|
|
|
2019-10-07 17:29:07 +08:00
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var ResourceLocator = require('../../../lib/models/resource-locator');
|
2017-03-23 01:58:37 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('ResourceLocator', function () {
|
2017-03-23 01:58:37 +08:00
|
|
|
var USERNAME = 'username';
|
|
|
|
var RESOURCE = 'wadus';
|
2018-01-03 23:04:31 +08:00
|
|
|
var TILE_RESOURCE = 'wadus/{z}/{x}/{y}.png';
|
2017-03-23 01:58:37 +08:00
|
|
|
var HTTP_SUBDOMAINS = ['1', '2', '3', '4'];
|
|
|
|
var HTTPS_SUBDOMAINS = ['a', 'b', 'c', 'd'];
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should return default urls when no serverMetadata is in environment', function () {
|
2017-03-23 01:58:37 +08:00
|
|
|
var resourceLocator = new ResourceLocator({});
|
|
|
|
var urls = resourceLocator.getUrls(USERNAME, RESOURCE);
|
|
|
|
assert.ok(urls);
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('basic', function () {
|
2018-01-03 20:57:01 +08:00
|
|
|
var BASIC_ENVIRONMENT = {
|
|
|
|
serverMetadata: {
|
|
|
|
cdn_url: {
|
|
|
|
http: 'cdn.carto.com',
|
|
|
|
https: 'cdn.ssl.carto.com'
|
|
|
|
}
|
2017-03-23 01:58:37 +08:00
|
|
|
}
|
2018-01-03 20:57:01 +08:00
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('getUrls', function () {
|
|
|
|
it('should return default urls when basic http and https domains are provided', function () {
|
2018-01-03 20:57:01 +08:00
|
|
|
var resourceLocator = new ResourceLocator(BASIC_ENVIRONMENT);
|
|
|
|
var urls = resourceLocator.getUrls(USERNAME, RESOURCE);
|
|
|
|
assert.ok(urls);
|
2017-03-23 01:58:37 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(urls.http, ['http://cdn.carto.com', USERNAME, 'api/v1/map', RESOURCE].join('/'));
|
|
|
|
assert.strictEqual(urls.https, ['https://cdn.ssl.carto.com', USERNAME, 'api/v1/map', RESOURCE].join('/'));
|
2018-01-03 20:57:01 +08:00
|
|
|
});
|
|
|
|
});
|
2018-01-03 23:04:31 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('getTileUrls', function () {
|
|
|
|
it('should return default urls when basic http and https domains are provided', function () {
|
2018-01-03 23:04:31 +08:00
|
|
|
var resourceLocator = new ResourceLocator(BASIC_ENVIRONMENT);
|
|
|
|
var urls = resourceLocator.getTileUrls(USERNAME, TILE_RESOURCE);
|
|
|
|
assert.ok(urls);
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(
|
2018-01-03 23:04:31 +08:00
|
|
|
urls.http,
|
|
|
|
[`http://cdn.carto.com/${USERNAME}/api/v1/map/${TILE_RESOURCE}`]
|
|
|
|
);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(
|
2018-01-03 23:04:31 +08:00
|
|
|
urls.https,
|
|
|
|
[`https://cdn.ssl.carto.com/${USERNAME}/api/v1/map/${TILE_RESOURCE}`]
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-01-04 04:53:03 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('getTemplateUrls', function () {
|
|
|
|
it('should return default urls when basic http and https domains are provided', function () {
|
2018-01-04 04:53:03 +08:00
|
|
|
var resourceLocator = new ResourceLocator(BASIC_ENVIRONMENT);
|
|
|
|
var urls = resourceLocator.getTemplateUrls(USERNAME, TILE_RESOURCE);
|
|
|
|
assert.ok(urls);
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(urls.http, {
|
2018-01-04 04:53:03 +08:00
|
|
|
urlTemplate: `http://cdn.carto.com/${USERNAME}/api/v1/map/${TILE_RESOURCE}`,
|
|
|
|
subdomains: []
|
|
|
|
});
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(urls.https, {
|
2018-01-04 04:53:03 +08:00
|
|
|
urlTemplate: `https://cdn.ssl.carto.com/${USERNAME}/api/v1/map/${TILE_RESOURCE}`,
|
|
|
|
subdomains: []
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-03-23 01:58:37 +08:00
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('resource templates', function () {
|
2018-01-03 20:57:01 +08:00
|
|
|
var RESOURCE_TEMPLATES_ENVIRONMENT = {
|
|
|
|
serverMetadata: {
|
|
|
|
cdn_url: {
|
|
|
|
http: 'cdn.carto.com',
|
|
|
|
https: 'cdn.ssl.carto.com'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resources_url_templates: {
|
|
|
|
http: 'http://{{=it.user}}.localhost.lan/api/v1/map',
|
|
|
|
https: 'https://{{=it.user}}.ssl.localhost.lan/api/v1/map'
|
2017-03-23 01:58:37 +08:00
|
|
|
}
|
2018-01-03 20:57:01 +08:00
|
|
|
};
|
2017-03-23 01:58:37 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('getUrls', function () {
|
|
|
|
it('resources_url_templates should take precedence over http and https domains', function () {
|
2018-01-03 20:57:01 +08:00
|
|
|
var resourceLocator = new ResourceLocator(RESOURCE_TEMPLATES_ENVIRONMENT);
|
|
|
|
var urls = resourceLocator.getUrls(USERNAME, RESOURCE);
|
|
|
|
assert.ok(urls);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(
|
2018-01-04 00:10:09 +08:00
|
|
|
urls.http,
|
|
|
|
['http://' + USERNAME + '.localhost.lan', 'api/v1/map', RESOURCE].join('/')
|
|
|
|
);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(
|
2018-01-04 00:10:09 +08:00
|
|
|
urls.https,
|
|
|
|
['https://' + USERNAME + '.ssl.localhost.lan', 'api/v1/map', RESOURCE].join('/')
|
|
|
|
);
|
2018-01-03 20:57:01 +08:00
|
|
|
});
|
|
|
|
});
|
2018-01-03 23:04:31 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('getTileUrls', function () {
|
|
|
|
it('resources_url_templates should take precedence over http and https domains', function () {
|
2018-01-03 23:04:31 +08:00
|
|
|
var resourceLocator = new ResourceLocator(RESOURCE_TEMPLATES_ENVIRONMENT);
|
|
|
|
var urls = resourceLocator.getTileUrls(USERNAME, TILE_RESOURCE);
|
|
|
|
assert.ok(urls);
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(
|
2018-01-03 23:04:31 +08:00
|
|
|
urls.http,
|
|
|
|
[`http://${USERNAME}.localhost.lan/api/v1/map/${TILE_RESOURCE}`]
|
|
|
|
);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(
|
2018-01-03 23:04:31 +08:00
|
|
|
urls.https,
|
|
|
|
[`https://${USERNAME}.ssl.localhost.lan/api/v1/map/${TILE_RESOURCE}`]
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-01-04 04:53:03 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('getTemplateUrls', function () {
|
|
|
|
it('resources_url_templates should take precedence over http and https domains', function () {
|
2018-01-04 04:53:03 +08:00
|
|
|
var resourceLocator = new ResourceLocator(RESOURCE_TEMPLATES_ENVIRONMENT);
|
|
|
|
var urls = resourceLocator.getTemplateUrls(USERNAME, TILE_RESOURCE);
|
|
|
|
assert.ok(urls);
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(urls.http, {
|
2018-01-04 04:53:03 +08:00
|
|
|
urlTemplate: `http://${USERNAME}.localhost.lan/api/v1/map/${TILE_RESOURCE}`,
|
|
|
|
subdomains: []
|
|
|
|
});
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(urls.https, {
|
2018-01-04 04:53:03 +08:00
|
|
|
urlTemplate: `https://${USERNAME}.ssl.localhost.lan/api/v1/map/${TILE_RESOURCE}`,
|
|
|
|
subdomains: []
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-03-23 01:58:37 +08:00
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('cdn templates', function () {
|
2018-01-03 20:57:01 +08:00
|
|
|
var CDN_TEMPLATES_ENVIRONMENT = {
|
|
|
|
serverMetadata: {
|
|
|
|
cdn_url: {
|
|
|
|
http: 'cdn.carto.com',
|
|
|
|
https: 'cdn.ssl.carto.com',
|
|
|
|
templates: {
|
|
|
|
http: {
|
2019-10-22 01:07:24 +08:00
|
|
|
url: 'http://{s}.cdn.carto.com',
|
2018-01-03 20:57:01 +08:00
|
|
|
subdomains: HTTP_SUBDOMAINS
|
|
|
|
},
|
|
|
|
https: {
|
2019-10-22 01:07:24 +08:00
|
|
|
url: 'https://cdn_{s}.ssl.cdn.carto.com',
|
2018-01-03 20:57:01 +08:00
|
|
|
subdomains: HTTPS_SUBDOMAINS
|
|
|
|
}
|
2017-03-23 01:58:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-03 20:57:01 +08:00
|
|
|
};
|
2018-01-04 04:53:03 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('getUrls', function () {
|
|
|
|
it('cdn_url templates should take precedence over http and https domains', function () {
|
2018-01-03 20:57:01 +08:00
|
|
|
var resourceLocator = new ResourceLocator(CDN_TEMPLATES_ENVIRONMENT);
|
|
|
|
var urls = resourceLocator.getUrls(USERNAME, RESOURCE);
|
|
|
|
assert.ok(urls);
|
|
|
|
|
|
|
|
var httpSubdomain = ResourceLocator.subdomain(HTTP_SUBDOMAINS, RESOURCE);
|
|
|
|
var httpsSubdomain = ResourceLocator.subdomain(HTTPS_SUBDOMAINS, RESOURCE);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(
|
2018-01-03 20:57:01 +08:00
|
|
|
urls.http,
|
|
|
|
['http://' + httpSubdomain + '.cdn.carto.com', USERNAME, 'api/v1/map', RESOURCE].join('/')
|
|
|
|
);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(
|
2018-01-03 20:57:01 +08:00
|
|
|
urls.https,
|
|
|
|
['https://cdn_' + httpsSubdomain + '.ssl.cdn.carto.com', USERNAME, 'api/v1/map', RESOURCE].join('/')
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2017-03-23 01:58:37 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('getTileUrls', function () {
|
|
|
|
it('cdn_url templates should take precedence over http and https domains', function () {
|
2018-01-03 23:04:31 +08:00
|
|
|
var resourceLocator = new ResourceLocator(CDN_TEMPLATES_ENVIRONMENT);
|
|
|
|
var urls = resourceLocator.getTileUrls(USERNAME, TILE_RESOURCE);
|
|
|
|
assert.ok(urls);
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(
|
2018-01-03 23:04:31 +08:00
|
|
|
urls.http,
|
|
|
|
HTTP_SUBDOMAINS
|
|
|
|
.map(s => `http://${s}.cdn.carto.com/${USERNAME}/api/v1/map/${TILE_RESOURCE}`)
|
|
|
|
);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(
|
2018-01-03 23:04:31 +08:00
|
|
|
urls.https,
|
|
|
|
HTTPS_SUBDOMAINS
|
|
|
|
.map(s => `https://cdn_${s}.ssl.cdn.carto.com/${USERNAME}/api/v1/map/${TILE_RESOURCE}`)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('getTemplateUrls', function () {
|
|
|
|
it('cdn_url templates should take precedence over http and https domains', function () {
|
2018-01-04 04:53:03 +08:00
|
|
|
var resourceLocator = new ResourceLocator(CDN_TEMPLATES_ENVIRONMENT);
|
|
|
|
var urls = resourceLocator.getTemplateUrls(USERNAME, TILE_RESOURCE);
|
|
|
|
assert.ok(urls);
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(urls.http, {
|
2018-01-04 04:53:03 +08:00
|
|
|
urlTemplate: `http://{s}.cdn.carto.com/${USERNAME}/api/v1/map/${TILE_RESOURCE}`,
|
|
|
|
subdomains: HTTP_SUBDOMAINS
|
|
|
|
});
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(urls.https, {
|
2018-01-04 04:53:03 +08:00
|
|
|
urlTemplate: `https://cdn_{s}.ssl.cdn.carto.com/${USERNAME}/api/v1/map/${TILE_RESOURCE}`,
|
|
|
|
subdomains: HTTPS_SUBDOMAINS
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-03-23 01:58:37 +08:00
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('cdn and resource templates', function () {
|
2018-01-03 20:57:01 +08:00
|
|
|
var CDN_URL_AND_RESOURCE_TEMPLATES_ENVIRONMENT = {
|
|
|
|
serverMetadata: {
|
|
|
|
cdn_url: {
|
|
|
|
http: 'cdn.carto.com',
|
|
|
|
https: 'cdn.ssl.carto.com',
|
|
|
|
templates: {
|
|
|
|
http: {
|
2019-10-22 01:07:24 +08:00
|
|
|
url: 'http://{s}.cdn.carto.com',
|
2018-01-03 20:57:01 +08:00
|
|
|
subdomains: HTTP_SUBDOMAINS
|
|
|
|
},
|
|
|
|
https: {
|
2019-10-22 01:07:24 +08:00
|
|
|
url: 'https://cdn_{s}.ssl.cdn.carto.com',
|
2018-01-03 20:57:01 +08:00
|
|
|
subdomains: HTTPS_SUBDOMAINS
|
|
|
|
}
|
2017-03-23 01:58:37 +08:00
|
|
|
}
|
|
|
|
}
|
2018-01-03 20:57:01 +08:00
|
|
|
},
|
|
|
|
resources_url_templates: {
|
|
|
|
http: 'http://{{=it.cdn_url}}/u/{{=it.user}}/api/v1/map',
|
|
|
|
https: 'https://{{=it.cdn_url}}/u/{{=it.user}}/api/v1/map'
|
2017-03-23 01:58:37 +08:00
|
|
|
}
|
2018-01-03 20:57:01 +08:00
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('getUrls', function () {
|
|
|
|
it('should mix cdn_url templates and resources_url_templates', function () {
|
2018-01-03 20:57:01 +08:00
|
|
|
var resourceLocator = new ResourceLocator(CDN_URL_AND_RESOURCE_TEMPLATES_ENVIRONMENT);
|
|
|
|
var urls = resourceLocator.getUrls(USERNAME, RESOURCE);
|
|
|
|
assert.ok(urls);
|
|
|
|
|
|
|
|
var httpSubdomain = ResourceLocator.subdomain(HTTP_SUBDOMAINS, RESOURCE);
|
|
|
|
var httpsSubdomain = ResourceLocator.subdomain(HTTPS_SUBDOMAINS, RESOURCE);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(
|
2018-01-03 20:57:01 +08:00
|
|
|
urls.http,
|
|
|
|
['http://' + httpSubdomain + '.cdn.carto.com', 'u', USERNAME, 'api/v1/map', RESOURCE].join('/')
|
|
|
|
);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(
|
2018-01-03 20:57:01 +08:00
|
|
|
urls.https,
|
2018-01-04 00:19:14 +08:00
|
|
|
`https://cdn_${httpsSubdomain}.ssl.cdn.carto.com/u/${USERNAME}/api/v1/map/${RESOURCE}`
|
2018-01-03 20:57:01 +08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2017-03-23 01:58:37 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('getTileUrls', function () {
|
|
|
|
it('should mix cdn_url templates and resources_url_templates', function () {
|
2018-01-03 23:04:31 +08:00
|
|
|
var resourceLocator = new ResourceLocator(CDN_URL_AND_RESOURCE_TEMPLATES_ENVIRONMENT);
|
|
|
|
var urls = resourceLocator.getTileUrls(USERNAME, TILE_RESOURCE);
|
|
|
|
assert.ok(urls);
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(
|
2018-01-03 23:04:31 +08:00
|
|
|
urls.http,
|
|
|
|
HTTP_SUBDOMAINS
|
|
|
|
.map(s => `http://${s}.cdn.carto.com/u/${USERNAME}/api/v1/map/${TILE_RESOURCE}`)
|
|
|
|
);
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(
|
2018-01-03 23:04:31 +08:00
|
|
|
urls.https,
|
|
|
|
HTTPS_SUBDOMAINS
|
|
|
|
.map(s => `https://cdn_${s}.ssl.cdn.carto.com/u/${USERNAME}/api/v1/map/${TILE_RESOURCE}`)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('getTemplateUrls', function () {
|
|
|
|
it('should mix cdn_url templates and resources_url_templates', function () {
|
2018-01-04 04:53:03 +08:00
|
|
|
var resourceLocator = new ResourceLocator(CDN_URL_AND_RESOURCE_TEMPLATES_ENVIRONMENT);
|
|
|
|
var urls = resourceLocator.getTemplateUrls(USERNAME, TILE_RESOURCE);
|
|
|
|
assert.ok(urls);
|
|
|
|
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(urls.http, {
|
2018-01-04 04:53:03 +08:00
|
|
|
urlTemplate: `http://{s}.cdn.carto.com/u/${USERNAME}/api/v1/map/${TILE_RESOURCE}`,
|
|
|
|
subdomains: HTTP_SUBDOMAINS
|
|
|
|
});
|
2019-10-22 01:52:51 +08:00
|
|
|
assert.deepStrictEqual(urls.https, {
|
2018-01-04 04:53:03 +08:00
|
|
|
urlTemplate: `https://cdn_{s}.ssl.cdn.carto.com/u/${USERNAME}/api/v1/map/${TILE_RESOURCE}`,
|
|
|
|
subdomains: HTTPS_SUBDOMAINS
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-03-23 01:58:37 +08:00
|
|
|
});
|
|
|
|
});
|