Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/proxy_spec.rb
1864 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
require_relative 'spec_helper'
21
22
module Selenium
23
module WebDriver
24
describe Proxy do
25
let :proxy_settings do # manual proxy settings
26
{
27
ftp: 'mythicalftpproxy:21',
28
http: 'mythicalproxy:80',
29
no_proxy: 'noproxy',
30
ssl: 'mythicalsslproxy',
31
socks: 'mythicalsocksproxy:65555',
32
socks_username: 'test',
33
socks_password: 'test',
34
socks_version: 5
35
}
36
end
37
38
let :pac_proxy_settings do
39
{
40
pac: 'http://example.com/foo.pac'
41
}
42
end
43
44
it 'raises ArgumentError if passed invalid options' do
45
expect { described_class.new(invalid_options: 'invalid') }.to raise_error(ArgumentError)
46
end
47
48
it 'raises ArgumentError if passed an invalid proxy type' do
49
expect { described_class.new(type: :invalid) }.to raise_error(ArgumentError)
50
end
51
52
it 'raises ArgumentError if the proxy type is changed' do
53
proxy = described_class.new(type: :direct)
54
expect { proxy.type = :system }.to raise_error(ArgumentError)
55
end
56
57
it 'allows valid options for a manual proxy', :aggregate_failures do
58
proxy = described_class.new(proxy_settings)
59
60
expect(proxy.ftp).to eq(proxy_settings[:ftp])
61
expect(proxy.http).to eq(proxy_settings[:http])
62
expect(proxy.no_proxy).to eq(proxy_settings[:no_proxy])
63
expect(proxy.ssl).to eq(proxy_settings[:ssl])
64
expect(proxy.socks).to eq(proxy_settings[:socks])
65
expect(proxy.socks_username).to eq(proxy_settings[:socks_username])
66
expect(proxy.socks_password).to eq(proxy_settings[:socks_password])
67
expect(proxy.socks_version).to eq(proxy_settings[:socks_version])
68
end
69
70
it 'returns a hash of the json properties to serialize', :aggregate_failures do
71
proxy_json = described_class.new(proxy_settings).as_json
72
73
expect(proxy_json['proxyType']).to eq('manual')
74
expect(proxy_json['ftpProxy']).to eq(proxy_settings[:ftp])
75
expect(proxy_json['httpProxy']).to eq(proxy_settings[:http])
76
expect(proxy_json['noProxy']).to eq([proxy_settings[:no_proxy]])
77
expect(proxy_json['sslProxy']).to eq(proxy_settings[:ssl])
78
expect(proxy_json['socksProxy']).to eq(proxy_settings[:socks])
79
expect(proxy_json['socksUsername']).to eq(proxy_settings[:socks_username])
80
expect(proxy_json['socksPassword']).to eq(proxy_settings[:socks_password])
81
expect(proxy_json['socksVersion']).to eq(proxy_settings[:socks_version])
82
end
83
84
it 'configures a PAC proxy', :aggregate_failures do
85
proxy_json = described_class.new(pac_proxy_settings).as_json
86
87
expect(proxy_json['proxyType']).to eq('pac')
88
expect(proxy_json['proxyAutoconfigUrl']).to eq(pac_proxy_settings[:pac])
89
end
90
91
it 'configures an auto-detected proxy', :aggregate_failures do
92
proxy_json = described_class.new(auto_detect: true).as_json
93
94
expect(proxy_json['proxyType']).to eq('autodetect')
95
expect(proxy_json['autodetect']).to be true
96
end
97
98
it 'onlies add settings that are not nil', :aggregate_failures do
99
settings = {type: :manual, http: 'http proxy'}
100
101
proxy = described_class.new(settings)
102
proxy_json = proxy.as_json
103
104
expect(proxy_json.delete('proxyType')).to eq(settings[:type].to_s)
105
expect(proxy_json.delete('httpProxy')).to eq(settings[:http])
106
107
expect(proxy_json).to be_empty
108
end
109
110
it 'returns a JSON string' do
111
proxy = described_class.new(proxy_settings)
112
expect(proxy.to_json).to be_a(String)
113
end
114
115
it 'can be serialized and deserialized' do
116
proxy = described_class.new(proxy_settings)
117
other = described_class.json_create(proxy.as_json)
118
119
expect(proxy).to eq(other)
120
end
121
122
it 'deserializes to nil if proxyType is UNSPECIFIED' do
123
expect(described_class.json_create('proxyType' => 'UNSPECIFIED')).to be_nil
124
end
125
end
126
end # WebDriver
127
end # Selenium
128
129