1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-28 17:27:50 +01:00
bitwarden-browser/spec/web/services/utils.service.spec.ts

35 lines
1.6 KiB
TypeScript
Raw Normal View History

2018-04-18 18:59:48 +02:00
import { UtilsService } from '../../../src/services/utils.service';
2018-04-17 22:15:19 +02:00
describe('Utils Service', () => {
describe('getHostname', () => {
it('should fail for invalid urls', () => {
expect(UtilsService.getHostname(null)).toBeNull();
expect(UtilsService.getHostname(undefined)).toBeNull();
expect(UtilsService.getHostname(' ')).toBeNull();
expect(UtilsService.getHostname('https://bit!:"_&ward.com')).toBeNull();
expect(UtilsService.getHostname('bitwarden')).toBeNull();
});
it('should handle valid urls', () => {
expect(UtilsService.getHostname('bitwarden.com')).toBe('bitwarden.com');
expect(UtilsService.getHostname('https://bitwarden.com')).toBe('bitwarden.com');
expect(UtilsService.getHostname('http://bitwarden.com')).toBe('bitwarden.com');
expect(UtilsService.getHostname('http://vault.bitwarden.com')).toBe('vault.bitwarden.com');
expect(UtilsService.getHostname('https://user:password@bitwarden.com:8080/password/sites?and&query#hash'))
.toBe('bitwarden.com');
});
it('should support localhost and IP', () => {
expect(UtilsService.getHostname('https://localhost')).toBe('localhost');
expect(UtilsService.getHostname('https://192.168.1.1')).toBe('192.168.1.1');
});
});
describe('newGuid', () => {
it('should create a valid guid', () => {
const validGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
expect(UtilsService.newGuid()).toMatch(validGuid);
});
});
});