-
Notifications
You must be signed in to change notification settings - Fork 904
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 #45 from brave/shields/169
disable shields for any protocol other than http or https
- Loading branch information
Showing
9 changed files
with
138 additions
and
7 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
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
export const isHttpOrHttps = (url?: string) => { | ||
if (!url) { | ||
return false | ||
} | ||
return /^https?:/i.test(url) | ||
} |
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
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,44 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import 'mocha' | ||
import * as assert from 'assert' | ||
import { isHttpOrHttps } from '../../../app/helpers/urlUtils' | ||
|
||
describe('urlUtils test', function () { | ||
describe('isHttpOrHttps', function () { | ||
it('matches http when defined as a protocol type', function () { | ||
const url = 'http://some-boring-unsafe-website.com' | ||
assert.equal(isHttpOrHttps(url), true) | ||
}) | ||
it('matches https when defined as a protocol type', function () { | ||
const url = 'https://some-nice-safe-website.com' | ||
assert.equal(isHttpOrHttps(url), true) | ||
}) | ||
it('does not match http when defined as an origin', function () { | ||
const url = 'file://http.some-website-tricking-you.com' | ||
assert.equal(isHttpOrHttps(url), false) | ||
}) | ||
it('does not match https when defined as an origin', function () { | ||
const url = 'file://https.some-website-tricking-you.com' | ||
assert.equal(isHttpOrHttps(url), false) | ||
}) | ||
it('does not match other protocol', function () { | ||
const url = 'ftp://some-old-website.com' | ||
assert.equal(isHttpOrHttps(url), false) | ||
}) | ||
it('does not match when url is not defined', function () { | ||
const url = undefined | ||
assert.equal(isHttpOrHttps(url), false) | ||
}) | ||
it('matches uppercase http', function () { | ||
const url = 'HTTP://SCREAMING-SAFE-WEBSITE.COM' | ||
assert.equal(isHttpOrHttps(url), true) | ||
}) | ||
it('matches uppercase https', function () { | ||
const url = 'HTTP://SCREAMING-UNSAFE-WEBSITE.COM' | ||
assert.equal(isHttpOrHttps(url), true) | ||
}) | ||
}) | ||
}) |