Skip to content

Commit

Permalink
Convert origin host and protocol to lower case in proxy urls
Browse files Browse the repository at this point in the history
  • Loading branch information
Churkin Andrey committed Jul 30, 2015
1 parent c1f520d commit 76d5232
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/client/sandboxes/dom-accessor-wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ function isStyleInstance (instance) {
if (instance instanceof NativeMethods.styleClass)
return true;

return instance && typeof instance === 'object' && typeof instance.border !== 'undefined' &&
(instance.toString() === '[object CSSStyleDeclaration]' ||
instance.toString() === '[object CSS2Properties]' ||
instance.toString() === '[object MSStyleCSSProperties]');
if (instance && typeof instance === 'object' && typeof instance.border !== 'undefined') {
instance = instance.toString();

return instance === '[object CSSStyleDeclaration]' || instance === '[object CSS2Properties]' ||
instance === '[object MSStyleCSSProperties]';
}

return false;
}

function isLocationInstance (instance) {
Expand All @@ -58,7 +62,7 @@ function getAnchorProperty (el, prop) {
if (el.href) {
var parsedProxyUrl = UrlUtil.parseProxyUrl(el.href);

anchor.href = parsedProxyUrl ? UrlUtil.formatUrl(parsedProxyUrl.originResourceInfo) : el.href;
anchor.href = parsedProxyUrl ? parsedProxyUrl.originUrl : el.href;

return anchor[prop];
}
Expand All @@ -68,7 +72,7 @@ function getAnchorProperty (el, prop) {

function setAnchorProperty (el, prop, value) {
if (el.href) {
anchor.href = UrlUtil.formatUrl(UrlUtil.parseProxyUrl(el.href).originResourceInfo);
anchor.href = UrlUtil.parseProxyUrl(el.href).originUrl;
anchor[prop] = value;
el.setAttribute('href', anchor.href);

Expand Down Expand Up @@ -680,7 +684,7 @@ export function init (window, document) {

get: function (doc) {
var proxyUrl = UrlUtil.parseProxyUrl(doc.referrer);
var result = proxyUrl ? UrlUtil.formatUrl(proxyUrl.originResourceInfo) : '';
var result = proxyUrl ? proxyUrl.originResourceInfo.originUrl : '';

return result;
},
Expand Down
2 changes: 2 additions & 0 deletions src/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export default class Proxy extends Router {
session.proxy = this;
this.openSessions[session.id] = session;

url = urlUtils.convertHostToLowerCase(url);

return urlUtils.getProxyUrl(url, this.server1Info.hostname, this.server1Info.port, session.id);
}

Expand Down
10 changes: 9 additions & 1 deletion src/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ UrlUtil.sameOriginCheck = function (location, checkedUrl) {
return false;
};

// NOTE: Convert origin protocol and hostname to lower case
// (https://github.com/superroma/testcafe-hammerhead/issues/1)
UrlUtil.convertHostToLowerCase = function (url) {
var parsedUrl = UrlUtil.parseUrl(url);

return (parsedUrl.protocol + '//' + parsedUrl.host).toLowerCase() + parsedUrl.partAfterHost;
};

UrlUtil.getProxyUrl = function (url, proxyHostname, proxyPort, jobUid, jobOwnerToken, resourceType) {
validateOriginUrl(url);

Expand All @@ -81,7 +89,7 @@ UrlUtil.getProxyUrl = function (url, proxyHostname, proxyPort, jobUid, jobOwnerT

params = params.join(REQUEST_DESCRIPTOR_VALUES_SEPARATOR);

return 'http://' + proxyHostname + ':' + proxyPort + '/' + params + '/' + url;
return 'http://' + proxyHostname + ':' + proxyPort + '/' + params + '/' + UrlUtil.convertHostToLowerCase(url);
};

UrlUtil.getDomain = function (parsed) {
Expand Down
7 changes: 7 additions & 0 deletions test/mocha/proxy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ describe('Proxy', function () {
})
.catch(done);
});

it('Should convert origin host and protocol to lower case', function () {
// BUG: https://github.com/superroma/testcafe-hammerhead/issues/1
var proxiedUrl = proxy.openSession('hTtp://ExaMple.Com:123/paTh/Image?Name=Value&#Hash', session);

expect(proxiedUrl).to.have.string('http://example.com:123/paTh/Image?Name=Value&#Hash');
});
});


Expand Down
7 changes: 7 additions & 0 deletions test/qunit/fixtures/util/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ test('remove unnecessary slashes form the begin of the url', function () {
strictEqual(proxy, 'http://localhost:5555/t!u/https://example.com/');
});

test('convert origin host and protocol to lower case', function () {
// BUG: https://github.com/superroma/testcafe-hammerhead/issues/1
var proxy = UrlUtil.getProxyUrl('hTtp://eXamPle.Com:123/paTh/Image?Name=Value&#Hash');

ok(proxy.indexOf('http://example.com:123/paTh/Image?Name=Value&#Hash') !== -1);
});

module('parse proxy url');

test('http', function () {
Expand Down

0 comments on commit 76d5232

Please sign in to comment.