fix(base-driver): allow https in helper URL generation
use constants/helpers for `jsonwp-proxy` url tests
MODIFY
packages/base-driver/test/helpers.js
packages/base-driver/test/helpers.js
@@ -56,7 +56,7 @@ const createAppiumURL = curry(
* createURLWithPath('appium/execute')
*/
(address, port, session, pathname) => {
- if (!address.startsWith('http://')) {
+ if (!/^https?:\/\//.test(address)) {
address = `http://${address}`;
}
let path = session ? `session/${session}` : '';

MODIFY
packages/base-driver/test/jsonwp-proxy/url-specs.js
packages/base-driver/test/jsonwp-proxy/url-specs.js
// transpile:mocha
import { JWProxy } from '../..';
-import {getTestPort, TEST_HOST} from '../helpers';
+import { getTestPort, DEFAULT_TEST_HOST, createAppiumURL } from '../helpers';
+import _ from 'lodash';
describe('JWProxy', function () {
let port;
+ let createTestURL;
+ let testStatusURL;
+ let createTestSessionURL;
+ let testNewSessionURL;
+
+ const PROXY_HOST = '127.0.0.2';
+ const PROXY_PORT = 4723;
+
+ const createProxyURL = createAppiumURL(PROXY_HOST, PROXY_PORT);
+ const PROXY_STATUS_URL = createProxyURL('', 'status');
+
function createJWProxy (opts = {}) {
- return new JWProxy({server: TEST_HOST, port, ...opts});
+ return new JWProxy({server: DEFAULT_TEST_HOST, port, ...opts});
}
before(async function () {
port = await getTestPort();
+ createTestURL = createAppiumURL(DEFAULT_TEST_HOST, port);
+ testStatusURL = createTestURL('', 'status');
+ createTestSessionURL = createTestURL(_, '');
+ testNewSessionURL = createTestURL('', 'session');
});
describe('proxying full urls', function () {
it('should translate host and port', function () {
- let incomingUrl = 'http://127.0.0.2:4723/status';
+ let incomingUrl = PROXY_STATUS_URL;
let j = createJWProxy();
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal(`http://${TEST_HOST}:${port}/status`);
+ proxyUrl.should.equal(testStatusURL);
});
it('should translate the scheme', function () {
- let incomingUrl = 'http://127.0.0.2:4723/status';
+ let incomingUrl = PROXY_STATUS_URL;
let j = createJWProxy({scheme: 'HTTPS'});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal(`https://${TEST_HOST}:${port}/status`);
+ proxyUrl.should.equal(createAppiumURL(`https://${DEFAULT_TEST_HOST}`, port, '', 'status'));
});
it('should translate the base', function () {
- let incomingUrl = 'http://127.0.0.2:4723/status';
+ let incomingUrl = PROXY_STATUS_URL;
let j = createJWProxy({base: ''});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal(`http://${TEST_HOST}:${port}/status`);
+ proxyUrl.should.equal(testStatusURL);
});
it('should translate the session id', function () {
- let incomingUrl = 'http://127.0.0.2:4723/session/foobar/element';
+ let incomingUrl = createProxyURL('foobar', 'element');
let j = createJWProxy({sessionId: 'barbaz'});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal(`http://${TEST_HOST}:${port}/session/barbaz/element`);
+ proxyUrl.should.equal(createTestURL('barbaz', 'element'));
});
it('should error when translating session commands without session id', function () {
- let incomingUrl = 'http://127.0.0.2:4723/session/foobar/element';
+ let incomingUrl = createProxyURL('foobar', 'element');
let j = createJWProxy();
(() => { j.getUrlForProxy(incomingUrl); }).should.throw('session id');
});
@@ -51,25 +67,25 @@ describe('JWProxy', function () {
let incomingUrl = '/status';
let j = createJWProxy();
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal(`http://${TEST_HOST}:${port}/status`);
+ proxyUrl.should.equal(testStatusURL);
});
it('should proxy /session', function () {
let incomingUrl = '/session';
let j = createJWProxy();
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal(`http://${TEST_HOST}:${port}/session`);
+ proxyUrl.should.equal(testNewSessionURL);
});
it('should proxy /sessions', function () {
let incomingUrl = '/sessions';
let j = createJWProxy();
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal(`http://${TEST_HOST}:${port}/sessions`);
+ proxyUrl.should.equal(createTestURL('', 'sessions'));
});
it('should proxy session commands based off /session', function () {
let incomingUrl = '/session/foobar/element';
let j = createJWProxy({sessionId: 'barbaz'});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal(`http://${TEST_HOST}:${port}/session/barbaz/element`);
+ proxyUrl.should.equal(createTestURL('barbaz', 'element'));
});
it('should error session commands based off /session without session id', function () {
let incomingUrl = '/session/foobar/element';
@@ -80,7 +96,7 @@ describe('JWProxy', function () {
let incomingUrl = '/session/3d001db2-7987-42a7-975d-8d5d5304083f/timeouts/implicit_wait';
let j = createJWProxy({sessionId: '123'});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal(`http://${TEST_HOST}:${port}/session/123/timeouts/implicit_wait`);
+ proxyUrl.should.equal(createTestURL('123', 'timeouts/implicit_wait'));
});
it('should proxy session commands based off /session as ""', function () {
let incomingUrl = '';
@@ -88,25 +104,25 @@ describe('JWProxy', function () {
(() => { j.getUrlForProxy(incomingUrl); }).should.throw('session id');
j = createJWProxy({sessionId: '123'});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal(`http://${TEST_HOST}:${port}/session/123`);
+ proxyUrl.should.equal(createTestSessionURL('123'));
});
it('should proxy session commands without /session', function () {
let incomingUrl = '/element';
let j = createJWProxy({sessionId: 'barbaz'});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal(`http://${TEST_HOST}:${port}/session/barbaz/element`);
+ proxyUrl.should.equal(createTestURL('barbaz', 'element'));
});
it(`should proxy session commands when '/session' is in the url`, function () {
let incomingUrl = '/session/82a9b7da-faaf-4a1d-8ef3-5e4fb5812200/cookie/session-something-or-other';
let j = createJWProxy({sessionId: 'barbaz'});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal(`http://${TEST_HOST}:${port}/session/barbaz/cookie/session-something-or-other`);
+ proxyUrl.should.equal(createTestURL('barbaz', 'cookie/session-something-or-other'));
});
it(`should proxy session commands when '/session' is in the url and not base on the original url`, function () {
let incomingUrl = '/session/82a9b7da-faaf-4a1d-8ef3-5e4fb5812200/cookie/session-something-or-other';
let j = createJWProxy({sessionId: 'barbaz'});
let proxyUrl = j.getUrlForProxy(incomingUrl);
- proxyUrl.should.equal(`http://${TEST_HOST}:${port}/session/barbaz/cookie/session-something-or-other`);
+ proxyUrl.should.equal(createTestURL('barbaz', 'cookie/session-something-or-other'));
});
it('should error session commands without /session without session id', function () {
let incomingUrl = '/element';

fix(base-driver): allow https in helper URL generation

- use constants/helpers for `jsonwp-proxy` url tests