-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from Authress/coerce-regional-endpoint
Coerce region endpoints to global authentication endpoint.
- Loading branch information
Showing
3 changed files
with
67 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
module.exports.sanitizeUrl = function sanitizeUrl(url) { | ||
if (url.startsWith('http')) { | ||
return url; | ||
module.exports.sanitizeUrl = function sanitizeUrl(rawUrlStrng) { | ||
let sanitizedUrl = rawUrlStrng; | ||
if (!sanitizedUrl.startsWith('http')) { | ||
sanitizedUrl = `https://${sanitizedUrl}`; | ||
} | ||
|
||
return `https://${url}`; | ||
const url = new URL(sanitizedUrl); | ||
const domainBaseUrlMatch = url.host.match(/^([a-z0-9-]+)[.][a-z0-9-]+[.]authress[.]io$/); | ||
if (domainBaseUrlMatch) { | ||
url.host = `${domainBaseUrlMatch[1]}.login.authress.io`; | ||
sanitizedUrl = url.toString(); | ||
} | ||
|
||
return sanitizedUrl.replace(/[/]+$/, ''); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const { describe, it, beforeEach, afterEach } = require('mocha'); | ||
const sinon = require('sinon'); | ||
const { expect } = require('chai'); | ||
|
||
const { LoginClient } = require('../src/index'); | ||
const windowManager = require('../src/windowManager'); | ||
const { sanitizeUrl } = require('../src/util'); | ||
|
||
let sandbox; | ||
beforeEach(() => { sandbox = sinon.createSandbox(); }); | ||
afterEach(() => sandbox.restore()); | ||
|
||
describe('util.js', () => { | ||
describe('sanitizeUrl()', () => { | ||
it('Returns http for localhost', () => { | ||
const authressApiUrl = 'http://localhost:8080'; | ||
const result = sanitizeUrl(authressApiUrl); | ||
expect(result).to.eql('http://localhost:8080'); | ||
}); | ||
|
||
it('Returns http for localstack', () => { | ||
const authressApiUrl = 'http://authress.localstack.cloud:4556'; | ||
const result = sanitizeUrl(authressApiUrl); | ||
expect(result).to.eql('http://authress.localstack.cloud:4556'); | ||
}); | ||
|
||
it('custom domain returns custom domain', () => { | ||
const authressApiUrl = 'https://authress.company.com'; | ||
const result = sanitizeUrl(authressApiUrl); | ||
expect(result).to.eql('https://authress.company.com'); | ||
}); | ||
|
||
it('raw authentication domain returns domain', () => { | ||
const authressApiUrl = 'https://account.login.authress.io'; | ||
const result = sanitizeUrl(authressApiUrl); | ||
expect(result).to.eql('https://account.login.authress.io'); | ||
}); | ||
|
||
it('Convert raw authorization region domain to global authentication. This can be necessary when an account incorrectly uses the authorization domain when really they need to use the authentication one.', () => { | ||
const authressApiUrl = 'https://account.api-na-east.authress.io'; | ||
const result = sanitizeUrl(authressApiUrl); | ||
expect(result).to.eql('https://account.login.authress.io'); | ||
}); | ||
}); | ||
}); | ||
|