From 765b1f47866c56f33fb1c2cdd555bae917b30264 Mon Sep 17 00:00:00 2001 From: Daniel James Smith Date: Thu, 11 Nov 2021 16:41:56 +0100 Subject: [PATCH] Add more inputs to the valid urls tests --- spec/common/misc/utils.spec.ts | 48 +++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/spec/common/misc/utils.spec.ts b/spec/common/misc/utils.spec.ts index b49d5f2d..d5b79093 100644 --- a/spec/common/misc/utils.spec.ts +++ b/spec/common/misc/utils.spec.ts @@ -20,12 +20,31 @@ describe('Utils Service', () => { }); it('should handle valid urls', () => { - expect(Utils.getDomain('https://bitwarden')).toBe('bitwarden'); - expect(Utils.getDomain('https://bitwarden.com')).toBe('bitwarden.com'); + expect(Utils.getDomain('bitwarden.com')).toBe('bitwarden.com'); expect(Utils.getDomain('http://bitwarden.com')).toBe('bitwarden.com'); + expect(Utils.getDomain('https://bitwarden.com')).toBe('bitwarden.com'); + + expect(Utils.getDomain('www.bitwarden.com')).toBe('bitwarden.com'); + expect(Utils.getDomain('http://www.bitwarden.com')).toBe('bitwarden.com'); + expect(Utils.getDomain('https://www.bitwarden.com')).toBe('bitwarden.com'); + + expect(Utils.getDomain('vault.bitwarden.com')).toBe('bitwarden.com'); expect(Utils.getDomain('http://vault.bitwarden.com')).toBe('bitwarden.com'); + expect(Utils.getDomain('https://vault.bitwarden.com')).toBe('bitwarden.com'); + + expect(Utils.getDomain('www.vault.bitwarden.com')).toBe('bitwarden.com'); + expect(Utils.getDomain('http://www.vault.bitwarden.com')).toBe('bitwarden.com'); + expect(Utils.getDomain('https://www.vault.bitwarden.com')).toBe('bitwarden.com'); + + expect(Utils.getDomain('user:password@bitwarden.com:8080/password/sites?and&query#hash')) + .toBe('bitwarden.com'); + expect(Utils.getDomain('http://user:password@bitwarden.com:8080/password/sites?and&query#hash')) + .toBe('bitwarden.com'); expect(Utils.getDomain('https://user:password@bitwarden.com:8080/password/sites?and&query#hash')) .toBe('bitwarden.com'); + + expect(Utils.getDomain('bitwarden.unknown')).toBe('bitwarden.unknown'); + expect(Utils.getDomain('http://bitwarden.unknown')).toBe('bitwarden.unknown'); expect(Utils.getDomain('https://bitwarden.unknown')).toBe('bitwarden.unknown'); }); @@ -64,10 +83,33 @@ describe('Utils Service', () => { }); it('should handle valid urls', () => { + expect(Utils.getHostname('bitwarden')).toBe('bitwarden'); + expect(Utils.getHostname('http://bitwarden')).toBe('bitwarden'); + expect(Utils.getHostname('https://bitwarden')).toBe('bitwarden'); + expect(Utils.getHostname('bitwarden.com')).toBe('bitwarden.com'); - expect(Utils.getHostname('https://bitwarden.com')).toBe('bitwarden.com'); expect(Utils.getHostname('http://bitwarden.com')).toBe('bitwarden.com'); + expect(Utils.getHostname('https://bitwarden.com')).toBe('bitwarden.com'); + + expect(Utils.getHostname('www.bitwarden.com')).toBe('www.bitwarden.com'); + expect(Utils.getHostname('http://www.bitwarden.com')).toBe('www.bitwarden.com'); + expect(Utils.getHostname('https://www.bitwarden.com')).toBe('www.bitwarden.com'); + + expect(Utils.getHostname('vault.bitwarden.com')).toBe('vault.bitwarden.com'); expect(Utils.getHostname('http://vault.bitwarden.com')).toBe('vault.bitwarden.com'); + expect(Utils.getHostname('https://vault.bitwarden.com')).toBe('vault.bitwarden.com'); + + expect(Utils.getHostname('www.vault.bitwarden.com')).toBe('www.vault.bitwarden.com'); + expect(Utils.getHostname('http://www.vault.bitwarden.com')).toBe('www.vault.bitwarden.com'); + expect(Utils.getHostname('https://www.vault.bitwarden.com')).toBe('www.vault.bitwarden.com'); + + expect(Utils.getHostname('user:password@bitwarden.com:8080/password/sites?and&query#hash')) + .toBe('bitwarden.com'); + expect(Utils.getHostname('https://user:password@bitwarden.com:8080/password/sites?and&query#hash')) + .toBe('bitwarden.com'); + expect(Utils.getHostname('https://bitwarden.unknown')).toBe('bitwarden.unknown'); + }); + }); it('should support localhost', () => {