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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +11 -14
  4. data/CHANGELOG.md +38 -0
  5. data/Gemfile +28 -7
  6. data/LICENSE.txt +1 -1
  7. data/README.md +147 -18
  8. data/Rakefile +1 -27
  9. data/development/Dockerfile +45 -0
  10. data/development/README.md +2 -0
  11. data/development/Vagrantfile.example +185 -9
  12. data/development/install-c7.sh +46 -0
  13. data/development/install-debian.sh +55 -0
  14. data/development/tinyproxy.conf +333 -0
  15. data/lib/vagrant-proxyconf/action.rb +15 -7
  16. data/lib/vagrant-proxyconf/action/base.rb +47 -5
  17. data/lib/vagrant-proxyconf/action/configure_apt_proxy.rb +17 -0
  18. data/lib/vagrant-proxyconf/action/configure_chef_proxy.rb +32 -27
  19. data/lib/vagrant-proxyconf/action/configure_docker_proxy.rb +132 -14
  20. data/lib/vagrant-proxyconf/action/configure_env_proxy.rb +58 -11
  21. data/lib/vagrant-proxyconf/action/configure_git_proxy.rb +25 -9
  22. data/lib/vagrant-proxyconf/action/configure_npm_proxy.rb +14 -6
  23. data/lib/vagrant-proxyconf/action/configure_pear_proxy.rb +15 -8
  24. data/lib/vagrant-proxyconf/action/configure_svn_proxy.rb +15 -8
  25. data/lib/vagrant-proxyconf/action/configure_yum_proxy.rb +16 -0
  26. data/lib/vagrant-proxyconf/action/is_enabled.rb +18 -1
  27. data/lib/vagrant-proxyconf/cap/linux/chef_proxy_conf.rb +17 -0
  28. data/lib/vagrant-proxyconf/cap/linux/docker_proxy_conf.rb +2 -1
  29. data/lib/vagrant-proxyconf/cap/linux/yum_proxy_conf.rb +19 -0
  30. data/lib/vagrant-proxyconf/cap/util.rb +4 -5
  31. data/lib/vagrant-proxyconf/capability.rb +10 -0
  32. data/lib/vagrant-proxyconf/config.rb +20 -0
  33. data/lib/vagrant-proxyconf/config/chef_proxy.rb +25 -0
  34. data/lib/vagrant-proxyconf/config/docker_proxy.rb +25 -0
  35. data/lib/vagrant-proxyconf/config/git_proxy.rb +3 -0
  36. data/lib/vagrant-proxyconf/config/npm_proxy.rb +25 -0
  37. data/lib/vagrant-proxyconf/config/pear_proxy.rb +19 -0
  38. data/lib/vagrant-proxyconf/version.rb +1 -1
  39. data/locales/en.yml +38 -0
  40. data/resources/yum_config.awk +1 -0
  41. data/spec/spec_helper.rb +27 -9
  42. data/spec/unit/fixtures/docker_client_config_json_enabled_proxy +9 -0
  43. data/spec/unit/fixtures/docker_client_config_json_no_proxy +5 -0
  44. data/spec/unit/fixtures/etc_environment_only_http_proxy.conf +9 -0
  45. data/spec/unit/fixtures/yum_with_repository_and_proxy_containing_special_chars.conf +10 -0
  46. data/spec/unit/vagrant-proxyconf/action/base_spec.rb +191 -0
  47. data/spec/unit/vagrant-proxyconf/action/configure_apt_proxy_spec.rb +162 -0
  48. data/spec/unit/vagrant-proxyconf/action/configure_chef_proxy_spec.rb +32 -0
  49. data/spec/unit/vagrant-proxyconf/action/configure_docker_proxy_spec.rb +491 -0
  50. data/spec/unit/vagrant-proxyconf/action/configure_env_proxy_spec.rb +105 -4
  51. data/spec/unit/vagrant-proxyconf/action/configure_git_proxy_spec.rb +116 -0
  52. data/spec/unit/vagrant-proxyconf/action/configure_npm_proxy_spec.rb +67 -0
  53. data/spec/unit/vagrant-proxyconf/action/configure_pear_proxy_spec.rb +116 -0
  54. data/spec/unit/vagrant-proxyconf/action/configure_svn_proxy_spec.rb +85 -0
  55. data/spec/unit/vagrant-proxyconf/action/configure_yum_proxy_spec.rb +100 -0
  56. data/spec/unit/vagrant-proxyconf/action/is_enabled_spec.rb +162 -12
  57. data/spec/unit/vagrant-proxyconf/cap/linux/docker_proxy_conf_spec.rb +1 -1
  58. data/spec/unit/vagrant-proxyconf/cap/util_spec.rb +2 -2
  59. data/spec/unit/vagrant-proxyconf/config/key_mixin_spec.rb +1 -1
  60. data/spec/unit/vagrant-proxyconf/resources/yum_config_spec.rb +14 -0
  61. data/test/issues/180/.rspec +2 -0
  62. data/test/issues/180/Dockerfile +47 -0
  63. data/test/issues/180/README.md +31 -0
  64. data/test/issues/180/Rakefile +27 -0
  65. data/test/issues/180/Vagrantfile +31 -0
  66. data/test/issues/180/entrypoint.sh +50 -0
  67. data/test/issues/180/spec/default/redhat_spec.rb +15 -0
  68. data/test/issues/180/spec/docker_host/redhat_spec.rb +165 -0
  69. data/test/issues/180/spec/spec_helper.rb +43 -0
  70. data/test/issues/180/tinyproxy.conf +333 -0
  71. data/travis/before_install +26 -0
  72. metadata +44 -4
