1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

Add support for running unit tests (#381)

* Add test runner.

* Fix tests. Add tests for UtilsService.getDomain

* Test getHostname.

* Add two missing test cases and fix getDomain.
This commit is contained in:
Oscar Hinton
2017-11-17 22:33:58 +01:00
committed by Kyle Spearrin
parent f9b00c6871
commit 4531846ff8
6 changed files with 164 additions and 22 deletions

View File

@@ -1,3 +1,4 @@
import * as tldjs from 'tldjs';
import { BrowserType } from '../enums/browserType.enum';
import { UtilsService as UtilsServiceInterface } from './abstractions/utils.service';
@@ -186,28 +187,19 @@ export default class UtilsService implements UtilsServiceInterface {
if (uriString.startsWith('http://') || uriString.startsWith('https://')) {
try {
const url = new URL(uriString);
if (!url.hostname) {
return null;
}
if (url.hostname === 'localhost' || UtilsService.validIpAddress(url.hostname)) {
return url.hostname;
}
if (typeof tldjs !== 'undefined' && tldjs) {
const domain = tldjs.getDomain(url.hostname);
if (domain != null) {
return domain;
}
}
return url.hostname;
const domain = tldjs.getDomain(url.hostname);
return domain ? domain : url.hostname;
} catch (e) { }
} else if (typeof tldjs !== 'undefined' && tldjs) {
const domain = tldjs.getDomain(uriString);
if (domain != null) {
return domain;
}
}
const domain = tldjs.getDomain(uriString);
if (domain != null) {
return domain;
}
return null;
@@ -226,10 +218,6 @@ export default class UtilsService implements UtilsServiceInterface {
if (uriString.startsWith('http://') || uriString.startsWith('https://')) {
try {
const url = new URL(uriString);
if (!url.hostname) {
return null;
}
return url.hostname;
} catch (e) { }
}