Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix how the tenant and client info url is build to avoid format issues #740

Merged
merged 4 commits into from
Dec 1, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@
"react": "^15.0.0 || ^16.0.0",
"react-addons-css-transition-group": "^15.0.0 || ^16.0.0",
"react-dom": "^15.0.0 || ^16.0.0",
"trim": "0.0.1"
"trim": "0.0.1",
"url-join": "^1.1.0"
},
"cdn-component": {
"name": "lock",
Expand Down
3 changes: 2 additions & 1 deletion src/core/client/settings.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import urljoin from 'url-join';
import { load } from '../../utils/cdn_utils';
import * as l from '../index';
import { initClient } from './index';

export function fetchClientSettings(clientID, clientBaseUrl, cb) {
load({
method: "setClient",
url: `${clientBaseUrl}/client/${clientID}.js?t${+new Date()}`,
url: urljoin(clientBaseUrl, 'client', `${clientID}.js`, `?t${+new Date()}`),
check: o => o && o.id === clientID,
cb: cb
});
Expand Down
5 changes: 3 additions & 2 deletions src/core/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import urljoin from 'url-join';
import Immutable, { List, Map, Set } from 'immutable';
import { isSmallScreen } from '../utils/media_utils';
import { endsWith } from '../utils/string_utils';
Expand Down Expand Up @@ -262,7 +263,7 @@ function extractClientBaseUrlOption(opts, domain) {
}
}

function extractTenantBaseUrlOption(opts, domain) {
export function extractTenantBaseUrlOption(opts, domain) {
if (opts.configurationBaseUrl && typeof opts.configurationBaseUrl === "string") {
return opts.configurationBaseUrl;
}
Expand All @@ -288,7 +289,7 @@ function extractTenantBaseUrlOption(opts, domain) {
domain = domainUrl;
}

return `${domain}/tenants/v1/${tenant_name}.js`;
return urljoin(domain, 'tenants', 'v1', `${tenant_name}.js`);
}

function extractLanguageBaseUrlOption(opts, domain) {
Expand Down
60 changes: 60 additions & 0 deletions test/tenantinfo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"use strict";
import { stub } from 'sinon';

import expect from 'expect.js';

import {extractTenantBaseUrlOption} from '../src/core/index';

describe("extractTenantBaseUrlOption", () => {

it('should return the configurationBaseUrl', () => {

var url = extractTenantBaseUrlOption({
configurationBaseUrl: 'https://test.com'
}, 'me.auth0.com');

expect(url).to.be('https://test.com')

});

it('should return the assetsUrl', () => {

var url = extractTenantBaseUrlOption({
assetsUrl: 'https://test.com'
}, 'me.auth0.com');

expect(url).to.be('https://test.com')

});

it('should return the cdn url', () => {

var url = extractTenantBaseUrlOption({

}, 'me.auth0.com');

expect(url).to.be('https://cdn.auth0.com/tenants/v1/me.js')

});

it('should return the regionalized cdn url', () => {

var url = extractTenantBaseUrlOption({

}, 'me.eu.auth0.com');

expect(url).to.be('https://cdn.eu.auth0.com/tenants/v1/me.js')

});

it('should return the instance url', () => {

var url = extractTenantBaseUrlOption({

}, 'auth.random.com');

expect(url).to.be('https://auth.random.com/tenants/v1/auth.js')

});

});