Skip to content

Commit

Permalink
run testcafe with https protocol (#1985)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Kalinin committed Apr 27, 2018
1 parent cc2d574 commit 109d1d6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/client/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ export function getProxyUrl (url, opts) {
/*eslint-disable no-restricted-properties*/
const proxyHostname = opts && opts.proxyHostname || location.hostname;
const proxyPort = opts && opts.proxyPort || location.port.toString();
const protocol = opts && opts.proxyProtocol || location.protocol;
/*eslint-enable no-restricted-properties*/

const proxyProtocol = parsedResourceType.isWebSocket ? 'ws:' : void 0;
const webSocketProtocol = protocol === 'https:' ? 'wss:' : 'ws:';
const proxyProtocol = parsedResourceType.isWebSocket ? webSocketProtocol : protocol;

const sessionId = opts && opts.sessionId || settings.get().sessionId;
let charset = opts && opts.charset;
let reqOrigin = opts && opts.reqOrigin;
Expand Down
26 changes: 19 additions & 7 deletions src/proxy/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Router from './router';
import http from 'http';
import https from 'https';
import * as urlUtils from '../utils/url';
import { readSync as read } from 'read-file-relative';
import { respond204, respond500, respondWithJSON, fetchBody, preventCaching } from '../utils/http';
Expand All @@ -22,26 +23,36 @@ function parseAsJson (msg) {
}
}

function createServerInfo (hostname, port, crossDomainPort) {
function createServerInfo (hostname, port, crossDomainPort, protocol) {
return {
hostname: hostname,
port: port,
crossDomainPort: crossDomainPort,
domain: `http://${hostname}:${port}`
protocol: protocol,
domain: `${protocol}//${hostname}:${port}`
};
}

// Proxy
export default class Proxy extends Router {
constructor (hostname, port1, port2) {
constructor (hostname, port1, port2, options) {
super();

this.openSessions = {};

this.server1Info = createServerInfo(hostname, port1, port2);
this.server2Info = createServerInfo(hostname, port2, port1);
this.server1 = http.createServer((req, res) => this._onRequest(req, res, this.server1Info));
this.server2 = http.createServer((req, res) => this._onRequest(req, res, this.server2Info));
options = options || {};

const serverProvider = options.ssl ? https : http;
const protocol = options.ssl ? 'https:' : 'http:';
const serverOptions = {
key: options.key || '',
cert: options.cert || ''
};

this.server1Info = createServerInfo(hostname, port1, port2, protocol);
this.server2Info = createServerInfo(hostname, port2, port1, protocol);
this.server1 = serverProvider.createServer(serverOptions, (req, res) => this._onRequest(req, res, this.server1Info));
this.server2 = serverProvider.createServer(serverOptions, (req, res) => this._onRequest(req, res, this.server2Info));

this.server1.on('upgrade', (req, socket, head) => this._onUpgradeRequest(req, socket, head, this.server1Info));
this.server2.on('upgrade', (req, socket, head) => this._onUpgradeRequest(req, socket, head, this.server2Info));
Expand Down Expand Up @@ -171,6 +182,7 @@ export default class Proxy extends Router {
return urlUtils.getProxyUrl(url, {
proxyHostname: this.server1Info.hostname,
proxyPort: this.server1Info.port,
proxyProtocol: this.server1Info.protocol,
sessionId: session.id
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/request-pipeline/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,13 @@ export default class RequestPipelineContext {

toProxyUrl (url, isCrossDomain, resourceType, charset) {
const proxyHostname = this.serverInfo.hostname;
const proxyProtocol = this.serverInfo.protocol;
const proxyPort = isCrossDomain ? this.serverInfo.crossDomainPort : this.serverInfo.port;
const sessionId = this.session.id;

return urlUtils.getProxyUrl(url, {
proxyHostname,
proxyProtocol,
proxyPort,
sessionId,
resourceType,
Expand Down

0 comments on commit 109d1d6

Please sign in to comment.