@@ -1,6 +1,15 @@
1
1
  require 'spec_helper'
2
2
  require 'vagrant-proxyconf/action/configure_svn_proxy'
3
3
 
4
+ def mock_write_config(machine)
5
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f /tmp/vagrant-proxyconf", error_check: false)
6
+ allow(machine).to receive_message_chain(:communicate, :upload)
7
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("chmod 0644 /tmp/vagrant-proxyconf")
8
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("chown root:root /tmp/vagrant-proxyconf")
9
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("mkdir -p /etc/subversion")
10
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("mv -f /tmp/vagrant-proxyconf /etc/subversion/servers")
11
+ end
12
+
4
13
  describe VagrantPlugins::ProxyConf::Action::ConfigureSvnProxy do
5
14
 
6
15
  describe '#config_name' do
@@ -8,6 +17,82 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureSvnProxy do
8
17
  it { is_expected.to eq 'svn_proxy' }
9
18
  end
10
19
 
20
+ describe "#configure_machine" do
21
+ let(:config) { OpenStruct.new }
22
+ let(:machine) { double('machine') }
23
+
24
+ subject do
25
+ svn_proxy = described_class.new(nil, nil)
26
+ svn_proxy.instance_variable_set(:@machine, machine)
27
+
28
+ allow(svn_proxy).to receive(:config) { config }
29
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:svn_proxy_conf).and_return(@supported)
30
+ allow(machine).to receive_message_chain(:guest, :capability).with(:svn_proxy_conf).and_return(@supported)
31
+
32
+ mock_write_config(machine)
33
+
34
+ svn_proxy.send(:configure_machine)
35
+ end
36
+
37
+ it 'returns nil, when not supported' do
38
+ @supported = false
39
+
40
+ config.http = 'http://some-svn-proxy:8080'
41
+ config.no_proxy = 'localhost'
42
+
43
+ is_expected.to eq nil
44
+ end
45
+
46
+ it 'returns true, when supported' do
47
+ @supported = true
48
+
49
+ config.http = 'http://some-svn-proxy:8080'
50
+ config.no_proxy = 'localhost'
51
+
52
+ is_expected.to eq true
53
+ end
54
+
55
+ end
56
+
57
+ describe "#unconfigure_machine" do
58
+ let(:config) { OpenStruct.new }
59
+ let(:machine) { double('machine') }
60
+
61
+ subject do
62
+ svn_proxy = described_class.new(nil, nil)
63
+ svn_proxy.instance_variable_set(:@machine, machine)
64
+
65
+ allow(svn_proxy).to receive(:config) { config }
66
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:svn_proxy_conf).and_return(@supported)
67
+ allow(machine).to receive_message_chain(:guest, :capability).with(:svn_proxy_conf).and_return(@supported)
68
+
69
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("touch /etc/subversion/servers")
70
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("sed -i.bak -e '/^http-proxy-/d' /etc/subversion/servers")
71
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("chown root:root /etc/subversion/servers")
72
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("chmod 0644 /etc/subversion/servers")
73
+
74
+ svn_proxy.send(:unconfigure_machine)
75
+ end
76
+
77
+ it 'returns nil, when not supported' do
78
+ @supported = false
79
+
80
+ config.http = 'http://some-svn-proxy:8080'
81
+ config.no_proxy = 'localhost'
82
+
83
+ is_expected.to eq nil
84
+ end
85
+
86
+ it 'returns true, when supported' do
87
+ @supported = true
88
+
89
+ config.http = 'http://some-svn-proxy:8080'
90
+ config.no_proxy = 'localhost'
91
+
92
+ is_expected.to eq true
93
+ end
94
+ end
95
+
11
96
  describe '#svn_config' do
