selenium-side-runner
Version:
Run Selenium IDE projects in cli
108 lines • 5.16 kB
JavaScript
"use strict";
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const proxy_1 = __importDefault(require("../proxy"));
describe('proxy parser', () => {
it('should parse a direct proxy', () => {
expect((0, proxy_1.default)('direct')).toEqual({
proxyType: 'direct',
});
});
it('should parse a system proxy', () => {
expect((0, proxy_1.default)('system')).toEqual({
proxyType: 'system',
});
});
it('should parse a pac proxy', () => {
expect((0, proxy_1.default)('pac', 'http://localhost/pac')).toEqual({
proxyType: 'pac',
proxyAutoconfigUrl: 'http://localhost/pac',
});
});
it('should throw if no pac file was given', () => {
expect(() => (0, proxy_1.default)('pac')).toThrowError('A proxy autoconfig URL was not passed (e.g. --proxy-options="http://localhost/pac")');
});
it('should parse a manual proxy', () => {
expect((0, proxy_1.default)('manual', {})).toEqual({
proxyType: 'manual',
});
});
it('should omit redundant keys from the proxy', () => {
expect((0, proxy_1.default)('manual', { test: 4, http: 'http://localhost:4324' })).toEqual({
proxyType: 'manual',
httpProxy: 'http://localhost:4324',
});
});
it('should whitelist the allowed proxy protocols', () => {
expect((0, proxy_1.default)('manual', {
test: 4,
http: 'http://localhost:4324',
https: 'http://localhost:4324',
ftp: 'http://localhost:4324',
bypass: ['http://something.com'],
})).toEqual({
proxyType: 'manual',
httpProxy: 'http://localhost:4324',
ftpProxy: 'http://localhost:4324',
sslProxy: 'http://localhost:4324',
noProxy: ['http://something.com'],
});
});
it('should return an empty object if no options were given to manual proxy', () => {
expect((0, proxy_1.default)('manual')).toEqual({
proxyType: 'manual',
});
});
it('should throw if non object was passed to manual proxy type', () => {
// @ts-expect-error intentionally invalid type
expect(() => (0, proxy_1.default)('manual', 5)).toThrowError('Proxy options were not passed to manual proxy (e.g. --proxy-options="http=localhost:321 ftp=localhost:4324")');
});
it('should parse socks proxy', () => {
expect((0, proxy_1.default)('socks', { socksProxy: 'localhost:213' })).toEqual({
proxyType: 'manual',
socksProxy: 'localhost:213',
});
});
it('should parse socks proxy version', () => {
expect((0, proxy_1.default)('socks', { socksProxy: 'localhost:213', socksVersion: 5 })).toEqual({
proxyType: 'manual',
socksProxy: 'localhost:213',
socksVersion: 5,
});
expect((0, proxy_1.default)('socks', { socksProxy: 'localhost:213', socksVersion: '5' })).toEqual({
proxyType: 'manual',
socksProxy: 'localhost:213',
socksVersion: 5,
});
});
it('should throw if no socks proxy url was given', () => {
expect(() => (0, proxy_1.default)('socks')).toThrowError('Proxy options were not passed to socks proxy (e.g. --proxy-options="socksProxy=localhost:321")');
expect(() => (0, proxy_1.default)('socks', {})).toThrowError('Proxy options were not passed to socks proxy (e.g. --proxy-options="socksProxy=localhost:321")');
});
it('should throw if a non-number was passed as socks version', () => {
expect(() => (0, proxy_1.default)('socks', { socksProxy: 'localhost:434', socksVersion: 'test' })).toThrowError('Proxy socks version is invalid (e.g. --proxy-options="socksProxy=localhost:321 socksVersion=5")');
});
it('should throw if an invalid proxy type was passed', () => {
// @ts-expect-error intentionally invalid type
expect(() => (0, proxy_1.default)('invalid')).toThrowError('An unknown proxy type was passed, use one of: direct, system, manual, socks or pac (e.g. --proxy-type="direct")');
});
});
//# sourceMappingURL=proxy.spec.js.map