Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize the proxy protocol #2024

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ async function getValidPort (port) {
}

// API
async function createTestCafe (hostname, port1, port2) {
[hostname, port1, port2] = await Promise.all([
async function createTestCafe (hostname, port1, port2, protocol) {
[hostname, port1, port2, protocol] = await Promise.all([
getValidHostname(hostname),
getValidPort(port1),
getValidPort(port2)
getValidPort(port2),
protocol
]);

var testcafe = new TestCafe(hostname, port1, port2);
var testcafe = new TestCafe(hostname, port1, port2, protocol);

setupExitHook(cb => testcafe.close().then(cb));

Expand Down
4 changes: 2 additions & 2 deletions src/testcafe.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const FAVICON = read('./client/ui/favicon.ico', true);


export default class TestCafe {
constructor (hostname, port1, port2) {
constructor (hostname, port1, port2, protocol) {
this.closed = false;
this.proxy = new Proxy(hostname, port1, port2);
this.proxy = new Proxy(hostname, port1, port2, protocol);
this.browserConnectionGateway = new BrowserConnectionGateway(this.proxy);
this.runners = [];

Expand Down
19 changes: 17 additions & 2 deletions test/server/create-testcafe-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ describe('TestCafe factory function', function () {
var testCafe = null;
var server = null;

function getTestCafe (hostname, port1, port2) {
return createTestCafe(hostname, port1, port2)
function getTestCafe (hostname, port1, port2, protocol) {
return createTestCafe(hostname, port1, port2, protocol)
.then(function (tc) {
testCafe = tc;
});
Expand Down Expand Up @@ -58,6 +58,21 @@ describe('TestCafe factory function', function () {
});
});

it('Should accept custom ports, hostname and protocol', function () {
return getTestCafe('localhost', 1338, 1339, 'https')
.then(function () {
return testCafe.createBrowserConnection();
})
.then(function (bc) {
var bcUrl = url.parse(bc.url);
var port = parseInt(bcUrl.port, 10);

expect(bcUrl.hostname).eql('localhost');
expect(bcUrl.protocol).eql('https:');
expect(port).eql(1338);
});
});

it('Should raise error if specified port is not free', function () {
var serverListen = new Promise(function (resolve) {
server = net.createServer();
Expand Down