mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
[PS-1123] Improve hostname and domain retrieval (#3168)
* Add test cases from previous PR https://github.com/bitwarden/jslib/pull/547 * Install tldts as replacement for tldjs * Use tldts for hostname and domain retrieval/validation * Remove usage of old tldjs.noop-implementation * Add handling of about protocol * Remove usage of tldEndingRegex and use tldts check instead * Uninstall @types/tldjs and tldjs * Updated package-lock.json * Fix accessibility cookie check * Rename loginUriView.spec to login-uri-view.spec * Add test for getDomain failing file links * getHostName - Return null when given, data, about or file links
This commit is contained in:
committed by
GitHub
parent
94e9744d06
commit
8c59eef257
65
libs/common/spec/view/login-uri-view.spec.ts
Normal file
65
libs/common/spec/view/login-uri-view.spec.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { UriMatchType } from "@bitwarden/common/enums/uriMatchType";
|
||||
import { LoginUriView } from "@bitwarden/common/models/view/login-uri.view";
|
||||
|
||||
const testData = [
|
||||
{
|
||||
match: UriMatchType.Host,
|
||||
uri: "http://example.com/login",
|
||||
expected: "http://example.com/login",
|
||||
},
|
||||
{
|
||||
match: UriMatchType.Host,
|
||||
uri: "bitwarden.com",
|
||||
expected: "http://bitwarden.com",
|
||||
},
|
||||
{
|
||||
match: UriMatchType.Host,
|
||||
uri: "bitwarden.de",
|
||||
expected: "http://bitwarden.de",
|
||||
},
|
||||
{
|
||||
match: UriMatchType.Host,
|
||||
uri: "bitwarden.br",
|
||||
expected: "http://bitwarden.br",
|
||||
},
|
||||
];
|
||||
|
||||
describe("LoginUriView", () => {
|
||||
it("isWebsite() given an invalid domain should return false", async () => {
|
||||
const uri = new LoginUriView();
|
||||
Object.assign(uri, { match: UriMatchType.Host, uri: "bit!:_&ward.com" });
|
||||
expect(uri.isWebsite).toBe(false);
|
||||
});
|
||||
|
||||
testData.forEach((data) => {
|
||||
it(`isWebsite() given ${data.uri} should return true`, async () => {
|
||||
const uri = new LoginUriView();
|
||||
Object.assign(uri, { match: data.match, uri: data.uri });
|
||||
expect(uri.isWebsite).toBe(true);
|
||||
});
|
||||
|
||||
it(`launchUri() given ${data.uri} should return ${data.expected}`, async () => {
|
||||
const uri = new LoginUriView();
|
||||
Object.assign(uri, { match: data.match, uri: data.uri });
|
||||
expect(uri.launchUri).toBe(data.expected);
|
||||
});
|
||||
|
||||
it(`canLaunch() given ${data.uri} should return true`, async () => {
|
||||
const uri = new LoginUriView();
|
||||
Object.assign(uri, { match: data.match, uri: data.uri });
|
||||
expect(uri.canLaunch).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it(`canLaunch should return false when MatchDetection is set to Regex`, async () => {
|
||||
const uri = new LoginUriView();
|
||||
Object.assign(uri, { match: UriMatchType.RegularExpression, uri: "bitwarden.com" });
|
||||
expect(uri.canLaunch).toBe(false);
|
||||
});
|
||||
|
||||
it(`canLaunch() should return false when the given protocol does not match CanLaunchWhiteList`, async () => {
|
||||
const uri = new LoginUriView();
|
||||
Object.assign(uri, { match: UriMatchType.Host, uri: "someprotocol://bitwarden.com" });
|
||||
expect(uri.canLaunch).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user