Path: blob/trunk/rb/spec/unit/selenium/webdriver/proxy_spec.rb
1864 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819require_relative 'spec_helper'2021module Selenium22module WebDriver23describe Proxy do24let :proxy_settings do # manual proxy settings25{26ftp: 'mythicalftpproxy:21',27http: 'mythicalproxy:80',28no_proxy: 'noproxy',29ssl: 'mythicalsslproxy',30socks: 'mythicalsocksproxy:65555',31socks_username: 'test',32socks_password: 'test',33socks_version: 534}35end3637let :pac_proxy_settings do38{39pac: 'http://example.com/foo.pac'40}41end4243it 'raises ArgumentError if passed invalid options' do44expect { described_class.new(invalid_options: 'invalid') }.to raise_error(ArgumentError)45end4647it 'raises ArgumentError if passed an invalid proxy type' do48expect { described_class.new(type: :invalid) }.to raise_error(ArgumentError)49end5051it 'raises ArgumentError if the proxy type is changed' do52proxy = described_class.new(type: :direct)53expect { proxy.type = :system }.to raise_error(ArgumentError)54end5556it 'allows valid options for a manual proxy', :aggregate_failures do57proxy = described_class.new(proxy_settings)5859expect(proxy.ftp).to eq(proxy_settings[:ftp])60expect(proxy.http).to eq(proxy_settings[:http])61expect(proxy.no_proxy).to eq(proxy_settings[:no_proxy])62expect(proxy.ssl).to eq(proxy_settings[:ssl])63expect(proxy.socks).to eq(proxy_settings[:socks])64expect(proxy.socks_username).to eq(proxy_settings[:socks_username])65expect(proxy.socks_password).to eq(proxy_settings[:socks_password])66expect(proxy.socks_version).to eq(proxy_settings[:socks_version])67end6869it 'returns a hash of the json properties to serialize', :aggregate_failures do70proxy_json = described_class.new(proxy_settings).as_json7172expect(proxy_json['proxyType']).to eq('manual')73expect(proxy_json['ftpProxy']).to eq(proxy_settings[:ftp])74expect(proxy_json['httpProxy']).to eq(proxy_settings[:http])75expect(proxy_json['noProxy']).to eq([proxy_settings[:no_proxy]])76expect(proxy_json['sslProxy']).to eq(proxy_settings[:ssl])77expect(proxy_json['socksProxy']).to eq(proxy_settings[:socks])78expect(proxy_json['socksUsername']).to eq(proxy_settings[:socks_username])79expect(proxy_json['socksPassword']).to eq(proxy_settings[:socks_password])80expect(proxy_json['socksVersion']).to eq(proxy_settings[:socks_version])81end8283it 'configures a PAC proxy', :aggregate_failures do84proxy_json = described_class.new(pac_proxy_settings).as_json8586expect(proxy_json['proxyType']).to eq('pac')87expect(proxy_json['proxyAutoconfigUrl']).to eq(pac_proxy_settings[:pac])88end8990it 'configures an auto-detected proxy', :aggregate_failures do91proxy_json = described_class.new(auto_detect: true).as_json9293expect(proxy_json['proxyType']).to eq('autodetect')94expect(proxy_json['autodetect']).to be true95end9697it 'onlies add settings that are not nil', :aggregate_failures do98settings = {type: :manual, http: 'http proxy'}99100proxy = described_class.new(settings)101proxy_json = proxy.as_json102103expect(proxy_json.delete('proxyType')).to eq(settings[:type].to_s)104expect(proxy_json.delete('httpProxy')).to eq(settings[:http])105106expect(proxy_json).to be_empty107end108109it 'returns a JSON string' do110proxy = described_class.new(proxy_settings)111expect(proxy.to_json).to be_a(String)112end113114it 'can be serialized and deserialized' do115proxy = described_class.new(proxy_settings)116other = described_class.json_create(proxy.as_json)117118expect(proxy).to eq(other)119end120121it 'deserializes to nil if proxyType is UNSPECIFIED' do122expect(described_class.json_create('proxyType' => 'UNSPECIFIED')).to be_nil123end124end125end # WebDriver126end # Selenium127128129