vagrant-proxyconf 1.5.2 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +11 -14
- data/CHANGELOG.md +38 -0
- data/Gemfile +28 -7
- data/LICENSE.txt +1 -1
- data/README.md +147 -18
- data/Rakefile +1 -27
- data/development/Dockerfile +45 -0
- data/development/README.md +2 -0
- data/development/Vagrantfile.example +185 -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 +132 -14
- 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/action/is_enabled.rb +18 -1
- 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 +491 -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/action/is_enabled_spec.rb +162 -12
- 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/test/issues/180/.rspec +2 -0
- data/test/issues/180/Dockerfile +47 -0
- data/test/issues/180/README.md +31 -0
- data/test/issues/180/Rakefile +27 -0
- data/test/issues/180/Vagrantfile +31 -0
- data/test/issues/180/entrypoint.sh +50 -0
- data/test/issues/180/spec/default/redhat_spec.rb +15 -0
- data/test/issues/180/spec/docker_host/redhat_spec.rb +165 -0
- data/test/issues/180/spec/spec_helper.rb +43 -0
- data/test/issues/180/tinyproxy.conf +333 -0
- data/travis/before_install +26 -0
- metadata +44 -4
@@ -7,9 +7,14 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureChefProxy do
|
|
7
7
|
describe '#configure_chef' do
|
8
8
|
let(:chef) { OpenStruct.new }
|
9
9
|
let(:config) { OpenStruct.new }
|
10
|
+
let(:machine) { double('machine') }
|
11
|
+
|
10
12
|
|
11
13
|
def configure_chef
|
12
14
|
action = described_class.new(nil, nil)
|
15
|
+
action.instance_variable_set(:@machine, machine)
|
16
|
+
config.enabled = true if config.enabled.nil?
|
17
|
+
allow(machine).to receive_message_chain(:config, :proxy).and_return(config)
|
13
18
|
allow(action).to receive(:config) { config }
|
14
19
|
action.send(:configure_chef, chef)
|
15
20
|
end
|
@@ -85,6 +90,33 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureChefProxy do
|
|
85
90
|
expect(chef.https_proxy).to eq 'http://sslproxy:3128'
|
86
91
|
end
|
87
92
|
end
|
93
|
+
|
94
|
+
context 'when user wants to disable the configured chef proxy and does not unset the configured proxy variables' do
|
95
|
+
before :each do
|
96
|
+
config.enabled = false
|
97
|
+
config.http = 'http://username:secretpass@my-proxy-host.example.com:8080'
|
98
|
+
config.https = 'https://username:secretpass@my-proxy-host.example.com:8080'
|
99
|
+
config.no_proxy = 'localhost,*.example.com'
|
100
|
+
|
101
|
+
configure_chef
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should unconfigure chef proxy' do
|
105
|
+
expect(config.enabled).to eq false
|
106
|
+
expect(config.http).to eq 'http://username:secretpass@my-proxy-host.example.com:8080'
|
107
|
+
expect(config.https).to eq 'https://username:secretpass@my-proxy-host.example.com:8080'
|
108
|
+
expect(config.no_proxy).to eq 'localhost,*.example.com'
|
109
|
+
|
110
|
+
expect(chef.http_proxy).to be_nil
|
111
|
+
expect(chef.http_proxy_user).to be_nil
|
112
|
+
expect(chef.http_proxy_pass).to be_nil
|
113
|
+
expect(chef.https_proxy).to be_nil
|
114
|
+
expect(chef.https_proxy_user).to be_nil
|
115
|
+
expect(chef.https_proxy_pass).to be_nil
|
116
|
+
expect(chef.no_proxy).to be_nil
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
88
120
|
end
|
89
121
|
|
90
122
|
end
|
@@ -1,10 +1,501 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'vagrant-proxyconf/config/proxy'
|
2
3
|
require 'vagrant-proxyconf/action/configure_docker_proxy'
|
3
4
|
|
5
|
+
def mock_write_docker_config(machine)
|
6
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f /tmp/vagrant-proxyconf", error_check: false)
|
7
|
+
allow(machine).to receive_message_chain(:communicate, :upload)
|
8
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("touch /etc/default/docker")
|
9
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("sed -e '/^HTTP_PROXY=/ d\n/^http_proxy=/ d\n/^HTTPS_PROXY=/ d\n/^https_proxy=/ d\n/^NO_PROXY=/ d\n/^no_proxy=/ d\n' /etc/default/docker > /etc/default/docker.new")
|
10
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("cat /tmp/vagrant-proxyconf >> /etc/default/docker.new")
|
11
|
+
allow(machine).to receive_message_chain(:communicate, :test).with("diff /etc/default/docker.new /etc/default/docker")
|
12
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("chmod 0644 /etc/default/docker.new")
|
13
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("chown root:root /etc/default/docker.new")
|
14
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("mv -f /etc/default/docker.new /etc/default/docker")
|
15
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("kill -HUP `pgrep -f 'docker'` || systemctl restart docker || service docker restart || /etc/init.d/docker restart")
|
16
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f /tmp/vagrant-proxyconf /etc/default/docker.new")
|
17
|
+
end
|
18
|
+
|
19
|
+
def mock_update_docker_client_config(machine)
|
20
|
+
allow(machine).to receive_message_chain(:communicate, :upload)
|
21
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("mv /tmp/vagrant-proxyconf-docker-config.json /etc/docker/config.json")
|
22
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("chown root:root /etc/docker/config.json")
|
23
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f /tmp/vagrant-proxyconf-docker-config.json")
|
24
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("sed -i.bak -e '/^DOCKER_CONFIG/d' /etc/environment")
|
25
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("echo DOCKER_CONFIG=/etc/docker >> /etc/environment")
|
26
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("mkdir -p /etc/docker")
|
27
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("chown root:root /etc/docker")
|
28
|
+
end
|
29
|
+
|
30
|
+
|
4
31
|
describe VagrantPlugins::ProxyConf::Action::ConfigureDockerProxy do
|
5
32
|
|
6
33
|
describe '#config_name' do
|
7
34
|
subject { described_class.new(double, double).config_name }
|
8
35
|
it { is_expected.to eq 'docker_proxy' }
|
9
36
|
end
|
37
|
+
|
38
|
+
describe "#configure_machine" do
|
39
|
+
|
40
|
+
context 'when docker is not supported' do
|
41
|
+
let(:app) { OpenStruct.new }
|
42
|
+
let(:env) { OpenStruct.new }
|
43
|
+
let(:machine) { double('machine') }
|
44
|
+
|
45
|
+
def configure_docker_proxy
|
46
|
+
docker_proxy = described_class.new(app, env)
|
47
|
+
docker_proxy.instance_variable_set(:@machine, machine)
|
48
|
+
|
49
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(false)
|
50
|
+
|
51
|
+
@docker_proxy = docker_proxy
|
52
|
+
end
|
53
|
+
|
54
|
+
before :each do
|
55
|
+
configure_docker_proxy
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'return nil' do
|
59
|
+
expect(@docker_proxy.send(:configure_machine)).to be_nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "when docker is supported" do
|
64
|
+
let(:app) { OpenStruct.new }
|
65
|
+
let(:env) { OpenStruct.new }
|
66
|
+
let(:machine) { double('machine') }
|
67
|
+
|
68
|
+
def configure_docker_proxy(fixture)
|
69
|
+
docker_proxy = described_class.new(app, env)
|
70
|
+
docker_proxy.instance_variable_set(:@machine, machine)
|
71
|
+
|
72
|
+
# #docker_client_config_path mock
|
73
|
+
fixture = docker_proxy.send(:tempfile, load_fixture(fixture)).path
|
74
|
+
docker_proxy.instance_variable_set(:@docker_client_config_path, fixture)
|
75
|
+
|
76
|
+
# #supported? mock
|
77
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(true)
|
78
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return('/etc/default/docker')
|
79
|
+
|
80
|
+
# #config mock
|
81
|
+
config = create_config_proxy(
|
82
|
+
:enabled => true,
|
83
|
+
:http => 'http://proxy-server-01.example.com:8080',
|
84
|
+
:https => 'https://proxy-server-01.example.com:8080',
|
85
|
+
:no_proxy => 'localhost',
|
86
|
+
)
|
87
|
+
|
88
|
+
allow(machine).to receive_message_chain(:config, :proxy).and_return(config)
|
89
|
+
allow(machine).to receive_message_chain(:config, :public_send).with(:docker_proxy).and_return(config)
|
90
|
+
|
91
|
+
mock_write_docker_config(machine)
|
92
|
+
mock_update_docker_client_config(machine)
|
93
|
+
|
94
|
+
# update_docker_client_config mock
|
95
|
+
allow(docker_proxy).to receive(:supports_config_json?).and_return(true)
|
96
|
+
|
97
|
+
@docker_proxy = docker_proxy
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'and when /etc/docker/config.json has proxy configuration' do
|
101
|
+
before :each do
|
102
|
+
fixture = fixture_file("docker_client_config_json_enabled_proxy")
|
103
|
+
configure_docker_proxy(fixture)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'update /etc/docker/config.json' do
|
107
|
+
allow(machine).to receive_message_chain(:communicate, :test).with('command -v systemctl').and_return('')
|
108
|
+
|
109
|
+
expect(@docker_proxy.send(:configure_machine)).to eq true
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "#docker_client_config_path" do
|
116
|
+
let(:machine) { double('machine') }
|
117
|
+
|
118
|
+
context "when not supported" do
|
119
|
+
subject do
|
120
|
+
docker_proxy = described_class.new(nil, nil)
|
121
|
+
docker_proxy.instance_variable_set(:@machine, machine)
|
122
|
+
|
123
|
+
allow(docker_proxy).to receive(:supports_config_json?).and_return(false)
|
124
|
+
|
125
|
+
# #supported? mock
|
126
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(true)
|
127
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return('/etc/default/docker')
|
128
|
+
|
129
|
+
docker_proxy.send(:docker_client_config_path)
|
130
|
+
end
|
131
|
+
|
132
|
+
it { is_expected.to eq nil }
|
133
|
+
end
|
134
|
+
|
135
|
+
context "when supported" do
|
136
|
+
context "when /etc/docker/config.json exists" do
|
137
|
+
subject do
|
138
|
+
docker_proxy = described_class.new(nil, nil)
|
139
|
+
docker_proxy.instance_variable_set(:@machine, machine)
|
140
|
+
docker_proxy.instance_variable_set(:@docker_client_config_path, nil)
|
141
|
+
|
142
|
+
allow(docker_proxy).to receive(:supports_config_json?).and_return(true)
|
143
|
+
|
144
|
+
allow(machine).to receive_message_chain(:communicate, :test).with("[ -f /etc/docker/config.json ]").and_return(true)
|
145
|
+
allow(machine).to receive_message_chain(:communicate, :sudo).with("chmod 0644 /etc/docker/config.json")
|
146
|
+
allow(machine).to receive_message_chain(:communicate, :download)
|
147
|
+
|
148
|
+
docker_proxy.send(:docker_client_config_path)
|
149
|
+
end
|
150
|
+
|
151
|
+
it { expect(File.exists?(subject)).to eq true }
|
152
|
+
end
|
153
|
+
|
154
|
+
context "when /etc/docker/config.json does not exist" do
|
155
|
+
subject do
|
156
|
+
docker_proxy = described_class.new(nil, nil)
|
157
|
+
docker_proxy.instance_variable_set(:@machine, machine)
|
158
|
+
docker_proxy.instance_variable_set(:@docker_client_config_path, nil)
|
159
|
+
|
160
|
+
allow(docker_proxy).to receive(:supports_config_json?).and_return(true)
|
161
|
+
|
162
|
+
allow(machine).to receive_message_chain(:communicate, :test).with("[ -f /etc/docker/config.json ]").and_return(false)
|
163
|
+
|
164
|
+
docker_proxy.send(:docker_client_config_path)
|
165
|
+
end
|
166
|
+
|
167
|
+
it do
|
168
|
+
expect(File.exists?(subject)).to eq true
|
169
|
+
expect(File.read(subject)).to eq "{}"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "#update_docker_client_config" do
|
176
|
+
let(:app) { OpenStruct.new }
|
177
|
+
let(:env) { OpenStruct.new }
|
178
|
+
let(:machine) { double('machine') }
|
179
|
+
|
180
|
+
context "when #supports_config_json? returns false" do
|
181
|
+
|
182
|
+
it 'return nil' do
|
183
|
+
docker_proxy = described_class.new(app, env)
|
184
|
+
docker_proxy.instance_variable_set(:@machine, machine)
|
185
|
+
|
186
|
+
allow(docker_proxy).to receive(:supports_config_json?).and_return(false)
|
187
|
+
|
188
|
+
# #supported? mock
|
189
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(true)
|
190
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return('/etc/default/docker')
|
191
|
+
|
192
|
+
expect(docker_proxy.send(:update_docker_client_config)).to eq nil
|
193
|
+
end
|
194
|
+
|
195
|
+
end
|
196
|
+
|
197
|
+
context "when #docker_client_config_path returns nil" do
|
198
|
+
it 'return nil' do
|
199
|
+
docker_proxy = described_class.new(app, env)
|
200
|
+
docker_proxy.instance_variable_set(:@machine, machine)
|
201
|
+
|
202
|
+
# mock a result that looks like no proxy is configured for the config.json
|
203
|
+
allow(docker_proxy).to receive(:supports_config_json?).and_return(true)
|
204
|
+
allow(docker_proxy).to receive(:docker_client_config_path).and_return(nil)
|
205
|
+
|
206
|
+
# #supported? mock
|
207
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(true)
|
208
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return('/etc/default/docker')
|
209
|
+
|
210
|
+
expect(docker_proxy.send(:update_docker_client_config)).to eq nil
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
context "when /etc/docker/config.json is supported" do
|
215
|
+
|
216
|
+
context "when configuration is disabled" do
|
217
|
+
it do
|
218
|
+
docker_proxy = described_class.new(app, env)
|
219
|
+
docker_proxy.instance_variable_set(:@machine, machine)
|
220
|
+
|
221
|
+
# mock a result that looks like proxy is configured for the config.json
|
222
|
+
fixture = fixture_file("docker_client_config_json_enabled_proxy")
|
223
|
+
fixture_content = load_fixture(fixture)
|
224
|
+
config_path = docker_proxy.send(:tempfile, fixture_content).path
|
225
|
+
|
226
|
+
docker_proxy.instance_variable_set(:@docker_client_config_path, config_path)
|
227
|
+
|
228
|
+
allow(docker_proxy).to receive(:supports_config_json?).and_return(true)
|
229
|
+
allow(docker_proxy).to receive(:disabled?).and_return(true)
|
230
|
+
|
231
|
+
mock_update_docker_client_config(machine)
|
232
|
+
|
233
|
+
expected = JSON.pretty_generate(
|
234
|
+
{
|
235
|
+
"proxies" => {
|
236
|
+
"default" => Hash.new
|
237
|
+
}
|
238
|
+
}
|
239
|
+
)
|
240
|
+
expect(docker_proxy.send(:update_docker_client_config)).to eq expected
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
context "when configuration is enabled" do
|
245
|
+
it do
|
246
|
+
docker_proxy = described_class.new(app, env)
|
247
|
+
docker_proxy.instance_variable_set(:@machine, machine)
|
248
|
+
|
249
|
+
# simulate config
|
250
|
+
config = create_config_proxy(
|
251
|
+
:enabled => true,
|
252
|
+
:http => 'http://proxy-server-01.example.com:8080',
|
253
|
+
:https => 'https://proxy-server-01.example.com:8080',
|
254
|
+
:no_proxy => 'localhost',
|
255
|
+
)
|
256
|
+
|
257
|
+
allow(machine).to receive_message_chain(:config, :proxy).and_return(config)
|
258
|
+
allow(machine).to receive_message_chain(:config, :public_send).with(:docker_proxy).and_return(config)
|
259
|
+
|
260
|
+
# mock a result that looks like no proxy is configured for the config.json
|
261
|
+
fixture = fixture_file("docker_client_config_json_no_proxy")
|
262
|
+
fixture_content = load_fixture(fixture)
|
263
|
+
config_path = docker_proxy.send(:tempfile, fixture_content).path
|
264
|
+
|
265
|
+
docker_proxy.instance_variable_set(:@docker_client_config_path, config_path)
|
266
|
+
|
267
|
+
allow(docker_proxy).to receive(:supports_config_json?).and_return(true)
|
268
|
+
allow(docker_proxy).to receive(:disabled?).and_return(false)
|
269
|
+
|
270
|
+
mock_update_docker_client_config(machine)
|
271
|
+
expected = JSON.pretty_generate(
|
272
|
+
{
|
273
|
+
"proxies" => {
|
274
|
+
"default" => {
|
275
|
+
"httpProxy" => "http://proxy-server-01.example.com:8080",
|
276
|
+
"httpsProxy" => "https://proxy-server-01.example.com:8080",
|
277
|
+
"noProxy" => "localhost",
|
278
|
+
}
|
279
|
+
}
|
280
|
+
}
|
281
|
+
)
|
282
|
+
|
283
|
+
expect(docker_proxy.send(:update_docker_client_config)).to eq expected
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
describe "#unconfigure_machine" do
|
290
|
+
|
291
|
+
context "when not supported" do
|
292
|
+
let(:app) { OpenStruct.new }
|
293
|
+
let(:env) { OpenStruct.new }
|
294
|
+
let(:machine) { double('machine') }
|
295
|
+
|
296
|
+
subject do
|
297
|
+
docker_proxy = described_class.new(app, env)
|
298
|
+
docker_proxy.instance_variable_set(:@machine, machine)
|
299
|
+
|
300
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(false)
|
301
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return(nil)
|
302
|
+
|
303
|
+
docker_proxy.send(:unconfigure_machine)
|
304
|
+
end
|
305
|
+
|
306
|
+
it 'return nil' do
|
307
|
+
is_expected.to eq nil
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
context "when supported" do
|
312
|
+
context "when config is enabled" do
|
313
|
+
let(:app) { OpenStruct.new }
|
314
|
+
let(:env) { OpenStruct.new }
|
315
|
+
let(:machine) { double('machine') }
|
316
|
+
|
317
|
+
subject do
|
318
|
+
docker_proxy = described_class.new(app, env)
|
319
|
+
docker_proxy.instance_variable_set(:@machine, machine)
|
320
|
+
docker_proxy.instance_variable_set(:@version, [18, 9, 0])
|
321
|
+
|
322
|
+
fixture = fixture_file("docker_client_config_json_enabled_proxy")
|
323
|
+
config_path = docker_proxy.send(:tempfile, load_fixture(fixture)).path
|
324
|
+
docker_proxy.instance_variable_set(:@docker_client_config_path, config_path)
|
325
|
+
|
326
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(true)
|
327
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return('/etc/default/docker')
|
328
|
+
|
329
|
+
# #config mock
|
330
|
+
allow(machine).to receive_message_chain(:config, :proxy, :enabled).and_return(true)
|
331
|
+
config = create_config_proxy(
|
332
|
+
:enabled => true,
|
333
|
+
:http => 'http://proxy-server-01.example.com:8080',
|
334
|
+
:https => 'https://proxy-server-01.example.com:8080',
|
335
|
+
:no_proxy => 'localhost',
|
336
|
+
)
|
337
|
+
allow(machine).to receive_message_chain(:config, :proxy).and_return(config)
|
338
|
+
allow(machine).to receive_message_chain(:config, :public_send).with(:docker_proxy).and_return(config)
|
339
|
+
|
340
|
+
# mock write_docker_config
|
341
|
+
mock_write_docker_config(machine)
|
342
|
+
|
343
|
+
# mock update_docker_client_config
|
344
|
+
mock_update_docker_client_config(machine)
|
345
|
+
|
346
|
+
docker_proxy.send(:unconfigure_machine)
|
347
|
+
end
|
348
|
+
|
349
|
+
it 'return true' do
|
350
|
+
is_expected.to eq true
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
context "when config is disabled" do
|
355
|
+
let(:app) { OpenStruct.new }
|
356
|
+
let(:env) { OpenStruct.new }
|
357
|
+
let(:machine) { double('machine') }
|
358
|
+
|
359
|
+
subject do
|
360
|
+
docker_proxy = described_class.new(app, env)
|
361
|
+
docker_proxy.instance_variable_set(:@machine, machine)
|
362
|
+
docker_proxy.instance_variable_set(:@version, [18, 9, 0])
|
363
|
+
|
364
|
+
fixture = fixture_file("docker_client_config_json_enabled_proxy")
|
365
|
+
config_path = docker_proxy.send(:tempfile, load_fixture(fixture)).path
|
366
|
+
docker_proxy.instance_variable_set(:@docker_client_config_path, config_path)
|
367
|
+
|
368
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(true)
|
369
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return('/etc/default/docker')
|
370
|
+
|
371
|
+
# #config mock
|
372
|
+
allow(machine).to receive_message_chain(:config, :proxy, :enabled?).and_return(false)
|
373
|
+
config = create_config_proxy(
|
374
|
+
:enabled => false,
|
375
|
+
:http => 'http://proxy-server-01.example.com:8080',
|
376
|
+
:https => 'https://proxy-server-01.example.com:8080',
|
377
|
+
:no_proxy => 'localhost',
|
378
|
+
)
|
379
|
+
allow(machine).to receive_message_chain(:config, :proxy).and_return(config)
|
380
|
+
allow(machine).to receive_message_chain(:config, :public_send).with(:docker_proxy).and_return(config)
|
381
|
+
|
382
|
+
allow(docker_proxy).to receive(:disabled?).and_return(true)
|
383
|
+
|
384
|
+
mock_write_docker_config(machine)
|
385
|
+
mock_update_docker_client_config(machine)
|
386
|
+
|
387
|
+
docker_proxy.send(:unconfigure_machine)
|
388
|
+
end
|
389
|
+
|
390
|
+
it 'should disable proxy configuration' do
|
391
|
+
is_expected.to eq true
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
describe "#docker_version" do
|
399
|
+
let(:machine) { double('machine') }
|
400
|
+
|
401
|
+
context "when not supported" do
|
402
|
+
subject do
|
403
|
+
docker_proxy = described_class.new(nil, nil)
|
404
|
+
docker_proxy.instance_variable_set(:@machine, machine)
|
405
|
+
|
406
|
+
# #supported? mock
|
407
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(false)
|
408
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return(nil)
|
409
|
+
|
410
|
+
docker_proxy.send(:docker_version)
|
411
|
+
end
|
412
|
+
|
413
|
+
it { is_expected.to eq nil }
|
414
|
+
end
|
415
|
+
|
416
|
+
context "when supported parse" do
|
417
|
+
subject do
|
418
|
+
docker_proxy = described_class.new(nil, nil)
|
419
|
+
docker_proxy.instance_variable_set(:@machine, machine)
|
420
|
+
|
421
|
+
# #supported? mock
|
422
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(true)
|
423
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return("/etc/default/docker")
|
424
|
+
|
425
|
+
allow(machine).to receive_message_chain(:communicate, :execute).with('docker --version').and_yield(@type, @version)
|
426
|
+
|
427
|
+
docker_proxy.send(:docker_version)
|
428
|
+
end
|
429
|
+
|
430
|
+
context '"Docker version 17.05.0-ce, build 89658be"' do
|
431
|
+
it do
|
432
|
+
@type = :stdout
|
433
|
+
@version = "Docker version 17.05.0-ce, build 89658be"
|
434
|
+
|
435
|
+
is_expected.to eq [17, 5, 0]
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
context '"Docker version 18.09.0, build 4d60db4"' do
|
440
|
+
it do
|
441
|
+
@type = :stdout
|
442
|
+
@version = "Docker version 18.09.0, build 4d60db4"
|
443
|
+
|
444
|
+
is_expected.to eq [18, 9, 0]
|
445
|
+
end
|
446
|
+
end
|
447
|
+
end
|
448
|
+
end
|
449
|
+
|
450
|
+
describe "#supports_config_json?" do
|
451
|
+
let(:machine) { double('machine') }
|
452
|
+
|
453
|
+
context "when not supported" do
|
454
|
+
subject do
|
455
|
+
docker_proxy = described_class.new(nil, nil)
|
456
|
+
docker_proxy.instance_variable_set(:@machine, machine)
|
457
|
+
|
458
|
+
# #supported? mock
|
459
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(false)
|
460
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return(nil)
|
461
|
+
|
462
|
+
docker_proxy.send(:supports_config_json?)
|
463
|
+
end
|
464
|
+
|
465
|
+
it 'returns false' do
|
466
|
+
is_expected.to eq false
|
467
|
+
end
|
468
|
+
end
|
469
|
+
|
470
|
+
context "when supported" do
|
471
|
+
subject do
|
472
|
+
docker_proxy = described_class.new(nil, nil)
|
473
|
+
docker_proxy.instance_variable_set(:@machine, machine)
|
474
|
+
docker_proxy.instance_variable_set(:@version, @version)
|
475
|
+
|
476
|
+
# #supported? mock
|
477
|
+
allow(machine).to receive_message_chain(:guest, :capability?).with(:docker_proxy_conf).and_return(true)
|
478
|
+
allow(machine).to receive_message_chain(:guest, :capability).with(:docker_proxy_conf).and_return("/etc/defualt/docker")
|
479
|
+
|
480
|
+
docker_proxy.send(:supports_config_json?)
|
481
|
+
end
|
482
|
+
|
483
|
+
it 'given docker_version is 18.09.1, return true' do
|
484
|
+
@version = [18, 9, 1]
|
485
|
+
is_expected.to eq true
|
486
|
+
end
|
487
|
+
|
488
|
+
it 'given docker_version is 17.07, return true' do
|
489
|
+
@version = [17, 7, 0]
|
490
|
+
is_expected.to eq true
|
491
|
+
end
|
492
|
+
|
493
|
+
it 'given docker_version is 17.06, return false' do
|
494
|
+
@version = [17, 6, 0]
|
495
|
+
is_expected.to eq false
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
end
|
500
|
+
|
10
501
|
end
|