vagrant-proxyconf 1.5.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +15 -14
- data/CHANGELOG.md +19 -0
- data/Gemfile +25 -7
- data/LICENSE.txt +1 -1
- data/README.md +117 -18
- data/Rakefile +1 -27
- data/development/Dockerfile +40 -0
- data/development/README.md +2 -0
- data/development/Vagrantfile.example +156 -9
- data/development/install-c7.sh +46 -0
- data/development/install-debian.sh +55 -0
- data/development/tinyproxy.conf +333 -0
- data/lib/vagrant-proxyconf/action.rb +15 -7
- data/lib/vagrant-proxyconf/action/base.rb +47 -5
- data/lib/vagrant-proxyconf/action/configure_apt_proxy.rb +17 -0
- data/lib/vagrant-proxyconf/action/configure_chef_proxy.rb +32 -27
- data/lib/vagrant-proxyconf/action/configure_docker_proxy.rb +113 -12
- data/lib/vagrant-proxyconf/action/configure_env_proxy.rb +58 -11
- data/lib/vagrant-proxyconf/action/configure_git_proxy.rb +25 -9
- data/lib/vagrant-proxyconf/action/configure_npm_proxy.rb +14 -6
- data/lib/vagrant-proxyconf/action/configure_pear_proxy.rb +15 -8
- data/lib/vagrant-proxyconf/action/configure_svn_proxy.rb +15 -8
- data/lib/vagrant-proxyconf/action/configure_yum_proxy.rb +16 -0
- data/lib/vagrant-proxyconf/cap/linux/chef_proxy_conf.rb +17 -0
- data/lib/vagrant-proxyconf/cap/linux/docker_proxy_conf.rb +2 -1
- data/lib/vagrant-proxyconf/cap/linux/yum_proxy_conf.rb +19 -0
- data/lib/vagrant-proxyconf/cap/util.rb +4 -5
- data/lib/vagrant-proxyconf/capability.rb +10 -0
- data/lib/vagrant-proxyconf/config.rb +20 -0
- data/lib/vagrant-proxyconf/config/chef_proxy.rb +25 -0
- data/lib/vagrant-proxyconf/config/docker_proxy.rb +25 -0
- data/lib/vagrant-proxyconf/config/git_proxy.rb +3 -0
- data/lib/vagrant-proxyconf/config/npm_proxy.rb +25 -0
- data/lib/vagrant-proxyconf/config/pear_proxy.rb +19 -0
- data/lib/vagrant-proxyconf/version.rb +1 -1
- data/locales/en.yml +38 -0
- data/resources/yum_config.awk +1 -0
- data/spec/spec_helper.rb +27 -9
- data/spec/unit/fixtures/docker_client_config_json_enabled_proxy +9 -0
- data/spec/unit/fixtures/docker_client_config_json_no_proxy +5 -0
- data/spec/unit/fixtures/etc_environment_only_http_proxy.conf +9 -0
- data/spec/unit/fixtures/yum_with_repository_and_proxy_containing_special_chars.conf +10 -0
- data/spec/unit/vagrant-proxyconf/action/base_spec.rb +191 -0
- data/spec/unit/vagrant-proxyconf/action/configure_apt_proxy_spec.rb +162 -0
- data/spec/unit/vagrant-proxyconf/action/configure_chef_proxy_spec.rb +32 -0
- data/spec/unit/vagrant-proxyconf/action/configure_docker_proxy_spec.rb +489 -0
- data/spec/unit/vagrant-proxyconf/action/configure_env_proxy_spec.rb +105 -4
- data/spec/unit/vagrant-proxyconf/action/configure_git_proxy_spec.rb +116 -0
- data/spec/unit/vagrant-proxyconf/action/configure_npm_proxy_spec.rb +67 -0
- data/spec/unit/vagrant-proxyconf/action/configure_pear_proxy_spec.rb +116 -0
- data/spec/unit/vagrant-proxyconf/action/configure_svn_proxy_spec.rb +85 -0
- data/spec/unit/vagrant-proxyconf/action/configure_yum_proxy_spec.rb +100 -0
- data/spec/unit/vagrant-proxyconf/cap/linux/docker_proxy_conf_spec.rb +1 -1
- data/spec/unit/vagrant-proxyconf/cap/util_spec.rb +2 -2
- data/spec/unit/vagrant-proxyconf/config/key_mixin_spec.rb +1 -1
- data/spec/unit/vagrant-proxyconf/resources/yum_config_spec.rb +14 -0
- data/travis/before_install +26 -0
- metadata +24 -4
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'vagrant-proxyconf/action/configure_env_proxy'
|
3
|
+
require 'vagrant-proxyconf/config/proxy'
|
3
4
|
|
4
5
|
describe VagrantPlugins::ProxyConf::Action::ConfigureEnvProxy do
|
5
6
|
|
@@ -24,12 +25,14 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureEnvProxy do
|
|
24
25
|
is_expected.to eq false
|
25
26
|
end
|
26
27
|
end
|
28
|
+
|
27
29
|
context 'when config proxy is not enabled' do
|
28
30
|
it do
|
29
31
|
@config_proxy_enabled = false
|
30
32
|
is_expected.to eq true
|
31
33
|
end
|
32
34
|
end
|
35
|
+
|
33
36
|
context 'when config proxy is empty string' do
|
34
37
|
it do
|
35
38
|
@config_proxy_enabled = ''
|
@@ -38,24 +41,60 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureEnvProxy do
|
|
38
41
|
end
|
39
42
|
|
40
43
|
context 'when target config proxy is enabled' do
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
+
context 'given config.proxy.enabled is a Hash' do
|
45
|
+
it 'when has key :enabled => true and not skipped, #disabled? should return false' do
|
46
|
+
@config_proxy_enabled = {
|
47
|
+
:env => {
|
48
|
+
:enabled => true,
|
49
|
+
:skip => false,
|
50
|
+
}
|
51
|
+
}
|
52
|
+
is_expected.to eq false
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'when key :enabled => true and skipped => true, #disabled should return false' do
|
56
|
+
@config_proxy_enabled = {
|
57
|
+
:env => {
|
58
|
+
:enabled => true,
|
59
|
+
:skip => true,
|
60
|
+
}
|
61
|
+
}
|
62
|
+
is_expected.to eq false
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'when config.proxy.enabled[:env] = true, return false' do
|
66
|
+
@config_proxy_enabled = { :env => true }
|
67
|
+
is_expected.to eq false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'given config.proxy.enabled is a Boolean' do
|
72
|
+
it 'when true, #disabled? should return false' do
|
73
|
+
@config_proxy_enabled = true
|
74
|
+
is_expected.to eq false
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'when false, #disabled? should return true' do
|
78
|
+
@config_proxy_enabled = false
|
79
|
+
is_expected.to eq true
|
80
|
+
end
|
44
81
|
end
|
45
82
|
end
|
83
|
+
|
46
84
|
context 'when target config proxy target is not enabled' do
|
47
85
|
it do
|
48
86
|
@config_proxy_enabled = { env: false }
|
49
87
|
is_expected.to eq true
|
50
88
|
end
|
51
89
|
end
|
90
|
+
|
52
91
|
context 'when other config proxy are not enabled' do
|
53
92
|
it do
|
54
93
|
@config_proxy_enabled = {
|
55
|
-
svn: false,
|
56
94
|
apt: false,
|
57
95
|
chef: false,
|
58
96
|
docker: false,
|
97
|
+
env: true,
|
59
98
|
git: false,
|
60
99
|
npm: false,
|
61
100
|
pear: false,
|
@@ -67,4 +106,66 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureEnvProxy do
|
|
67
106
|
|
68
107
|
end
|
69
108
|
end
|
109
|
+
|
110
|
+
describe "#unconfigure_machine" do
|
111
|
+
let(:app) { lambda { |env| } }
|
112
|
+
let(:env) { Hash.new }
|
113
|
+
let(:machine) { double('machine') }
|
114
|
+
|
115
|
+
context 'when proxy is not enabled' do
|
116
|
+
context "and guest is windows" do
|
117
|
+
subject do
|
118
|
+
conf = described_class.new(app, env)
|
119
|
+
allow(conf).to receive(:windows_guest?).and_return(true)
|
120
|
+
conf.send(:unconfigure_machine)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should raise NotImplementedError' do
|
124
|
+
expect { subject }.to raise_error(NotImplementedError)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "and guest is linux" do
|
129
|
+
subject do
|
130
|
+
conf = described_class.new(app, env)
|
131
|
+
|
132
|
+
# configure test doubles
|
133
|
+
allow(conf).to receive(:windows_guest?).and_return(false)
|
134
|
+
conf.instance_variable_set(:@machine, machine)
|
135
|
+
|
136
|
+
@config[:enabled] = false
|
137
|
+
proxy = create_config_proxy(@config)
|
138
|
+
|
139
|
+
allow(machine).to receive_message_chain(:config, :proxy).and_return(proxy)
|
140
|
+
allow(machine).to receive_message_chain(:config, :public_send).with(:env_proxy).and_return(proxy)
|
141
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f /etc/sudoers.d/proxy")
|
142
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f /etc/profile.d/proxy.sh")
|
143
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f /tmp/vagrant-proxyconf", {:error_check => false})
|
144
|
+
allow(machine).to receive_message_chain(:communicate, :upload)
|
145
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("touch /etc/environment")
|
146
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("sed -e '/^HTTP_PROXY=/ d\n/^HTTPS_PROXY=/ d\n/^FTP_PROXY=/ d\n/^NO_PROXY=/ d\n/^http_proxy=/ d\n/^https_proxy=/ d\n/^ftp_proxy=/ d\n/^no_proxy=/ d\n' -e '/^$/d' /etc/environment > /etc/environment.new")
|
147
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("cat /tmp/vagrant-proxyconf >> /etc/environment.new")
|
148
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("chmod 0644 /etc/environment.new")
|
149
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("chown root:root /etc/environment.new")
|
150
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("mv -f /etc/environment.new /etc/environment")
|
151
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f /tmp/vagrant-proxyconf").and_return("sib")
|
152
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:env_proxy_conf).and_return("/etc/profile.d/proxy.sh")
|
153
|
+
|
154
|
+
conf.send(:unconfigure_machine)
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'should remove file /etc/sudoers.d/proxy, /etc/sudoers.d/proxy.sh and remove configuration from /etc/environment and return true' do
|
158
|
+
@config = {
|
159
|
+
:ftp => 'ftp://foo-proxy.foo-domain.com:8080',
|
160
|
+
:http => nil,
|
161
|
+
:https => 'https://foo-proxy.foo-domain.com:8080',
|
162
|
+
:no_proxy => 'localhost',
|
163
|
+
}
|
164
|
+
|
165
|
+
is_expected.to eq true
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
70
171
|
end
|
@@ -8,4 +8,120 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureGitProxy do
|
|
8
8
|
it { is_expected.to eq 'git_proxy' }
|
9
9
|
end
|
10
10
|
|
11
|
+
describe "#configure_machine" do
|
12
|
+
|
13
|
+
context "when configuration is enabled" do
|
14
|
+
let(:app) { OpenStruct.new }
|
15
|
+
let(:env) { OpenStruct.new }
|
16
|
+
let(:machine) { double('machine') }
|
17
|
+
|
18
|
+
context "when supported" do
|
19
|
+
subject do
|
20
|
+
git_proxy = described_class.new(app, env)
|
21
|
+
git_proxy.instance_variable_set(:@machine, machine)
|
22
|
+
|
23
|
+
config = create_config_proxy(
|
24
|
+
:enabled => true,
|
25
|
+
:http => 'http://proxy-server-01.example.com:8080',
|
26
|
+
:https => 'https://proxy-server-01.example.com:8080',
|
27
|
+
:no_proxy => 'localhost',
|
28
|
+
)
|
29
|
+
|
30
|
+
allow(machine).to receive_message_chain(:config, :proxy).and_return(config)
|
31
|
+
allow(machine).to receive_message_chain(:config, :public_send).with(:git_proxy).and_return(config)
|
32
|
+
|
33
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:git_proxy_conf).and_return(true)
|
34
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:git_proxy_conf).and_return("/usr/bin/git")
|
35
|
+
|
36
|
+
if git_proxy.send(:disabled?)
|
37
|
+
binding.pry
|
38
|
+
else
|
39
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("/usr/bin/git config --system http.proxy http://proxy-server-01.example.com:8080")
|
40
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("/usr/bin/git config --system https.proxy https://proxy-server-01.example.com:8080")
|
41
|
+
end
|
42
|
+
|
43
|
+
git_proxy.send(:configure_machine)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'configures git proxy and returns true' do
|
47
|
+
is_expected.to eq true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "when not supported" do
|
52
|
+
subject do
|
53
|
+
git_proxy = described_class.new(app, env)
|
54
|
+
git_proxy.instance_variable_set(:@machine, machine)
|
55
|
+
|
56
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:git_proxy_conf).and_return(false)
|
57
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:git_proxy_conf).and_return(nil)
|
58
|
+
|
59
|
+
git_proxy.send(:configure_machine)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "does not configure the git proxy and returns nil" do
|
63
|
+
is_expected.to eq nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when configuration is disabled" do
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#unconfigure_machine" do
|
74
|
+
context "when not supported" do
|
75
|
+
let(:app) { OpenStruct.new }
|
76
|
+
let(:env) { OpenStruct.new }
|
77
|
+
let(:machine) { double('machine') }
|
78
|
+
|
79
|
+
subject do
|
80
|
+
git_proxy = described_class.new(app, env)
|
81
|
+
git_proxy.instance_variable_set(:@machine, machine)
|
82
|
+
|
83
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:git_proxy_conf).and_return(false)
|
84
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:git_proxy_conf).and_return(nil)
|
85
|
+
|
86
|
+
git_proxy.send(:unconfigure_machine)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'returns nil' do
|
90
|
+
is_expected.to eq nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "when supported and configuration is disabled" do
|
95
|
+
let(:app) { OpenStruct.new }
|
96
|
+
let(:env) { OpenStruct.new }
|
97
|
+
let(:machine) { double('machine') }
|
98
|
+
|
99
|
+
subject do
|
100
|
+
git_proxy = described_class.new(app, env)
|
101
|
+
git_proxy.instance_variable_set(:@machine, machine)
|
102
|
+
|
103
|
+
config = create_config_proxy(
|
104
|
+
:enabled => false,
|
105
|
+
:http => 'http://proxy-server-01.example.com:8080',
|
106
|
+
:https => 'https://proxy-server-01.example.com:8080',
|
107
|
+
:no_proxy => 'localhost',
|
108
|
+
)
|
109
|
+
|
110
|
+
allow(machine).to receive_message_chain(:config, :proxy).and_return(config)
|
111
|
+
allow(machine).to receive_message_chain(:config, :public_send).with(:git_proxy).and_return(config)
|
112
|
+
|
113
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:git_proxy_conf).and_return(true)
|
114
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:git_proxy_conf).and_return("/usr/bin/git")
|
115
|
+
|
116
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("/usr/bin/git config --system --unset-all http.proxy", error_check: false)
|
117
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("/usr/bin/git config --system --unset-all https.proxy", error_check: false)
|
118
|
+
|
119
|
+
git_proxy.send(:unconfigure_machine)
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'configures git proxy and returns true' do
|
123
|
+
is_expected.to eq true
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
11
127
|
end
|
@@ -7,4 +7,71 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureNpmProxy do
|
|
7
7
|
subject { described_class.new(double, double).config_name }
|
8
8
|
it { is_expected.to eq 'npm_proxy' }
|
9
9
|
end
|
10
|
+
|
11
|
+
describe '#set_or_delete_proxy' do
|
12
|
+
let(:app) { OpenStruct.new }
|
13
|
+
let(:env) { OpenStruct.new }
|
14
|
+
let(:machine) { double('machine') }
|
15
|
+
|
16
|
+
context "when not supported" do
|
17
|
+
subject do
|
18
|
+
npm_proxy = described_class.new(app, env)
|
19
|
+
npm_proxy.instance_variable_set(:@machine, machine)
|
20
|
+
|
21
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:npm_proxy_conf).and_return(false)
|
22
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:npm_proxy_conf).and_return(nil)
|
23
|
+
|
24
|
+
npm_proxy.send(:set_or_delete_proxy, @key, @value)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'return nil' do
|
28
|
+
@key = "proxy"
|
29
|
+
@value = "http://proxy-server-01.example.com:8888"
|
30
|
+
is_expected.to eq nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when supported' do
|
35
|
+
context 'and has value argument' do
|
36
|
+
subject do
|
37
|
+
npm_proxy = described_class.new(app, env)
|
38
|
+
npm_proxy.instance_variable_set(:@machine, machine)
|
39
|
+
|
40
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:npm_proxy_conf).and_return(true)
|
41
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:npm_proxy_conf).and_return("/usr/bin/npm")
|
42
|
+
|
43
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("/usr/bin/npm config --global set #{@key} #{@value}")
|
44
|
+
|
45
|
+
npm_proxy.send(:set_or_delete_proxy, @key, @value)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should set npm config item' do
|
49
|
+
@key = "proxy"
|
50
|
+
@value = "http://proxyserver:8080"
|
51
|
+
is_expected.to eq true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'and does not have value argument' do
|
56
|
+
subject do
|
57
|
+
npm_proxy = described_class.new(app, env)
|
58
|
+
npm_proxy.instance_variable_set(:@machine, machine)
|
59
|
+
|
60
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:npm_proxy_conf).and_return(true)
|
61
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:npm_proxy_conf).and_return("/usr/bin/npm")
|
62
|
+
|
63
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("/usr/bin/npm config --global set #{@key} foo")
|
64
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("/usr/bin/npm config --global delete #{@key}")
|
65
|
+
|
66
|
+
npm_proxy.send(:set_or_delete_proxy, @key, @value)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should delete npm config item' do
|
70
|
+
@key = "proxy"
|
71
|
+
@value = nil
|
72
|
+
is_expected.to eq true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
10
77
|
end
|
@@ -7,4 +7,120 @@ describe VagrantPlugins::ProxyConf::Action::ConfigurePearProxy do
|
|
7
7
|
subject { described_class.new(double, double).config_name }
|
8
8
|
it { is_expected.to eq 'pear_proxy' }
|
9
9
|
end
|
10
|
+
|
11
|
+
describe "#configure_machine" do
|
12
|
+
let(:app) { OpenStruct.new }
|
13
|
+
let(:env) { OpenStruct.new }
|
14
|
+
let(:machine) { double('machine') }
|
15
|
+
|
16
|
+
context "when not supported" do
|
17
|
+
subject do
|
18
|
+
pear_proxy = described_class.new(app, env)
|
19
|
+
pear_proxy.instance_variable_set(:@machine, machine)
|
20
|
+
|
21
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:pear_proxy_conf).and_return(false)
|
22
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:pear_proxy_conf).and_return(nil)
|
23
|
+
|
24
|
+
pear_proxy.send(:configure_machine)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns nil' do
|
28
|
+
is_expected.to eq nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when supported" do
|
33
|
+
subject do
|
34
|
+
pear_proxy = described_class.new(app, env)
|
35
|
+
pear_proxy.instance_variable_set(:@machine, machine)
|
36
|
+
|
37
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:pear_proxy_conf).and_return(true)
|
38
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:pear_proxy_conf).and_return('/usr/bin/pear')
|
39
|
+
|
40
|
+
allow(machine).to receive_message_chain(:config, :proxy).and_return(@config)
|
41
|
+
allow(machine).to receive_message_chain(:config, :public_send).with(:pear_proxy).and_return(@config)
|
42
|
+
|
43
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("/usr/bin/pear config-set http_proxy #{@http_proxy} system")
|
44
|
+
|
45
|
+
pear_proxy.send(:configure_machine)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'and not disabled, sets http proxy to http://proxy:8080' do
|
49
|
+
@config = create_config_proxy(
|
50
|
+
:enabled => true,
|
51
|
+
:http => 'http://proxy:8080',
|
52
|
+
:https => 'https://proxy:8080',
|
53
|
+
:no_proxy => 'localhost',
|
54
|
+
)
|
55
|
+
@http_proxy = "http://proxy:8080"
|
56
|
+
|
57
|
+
is_expected.to eq true
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'and disabled, disables the proxy' do
|
61
|
+
@config = create_config_proxy(
|
62
|
+
:enabled => false,
|
63
|
+
:http => 'http://proxy:8080',
|
64
|
+
:https => 'https://proxy:8080',
|
65
|
+
:no_proxy => 'localhost',
|
66
|
+
)
|
67
|
+
@http_proxy = "''"
|
68
|
+
|
69
|
+
is_expected.to eq true
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#unconfigure_machine" do
|
75
|
+
let(:app) { OpenStruct.new }
|
76
|
+
let(:env) { OpenStruct.new }
|
77
|
+
let(:machine) { double('machine') }
|
78
|
+
|
79
|
+
context "when not supported" do
|
80
|
+
subject do
|
81
|
+
pear_proxy = described_class.new(app, env)
|
82
|
+
pear_proxy.instance_variable_set(:@machine, machine)
|
83
|
+
|
84
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:pear_proxy_conf).and_return(false)
|
85
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:pear_proxy_conf).and_return(nil)
|
86
|
+
|
87
|
+
pear_proxy.send(:unconfigure_machine)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'returns nil' do
|
91
|
+
is_expected.to eq nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "when supported" do
|
96
|
+
subject do
|
97
|
+
pear_proxy = described_class.new(app, env)
|
98
|
+
pear_proxy.instance_variable_set(:@machine, machine)
|
99
|
+
|
100
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:pear_proxy_conf).and_return(true)
|
101
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:pear_proxy_conf).and_return('/usr/bin/pear')
|
102
|
+
|
103
|
+
allow(machine).to receive_message_chain(:config, :proxy).and_return(@config)
|
104
|
+
allow(machine).to receive_message_chain(:config, :public_send).with(:pear_proxy).and_return(@config)
|
105
|
+
|
106
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("/usr/bin/pear config-set http_proxy #{@http_proxy} system")
|
107
|
+
|
108
|
+
pear_proxy.send(:unconfigure_machine)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'disables http proxy' do
|
112
|
+
@config = create_config_proxy(
|
113
|
+
:enabled => false,
|
114
|
+
:http => nil,
|
115
|
+
:https => nil,
|
116
|
+
:no_proxy => nil,
|
117
|
+
)
|
118
|
+
@http_proxy = "''"
|
119
|
+
|
120
|
+
is_expected.to eq true
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
|
10
126
|
end
|