-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ import { | |
walkJsx, | ||
getJsxChildren, | ||
serialiseJsx, | ||
validateLink, | ||
} from './ui'; | ||
|
||
describe('getTextChildren', () => { | ||
|
@@ -541,6 +542,61 @@ describe('getJsxElementFromComponent', () => { | |
}); | ||
}); | ||
|
||
describe('validateLink', () => { | ||
it('passes for a valid link', () => { | ||
const fn = jest.fn().mockReturnValue(false); | ||
|
||
expect(() => validateLink('https://foo.bar', fn)).not.toThrow(); | ||
expect(() => validateLink('mailto:[email protected]', fn)).not.toThrow(); | ||
|
||
expect(fn).toHaveBeenCalledTimes(2); | ||
expect(fn).toHaveBeenCalledWith('foo.bar'); | ||
expect(fn).toHaveBeenCalledWith('bar.com'); | ||
}); | ||
|
||
it('throws an error for an invalid protocol', () => { | ||
const fn = jest.fn().mockReturnValue(false); | ||
|
||
expect(() => validateLink('http://foo.bar', fn)).toThrow( | ||
'Invalid URL: Protocol must be one of: https:, mailto:.', | ||
); | ||
|
||
expect(fn).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('throws an error for an invalid URL', () => { | ||
const fn = jest.fn().mockReturnValue(false); | ||
|
||
expect(() => validateLink('foo.bar', fn)).toThrow( | ||
'Invalid URL: Unable to parse URL.', | ||
); | ||
|
||
expect(fn).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('throws an error for a phishing link', () => { | ||
const fn = jest.fn().mockReturnValue(true); | ||
|
||
expect(() => validateLink('https://test.metamask-phishing.io', fn)).toThrow( | ||
'Invalid URL: The specified URL is not allowed.', | ||
); | ||
|
||
expect(fn).toHaveBeenCalledTimes(1); | ||
expect(fn).toHaveBeenCalledWith('test.metamask-phishing.io'); | ||
}); | ||
|
||
it('throws an error for a phishing email', () => { | ||
const fn = jest.fn().mockReturnValue(true); | ||
|
||
expect(() => | ||
validateLink('mailto:[email protected]', fn), | ||
).toThrow('Invalid URL: The specified URL is not allowed.'); | ||
|
||
expect(fn).toHaveBeenCalledTimes(1); | ||
expect(fn).toHaveBeenCalledWith('test.metamask-phishing.io'); | ||
}); | ||
}); | ||
|
||
describe('validateTextLinks', () => { | ||
it('passes for valid links', () => { | ||
expect(() => | ||
|
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