12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- /**
- * Copyright (c) 2018-present, Infinite Red, Inc.
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- *
- * @format
- */
-
- 'use strict';
-
- const WebViewShared = require('WebViewShared');
- describe('WebViewShared', () => {
- it('extracts the origin correctly', () => {
- expect(WebViewShared.extractOrigin('http://facebook.com')).toBe(
- 'http://facebook.com',
- );
- expect(WebViewShared.extractOrigin('https://facebook.com')).toBe(
- 'https://facebook.com',
- );
- expect(WebViewShared.extractOrigin('http://facebook.com:8081')).toBe(
- 'http://facebook.com:8081',
- );
- expect(WebViewShared.extractOrigin('ftp://facebook.com')).toBe(
- 'ftp://facebook.com',
- );
- expect(WebViewShared.extractOrigin('myweirdscheme://')).toBe(
- 'myweirdscheme://',
- );
- expect(WebViewShared.extractOrigin('http://facebook.com/')).toBe(
- 'http://facebook.com',
- );
- expect(WebViewShared.extractOrigin('http://facebook.com/longerurl')).toBe(
- 'http://facebook.com',
- );
- expect(
- WebViewShared.extractOrigin('http://facebook.com/http://facebook.com'),
- ).toBe('http://facebook.com');
- expect(
- WebViewShared.extractOrigin('http://facebook.com//http://facebook.com'),
- ).toBe('http://facebook.com');
- expect(
- WebViewShared.extractOrigin('http://facebook.com//http://facebook.com//'),
- ).toBe('http://facebook.com');
- expect(WebViewShared.extractOrigin('about:blank')).toBe('about:blank');
- });
-
- it('rejects bad urls', () => {
- expect(WebViewShared.extractOrigin('a/b')).toBeNull();
- expect(WebViewShared.extractOrigin('a//b')).toBeNull();
- });
-
- it('creates a whitelist regex correctly', () => {
- expect(WebViewShared.originWhitelistToRegex('http://*')).toBe('http://.*');
- expect(WebViewShared.originWhitelistToRegex('*')).toBe('.*');
- expect(WebViewShared.originWhitelistToRegex('*//test')).toBe('.*//test');
- expect(WebViewShared.originWhitelistToRegex('*/*')).toBe('.*/.*');
- expect(WebViewShared.originWhitelistToRegex('*.com')).toBe('.*\\.com');
- });
- });
|