12
97
  subject do
13
98
  action = described_class.new(nil, nil)
@@ -41,4 +41,104 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureYumProxy do
41
41
  it { is_expected.to eq %q{-v proxy=http://proxy.com:8080 -v user=foo\% -v pass=abc\#123} }
42
42
  end
43
43
  end
44
+
45
+ describe "#configure_machine" do
46
+ let(:machine) { double('machine') }
47
+ let(:config) { OpenStruct.new }
48
+
49
+ context "when not supported" do
50
+ subject do
51
+ yum_proxy = described_class.new(nil, nil)
52
+ yum_proxy.instance_variable_set(:@machine, machine)
53
+
54
+ allow(yum_proxy).to receive(:config) { config }
55
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:yum_proxy_conf).and_return(false)
56
+ allow(machine).to receive_message_chain(:guest, :capability).with(:yum_proxy_conf).and_return(nil)
57
+
58
+ yum_proxy.send(:configure_machine)
59
+ end
60
+
61
+ it 'returns nil' do
62
+ is_expected.to eq nil
63
+ end
64
+ end
65
+
66
+ context "when supported" do
67
+ subject do
68
+ yum_proxy = described_class.new(nil, nil)
69
+ yum_proxy.instance_variable_set(:@machine, machine)
70
+
71
+ config.http = "http://username:pass@some-yum-proxy-server:8080"
72
+
73
+ allow(yum_proxy).to receive(:config) { config }
74
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:yum_proxy_conf).and_return(true)
75
+ allow(machine).to receive_message_chain(:guest, :capability).with(:yum_proxy_conf).and_return("/etc/yum.conf")
76
+
77
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f /tmp/vagrant-proxyconf", error_check: false)
78
+ allow(machine).to receive_message_chain(:communicate, :upload)
79
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("touch /etc/yum.conf")
80
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("gawk -f /tmp/vagrant-proxyconf -v proxy=http://some-yum-proxy-server:8080 -v user=username -v pass=pass /etc/yum.conf > /etc/yum.conf.new")
81
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("chmod 0644 /etc/yum.conf.new")
82
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("chown root:root /etc/yum.conf.new")
83
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("mv -f /etc/yum.conf.new /etc/yum.conf")
84
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f /tmp/vagrant-proxyconf")
85
+
86
+ yum_proxy.send(:configure_machine)
87
+ end
88
+
89
+ it 'returns true' do
90
+ is_expected.to eq true
91
+ end
92
+
93
+ end
94
+ end
95
+
96
+ describe "#unconfigure_machine" do
97
+ let(:machine) { double('machine') }
98
+ let(:config) { OpenStruct.new }
99
+
100
+ context "when not supported" do
101
+ subject do
102
+ yum_proxy = described_class.new(nil, nil)
103
+ yum_proxy.instance_variable_set(:@machine, machine)
104
+
105
+ allow(yum_proxy).to receive(:config) { config }
106
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:yum_proxy_conf).and_return(false)
107
+ allow(machine).to receive_message_chain(:guest, :capability).with(:yum_proxy_conf).and_return(nil)
108
+
109
+ yum_proxy.send(:unconfigure_machine)
110
+ end
111
+
112
+ it 'returns nil' do
113
+ is_expected.to eq nil
114
+ end
115
+ end
116
+
117
+ context "when supported" do
118
+ subject do
119
+ yum_proxy = described_class.new(nil, nil)
120
+ yum_proxy.instance_variable_set(:@machine, machine)
121
+
122
+ config.proxy = OpenStruct.new
123
+ config.proxy.enabled = false
124
+ config.http = "http://username:pass@some-yum-proxy-server:8080"
125
+
126
+ allow(yum_proxy).to receive(:config) { config }
127
+ allow(machine).to receive(:config) { config }
128
+
129
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:yum_proxy_conf).and_return(true)
130
+ allow(machine).to receive_message_chain(:guest, :capability).with(:yum_proxy_conf).and_return("/etc/yum.conf")
131
+
132
+ allow(machine).to receive_message_chain(:communicate, :test).with("grep '^proxy' /etc/yum.conf").and_return(true)
133
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("sed -i.bak -e '/^proxy/d' /etc/yum.conf")
134
+
135
+ yum_proxy.send(:unconfigure_machine)
136
+ end
137
+
138
+ it 'returns true' do
139
+ is_expected.to eq true
140
+ end
141
+ end
142
+ end
143
+
44
144
  end
