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: make issuer url validation follow the same check rules as the domain url validator #1291

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
32 changes: 31 additions & 1 deletion __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
runIframe,
urlDecodeB64,
getCrypto,
validateCrypto
validateCrypto,
getTokenIssuer
} from '../src/utils';

import { DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS } from '../src/constants';
Expand Down Expand Up @@ -493,4 +494,33 @@ describe('utils', () => {
`);
});
});

describe('getTokenIssuer', () => {
it('should add https:// to a non well formed URL', () => {
const issuer = getTokenIssuer('www.issuer.com', 'https://www.domain.com');
expect(issuer).toBe('https://www.issuer.com/');
});
it('should not add https:// to a well formed URL with HTTPS protocol', () => {
const issuer = getTokenIssuer(
'https://www.issuer.com',
'https://www.domain.com'
);
expect(issuer).toBe('https://www.issuer.com');
});
it('should not add https:// to a well formed URL with HTTP protocol', () => {
const issuer = getTokenIssuer(
'http://www.issuer.com',
'https://www.domain.com'
);
expect(issuer).toBe('http://www.issuer.com');
});
it('should return domain when issuer is undefined', () => {
const issuer = getTokenIssuer(undefined, 'https://www.domain.com');
expect(issuer).toBe('https://www.domain.com/');
});
it('should return domain when issuer is an empty string', () => {
const issuer = getTokenIssuer('', 'https://www.domain.com');
expect(issuer).toBe('https://www.domain.com/');
});
});
});
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export const getTokenIssuer = (
domainUrl: string
) => {
if (issuer) {
return issuer.startsWith('https://') ? issuer : `https://${issuer}/`;
return /^https?:\/\//.test(issuer) ? issuer : `https://${issuer}/`;
}

return `${domainUrl}/`;
Expand Down