Skip to content

Commit

Permalink
proxy bypass check for specific request DevExpress#1791 (DevExpress#2209
Browse files Browse the repository at this point in the history
)
  • Loading branch information
AlexKamaev authored and AlexanderMoskovkin committed Mar 23, 2018
1 parent c7a806b commit 688d723
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 174 deletions.
17 changes: 12 additions & 5 deletions src/runner/test-run-controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import EventEmitter from 'events';
import { TestRun as LegacyTestRun } from 'testcafe-legacy-api';
import checkUrl from '../utils/check-url';
import TestRun from '../test-run';


Expand Down Expand Up @@ -127,10 +126,18 @@ export default class TestRunController extends EventEmitter {

testRun.start();

const pageUrl = testRun.test.pageUrl;
const needBypassHost = this.opts.proxyBypass && checkUrl(pageUrl, this.opts.proxyBypass.split(','));
const externalProxyHost = needBypassHost ? null : this.opts.externalProxyHost;
const pageUrl = testRun.test.pageUrl;
const externalProxyHost = this.opts.externalProxyHost;
const proxyBypassRules = this.opts.proxyBypass && this.opts.proxyBypass.split(',');
let externalProxySettings = null;

return this.proxy.openSession(pageUrl, testRun, externalProxyHost);
if (externalProxyHost) {
externalProxySettings = {
url: externalProxyHost,
bypassRules: proxyBypassRules
};
}

return this.proxy.openSession(pageUrl, testRun, externalProxySettings);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
</head>
<body>
<div id="result"></div>
<script src="http://non-existing-url.xyz"></script>
</body>
</html>
14 changes: 14 additions & 0 deletions test/functional/fixtures/proxy/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,19 @@ describe('Using proxy-bypass', function () {
it('Should bypass using proxy by set of rules', function () {
return runTests('testcafe-fixtures/index.test.js', null, { useProxy: ERROR_PROXY_URL, proxyBypass: 'dummy,localhost:3000' });
});

it('Should open page without proxy but get resource with proxy', function () {
const http = require('http');

const server = http.createServer(function (req, res) {
res.write('document.getElementById(\'result\').innerHTML = \'proxy\'');
res.end();
}).listen(3006);

return runTests('testcafe-fixtures/bypass-page-proxy-request.test.js', null, { useProxy: 'localhost:3006', proxyBypass: 'localhost:3000' })
.then(() => {
server.close();
});
});
});

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Selector } from 'testcafe';

fixture `Open page without proxy but get resource with proxy`
.page `http://localhost:3000/fixtures/proxy/pages/bypass-page-proxy-request.html`;

test('Should open page without proxy but get resource with proxy', async t => {
await t.expect(Selector('#result').innerText).eql('proxy');
});
169 changes: 0 additions & 169 deletions test/server/match-url-test.js

This file was deleted.

0 comments on commit 688d723

Please sign in to comment.