-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate list of emails in
validateLink
function (#2750)
This improves the hostname validation when using a list of emails rather than a single email.
- Loading branch information
Showing
3 changed files
with
80 additions
and
5 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"branches": 99.73, | ||
"functions": 98.9, | ||
"lines": 99.43, | ||
"statements": 96.33 | ||
"lines": 99.44, | ||
"statements": 96.34 | ||
} |
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 |
---|---|---|
|
@@ -554,6 +554,30 @@ describe('validateLink', () => { | |
expect(fn).toHaveBeenCalledWith('bar.com'); | ||
}); | ||
|
||
it('passes for a valid list of emails', () => { | ||
const fn = jest.fn().mockReturnValue(false); | ||
|
||
expect(() => | ||
validateLink('mailto:[email protected],[email protected],[email protected]', fn), | ||
).not.toThrow(); | ||
|
||
expect(fn).toHaveBeenCalledTimes(3); | ||
expect(fn).toHaveBeenCalledWith('bar.com'); | ||
expect(fn).toHaveBeenCalledWith('baz.com'); | ||
expect(fn).toHaveBeenCalledWith('qux.com'); | ||
}); | ||
|
||
it('passes for a valid email with a parameter', () => { | ||
const fn = jest.fn().mockReturnValue(false); | ||
|
||
expect(() => | ||
validateLink('mailto:[email protected]?subject=Subject', fn), | ||
).not.toThrow(); | ||
|
||
expect(fn).toHaveBeenCalledTimes(1); | ||
expect(fn).toHaveBeenCalledWith('bar.com'); | ||
}); | ||
|
||
it('throws an error for an invalid protocol', () => { | ||
const fn = jest.fn().mockReturnValue(false); | ||
|
||
|
@@ -595,6 +619,44 @@ describe('validateLink', () => { | |
expect(fn).toHaveBeenCalledTimes(1); | ||
expect(fn).toHaveBeenCalledWith('test.metamask-phishing.io'); | ||
}); | ||
|
||
it('throws an error for a phishing email when using multiple emails', () => { | ||
const fn = jest.fn().mockImplementation((email) => { | ||
if (email === 'test.metamask-phishing.io') { | ||
return true; | ||
} | ||
|
||
return false; | ||
}); | ||
|
||
expect(() => | ||
validateLink('mailto:[email protected],[email protected]', 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 when using parameters', () => { | ||
const fn = jest.fn().mockImplementation((email) => { | ||
if (email === 'test.metamask-phishing.io') { | ||
return true; | ||
} | ||
|
||
return false; | ||
}); | ||
|
||
expect(() => | ||
validateLink( | ||
'mailto:[email protected],[email protected]?subject=Subject', | ||
fn, | ||
), | ||
).toThrow('Invalid URL: The specified URL is not allowed.'); | ||
|
||
expect(fn).toHaveBeenCalledTimes(2); | ||
expect(fn).toHaveBeenCalledWith('bar.com'); | ||
expect(fn).toHaveBeenCalledWith('test.metamask-phishing.io'); | ||
}); | ||
}); | ||
|
||
describe('validateTextLinks', () => { | ||
|
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