Skip to content

Commit

Permalink
Merge pull request #740 from auth0/fix-configuration-url
Browse files Browse the repository at this point in the history
Fix how the tenant and client info url is build to avoid format issues
  • Loading branch information
hzalaz authored Dec 1, 2016
2 parents 01c7a69 + 62a6853 commit cb38b57
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
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')

});

});

0 comments on commit cb38b57

Please sign in to comment.