@@ -20,26 +20,176 @@ describe VagrantPlugins::ProxyConf::Action::IsEnabled do
20
20
  end
21
21
  end
22
22
 
23
- [false, ''].each do |value|
24
- context "with `config.proxy.enabled=#{value.inspect}`" do
25
- let(:enabled) { value }
23
+ describe "#has_proxy_env_var?" do
24
+ subject do
25
+ is_enabled = described_class.new(app, env)
26
26
 
27
- it "results to falsy" do
28
- described_class.new(app, {}).call(env)
29
- expect(env[:result]).to be_falsey
27
+ is_enabled.send(:has_proxy_env_var?, var)
28
+ end
29
+
30
+ context "when HTTP_PROXY is set in the environment and config.proxy.enabled=true" do
31
+ let(:enabled) { true }
32
+ let(:var) { 'HTTP_PROXY' }
33
+
34
+ before :each do
35
+ ENV[var] = 'http://localhost:8888'
36
+ end
37
+
38
+ after :each do
39
+ ENV[var] = nil
40
+ end
41
+
42
+ it { expect(ENV[var]).to eq 'http://localhost:8888' }
43
+
44
+ it { is_expected.to eq true }
45
+ end
46
+
47
+ context "when HTTPS_PROXY="" is set in the environment and config.proxy.enabled=true" do
48
+ let(:enabled) { true }
49
+ let(:var) { 'HTTPS_PROXY' }
50
+
51
+ before :each do
52
+ ENV[var] = ''
53
+ end
54
+
55
+ after :each do
56
+ ENV[var] = nil
57
+ end
58
+
59
+ it { expect(ENV[var]).to eq '' }
60
+ it { is_expected.to eq false }
61
+ end
62
+
63
+ end
64
+
65
+ describe "#plugin_disabled?" do
66
+
67
+ subject do
68
+ is_enabled = described_class.new(app, env)
69
+ is_enabled.send(:plugin_disabled?, env[:machine].config.proxy)
70
+ end
71
+
72
+ context "given config.proxy.enabled=false" do
73
+ let(:enabled) { false }
74
+
75
+ it { is_expected.to eq true }
76
+ end
77
+
78
+ context "given config.proxy.enabled=''" do
79
+ let(:enabled) { "" }
80
+
81
+ it { is_expected.to eq true }
82
+ end
83
+
84
+ context "given config.proxy.enabled=nil" do
85
+ let(:enabled) { false }
86
+
87
+ it { is_expected.to eq true }
88
+ end
89
+
90
+ context "given config.proxy.enabled={}" do
91
+ let(:enabled) { false }
92
+
93
+ it { is_expected.to eq true }
94
+ end
95
+
96
+ context "given config.proxy.enabled={:foo => 'bar'}" do
97
+ let(:enabled) do
98
+ {:foo => 'bar'}
30
99
  end
100
+
101
+ it { is_expected.to eq false }
102
+ end
103
+
104
+ context "given config.proxy.enabled=true" do
105
+ let(:enabled) { true }
106
+
107
+ it { is_expected.to eq false }
31
108
  end
109
+
110
+ context "given config.proxy.enabled='http://localhost:8080'" do
111
+ let(:enabled) { 'http://localhost:8080' }
112
+
113
+ it { is_expected.to eq false }
114
+ end
115
+
32
116
  end
33
117
 
34
- [nil, true, :auto, 'yes please'].each do |value|
35
- context "with `config.proxy.enabled=#{value.inspect}`" do
36
- let(:enabled) { value }
118
+ describe "#plugin_enabled?" do
119
+ subject do
120
+ is_enabled = described_class.new(app, env)
121
+ is_enabled.send(:plugin_enabled?, env[:machine].config.proxy)
122
+ end
123
+
124
+ context "when config.proxy.enabled=false and ENV['HTTP_PROXY']='http://localhost:8888'" do
125
+ let(:enabled) { false }
126
+ let(:var) { 'HTTP_PROXY' }
127
+
128
+ before :each do
129
+ ENV[var] = 'http://localhost:8888'
130
+ end
37
131
 
38
- it "results to truthy" do
39
- described_class.new(app, {}).call(env)
40
- expect(env[:result]).to be_truthy
132
+ after :each do
133
+ ENV[var] = nil
41
134
  end
135
+
136
+ it { is_expected.to eq false }
42
137
  end
