Skip to content

Commit

Permalink
let "poi-lists" directory depend on hub origin only;
Browse files Browse the repository at this point in the history
add handling for "poi_hub_origin = /" (necessary for e2e tests);
add CORS header hint for "poi-lists" directory to documentation
OIL-325
  • Loading branch information
Alexander Glintschert committed May 6, 2019
1 parent c9c9f31 commit 33a1e1c
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 57 deletions.
2 changes: 1 addition & 1 deletion docs/src/docs/03-configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ To instantiate oil.js with POI activated, make up a name for your company group

* Setup a server where the consent cookie is stored. For example `any.domain.com`.
* Upload `hub.html` from the `./release` folder, resulting in `https://any.domain.com/hub.html`
* Create a `MyGroupName.json` and upload it in a subfolder named `poi-lists` to your server, resulting in `https://any.domain.com/poi-lists/MyGroupName.json`. Note the file name must be the same as the value passed in poi_group_name. For an example see <<poi-list, POI-List section>>.
* Create a `MyGroupName.json` and upload it in a subfolder named `poi-lists` to your server, resulting in `https://any.domain.com/poi-lists/MyGroupName.json`. Note: The file name must be the same as the value passed in `poi_group_name`. For an example see <<poi-list, POI-List section>>. Note: Enable CORS for the `poi-lists` directory and its contained files.
* Make sure the `MyGroupName.json` is served with the right CORS-headers so that your websites are allowed to read it.
* Add the required parameters to each website configuration that should share the consent cookie:

Expand Down
3 changes: 0 additions & 3 deletions etc/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ module.exports = {
}, {
from: path.resolve(sourcePath, 'demos/empty.html'),
to: 'demos/empty.html'
}, {
from: path.resolve(sourcePath, 'demos/poi-lists'),
to: 'demos/poi-lists'
}],
title: 'OIL',
additionalWebpackOptions: false
Expand Down
29 changes: 0 additions & 29 deletions src/demos/poi-lists/axelSpringerSe_01.json

This file was deleted.

9 changes: 0 additions & 9 deletions src/demos/poi-lists/withBlacklist.json

This file was deleted.

9 changes: 0 additions & 9 deletions src/demos/poi-lists/withWhitelist.json

This file was deleted.

5 changes: 3 additions & 2 deletions src/scripts/core/core_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function isSubscriberSetCookieActive() {
export function getHubOrigin() {
let origin = getConfigValue(OIL_CONFIG.ATTR_HUB_ORIGIN, 'https://unpkg.com');
if (origin) {
return origin.indexOf('http') !== -1 ? origin : location.protocol + origin;
return origin === '/' || origin.indexOf('http') !== -1 ? origin : location.protocol + origin;
}
return null;
}
Expand Down Expand Up @@ -207,7 +207,8 @@ export function getHubLocation() {
}

export function getPoiListDirectory() {
return getHubLocation().replace(/\/[^/]+$/, '/poi-lists');
let hubOrigin = getHubOrigin();
return hubOrigin.endsWith('/') ? hubOrigin.replace(/\/$/, '/poi-lists') : hubOrigin + '/poi-lists';
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script id="oil-configuration" type="application/configuration">
{
"config_version": 1,
"poi_hub_origin": "/",
"poi_hub_path": "path/to/my/hub.html"
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script id="oil-configuration" type="application/configuration">
{
"config_version": 1,
"poi_hub_origin": "https://myServer.com/",
"poi_hub_path": "path/to/my/hub.html"
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script id="oil-configuration" type="application/configuration">
{
"config_version": 1,
"poi_hub_origin": "//myServer.com",
"poi_hub_path": "path/to/my/hub.html"
}
</script>
41 changes: 37 additions & 4 deletions test/specs/core/core_config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import {
getConfigValue,
getCookieExpireInDays,
getCustomPurposes,
getDefaultToOptin, getHubLocation,
getDefaultToOptin,
getHubLocation,
getHubOrigin,
getHubPath,
getIabVendorBlacklist,
getIabVendorWhitelist,
getLanguageFromLocale,
getLocale,
getLocaleUrl,
getLocaleVariantName,
getPoiGroupName, getPoiListDirectory,
getPoiGroupName,
getPoiListDirectory,
getPublicPath,
getShowLimitedVendors,
setGdprApplies,
Expand Down Expand Up @@ -217,6 +220,25 @@ describe('core_config', () => {

});

describe('getHubOrigin', () => {

it('returns complete configured hub origin', () => {
loadFixture('config/given.config.with.poiHubOrigin.and.poiHubPath.html');
expect(getHubOrigin()).toEqual('https://myServer.com');
});

it('returns complete configured hub origin if it is "/"', () => {
loadFixture('config/given.config.with.poiHubOrigin.being.slash.html');
expect(getHubOrigin()).toEqual('/');
});

it('returns configured hub origin with added protocol it missed', () => {
loadFixture('config/given.config.with.poiHubOrigin.without.protocol.html');
expect(getHubOrigin()).toEqual('http://myServer.com');
});

});

describe('getHubLocation', () => {

it('returns correct hub location depending on configured hub origin and hub path', () => {
Expand All @@ -227,9 +249,20 @@ describe('core_config', () => {
});

describe('getPoiListDirectory', () => {
it('returns correct poi list directory depending on configured hub origin and hub path', () => {

it('returns correct poi list directory depending on configured hub origin ending with "/"', () => {
loadFixture('config/given.config.with.poiHubOrigin.ending.with.slash.html');
expect(getPoiListDirectory()).toEqual('https://myServer.com/poi-lists');
});

it('returns correct poi list directory depending on configured hub origin not ending with "/"', () => {
loadFixture('config/given.config.with.poiHubOrigin.and.poiHubPath.html');
expect(getPoiListDirectory()).toEqual('https://myServer.com/path/to/my/poi-lists');
expect(getPoiListDirectory()).toEqual('https://myServer.com/poi-lists');
});

it('returns correct poi list directory depending on configured hub origin being "/"', () => {
loadFixture('config/given.config.with.poiHubOrigin.being.slash.html');
expect(getPoiListDirectory()).toEqual('/poi-lists');
});

});
Expand Down

0 comments on commit 33a1e1c

Please sign in to comment.