MM-14446: consider subpath when evaluating if url is internal (#946)

* MM-14446: consider subpath when evaluating if url is internal

When clicking on an URL with `target=_blank`, the webview decides if it should launch an external browser or a new window within the Electron application. Update this logic to consider the application's configured subpath so as to treat links outside the subpath but on the same domain as external.

* fix licensing on new file

* fix .eslintrc.json indentation

* tweak header eslint rules for specific files
This commit is contained in:
Jesse Hallam
2019-03-15 15:20:41 -04:00
committed by William Gathoye
parent 6e2b3d7fab
commit 79e020ba43
5 changed files with 182 additions and 30 deletions

View File

@@ -0,0 +1,47 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
'use strict';
import url from 'url';
import assert from 'assert';
import Utils from '../../../src/utils/util';
describe('Utils', () => {
describe('isInternalURL', () => {
it('should be false for different hosts', () => {
const currentURL = url.parse('http://localhost/team/channel1');
const targetURL = url.parse('http://example.com/team/channel2');
const basename = '/';
assert.equal(Utils.isInternalURL(targetURL, currentURL, basename), false);
});
it('should be false for same hosts, non-matching basename', () => {
const currentURL = url.parse('http://localhost/subpath/team/channel1');
const targetURL = url.parse('http://localhost/team/channel2');
const basename = '/subpath';
assert.equal(Utils.isInternalURL(targetURL, currentURL, basename), false);
});
it('should be true for same hosts, matching basename', () => {
const currentURL = url.parse('http://localhost/subpath/team/channel1');
const targetURL = url.parse('http://localhost/subpath/team/channel2');
const basename = '/subpath';
assert.equal(Utils.isInternalURL(targetURL, currentURL, basename), true);
});
it('should be true for same hosts, default basename', () => {
const currentURL = url.parse('http://localhost/team/channel1');
const targetURL = url.parse('http://localhost/team/channel2');
const basename = '/';
assert.equal(Utils.isInternalURL(targetURL, currentURL, basename), true);
});
it('should be true for same hosts, default basename, empty target path', () => {
const currentURL = url.parse('http://localhost/team/channel1');
const targetURL = url.parse('http://localhost/');
const basename = '/';
assert.equal(Utils.isInternalURL(targetURL, currentURL, basename), true);
});
});
});