138
+
139
+ end
140
+
141
+ describe "#call" do
142
+ [false, '', {}, nil].each do |value|
143
+ context "with `config.proxy.enabled=#{value.inspect}`" do
144
+ let(:enabled) { value }
145
+
146
+ it "results to falsy" do
147
+ described_class.new(app, {}).call(env)
148
+ expect(env[:result]).to be_falsey
149
+ end
150
+ end
151
+ end
152
+
153
+ [true, :auto, 'yes please', {:foo => 'yes'}].each do |value|
154
+ context "with `config.proxy.enabled=#{value.inspect}` and HTTP_PROXY=http://localhost:8888" do
155
+ let(:enabled) { value }
156
+ let(:var) { 'HTTP_PROXY' }
157
+
158
+ before :each do
159
+ ENV[var] = 'http://localhost:8888'
160
+ end
161
+
162
+ after :each do
163
+ ENV[var] = nil
164
+ end
165
+
166
+ it "results to truthy" do
167
+ described_class.new(app, {}).call(env)
168
+ expect(env[:result]).to be_truthy
169
+ end
170
+ end
171
+ end
172
+
173
+ [true, :auto, 'yes please', {:foo => 'yes'}].each do |value|
174
+ context "with `config.proxy.enabled=#{value.inspect}` and HTTP_PROXY=''" do
175
+ let(:enabled) { value }
176
+ let(:var) { 'HTTP_PROXY' }
177
+
178
+ before :each do
179
+ ENV[var] = ''
180
+ end
181
+
182
+ after :each do
183
+ ENV[var] = nil
184
+ end
185
+
186
+ it "results to truthy" do
187
+ described_class.new(app, {}).call(env)
188
+ expect(env[:result]).to be_falsey
189
+ end
190
+ end
191
+ end
192
+
43
193
  end
44
194
 
45
195
  end
@@ -17,7 +17,7 @@ describe VagrantPlugins::ProxyConf::Cap::Linux::DockerProxyConf do
17
17
  (c == 'docker') ? '/path/to/docker' : false
18
18
  end
19
19
  allow(communicator).to receive(:test) do |c|
20
- c == 'cat /etc/redhat-release'
20
+ c == '[ -f /etc/redhat-release ]'
21
21
  end
22
22
 
23
23
  expect(described_class.docker_proxy_conf(machine)).to eq '/etc/sysconfig/docker'
@@ -13,7 +13,7 @@ describe VagrantPlugins::ProxyConf::Cap::Util do
13
13
 
14
14
  it "returns the path when the command is installed" do
15
15
  expect(communicator).to receive(:execute).
16
- with('which foo', error_check: false).
16
+ with('command -v foo', error_check: false).
17
17
  and_yield(:stdout, "/path/to/foo\n").
18
18
  and_yield(:stdout, "PROMPT\n").
19
19
  and_yield(:stderr, "not foo\n").
@@ -23,7 +23,7 @@ describe VagrantPlugins::ProxyConf::Cap::Util do
23
23
 
24
24
  it "returns false when the command is not installed" do
25
25
  expect(communicator).to receive(:execute).
26
- with('which bar', error_check: false).
26
+ with('command -v bar', error_check: false).
27
27
  and_return(1)
28
28
  expect(described_class.which(machine, 'bar')).to be_falsey
29
29
  end
@@ -9,7 +9,7 @@ describe VagrantPlugins::ProxyConf::Config::KeyMixin do
9
9
  key :bar
10
10
 
11
11
  # Hack to keep rspec 3 description generation happy
12
- def respond_to?(method)
12
+ def respond_to?(method, include_all = false)
13
13
  return false if method == :to_ary
14
14
  super
15
15
  end
@@ -69,6 +69,20 @@ describe 'resources/yum_config.awk' do
69
69
  end
70
70
  end
71
71
 
72
+ context "with old proxy conf containing special characters" do
73
+ let(:old_conf) { 'yum_with_repository_and_proxy_containing_special_chars.conf' }
74
+
75
+ it "replaces existing proxy and userinfo" do
76
+ conf = { proxy: 'http://proxy.example.com:3128/', user: 'foo', pass: 'bar' }
77
+ expect(configure(conf)).to eq fixture('yum_with_repository_and_proxy.conf')
78
+ end
79
+
80
+ it "disables existing proxy" do
81
+ conf = { proxy: '', user: 'baz', pass: 'bar' }
82
+ expect(configure(conf)).to eq fixture('yum_with_repository_and_disabled_proxy.conf')
83
+ end
84
+ end
85
+
72
86
  context "without userinfo" do
73
87
  let(:old_conf) { 'yum_with_repository_and_proxy_without_userinfo.conf' }
74
88