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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +15 -14
  4. data/CHANGELOG.md +19 -0
  5. data/Gemfile +25 -7
  6. data/LICENSE.txt +1 -1
  7. data/README.md +117 -18
  8. data/Rakefile +1 -27
  9. data/development/Dockerfile +40 -0
  10. data/development/README.md +2 -0
  11. data/development/Vagrantfile.example +156 -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 +113 -12
  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/cap/linux/chef_proxy_conf.rb +17 -0
  27. data/lib/vagrant-proxyconf/cap/linux/docker_proxy_conf.rb +2 -1
  28. data/lib/vagrant-proxyconf/cap/linux/yum_proxy_conf.rb +19 -0
  29. data/lib/vagrant-proxyconf/cap/util.rb +4 -5
  30. data/lib/vagrant-proxyconf/capability.rb +10 -0
  31. data/lib/vagrant-proxyconf/config.rb +20 -0
  32. data/lib/vagrant-proxyconf/config/chef_proxy.rb +25 -0
  33. data/lib/vagrant-proxyconf/config/docker_proxy.rb +25 -0
  34. data/lib/vagrant-proxyconf/config/git_proxy.rb +3 -0
  35. data/lib/vagrant-proxyconf/config/npm_proxy.rb +25 -0
  36. data/lib/vagrant-proxyconf/config/pear_proxy.rb +19 -0
  37. data/lib/vagrant-proxyconf/version.rb +1 -1
  38. data/locales/en.yml +38 -0
  39. data/resources/yum_config.awk +1 -0
  40. data/spec/spec_helper.rb +27 -9
  41. data/spec/unit/fixtures/docker_client_config_json_enabled_proxy +9 -0
  42. data/spec/unit/fixtures/docker_client_config_json_no_proxy +5 -0
  43. data/spec/unit/fixtures/etc_environment_only_http_proxy.conf +9 -0
  44. data/spec/unit/fixtures/yum_with_repository_and_proxy_containing_special_chars.conf +10 -0
  45. data/spec/unit/vagrant-proxyconf/action/base_spec.rb +191 -0
  46. data/spec/unit/vagrant-proxyconf/action/configure_apt_proxy_spec.rb +162 -0
  47. data/spec/unit/vagrant-proxyconf/action/configure_chef_proxy_spec.rb +32 -0
  48. data/spec/unit/vagrant-proxyconf/action/configure_docker_proxy_spec.rb +489 -0
  49. data/spec/unit/vagrant-proxyconf/action/configure_env_proxy_spec.rb +105 -4
  50. data/spec/unit/vagrant-proxyconf/action/configure_git_proxy_spec.rb +116 -0
  51. data/spec/unit/vagrant-proxyconf/action/configure_npm_proxy_spec.rb +67 -0
  52. data/spec/unit/vagrant-proxyconf/action/configure_pear_proxy_spec.rb +116 -0
  53. data/spec/unit/vagrant-proxyconf/action/configure_svn_proxy_spec.rb +85 -0
  54. data/spec/unit/vagrant-proxyconf/action/configure_yum_proxy_spec.rb +100 -0
  55. data/spec/unit/vagrant-proxyconf/cap/linux/docker_proxy_conf_spec.rb +1 -1
  56. data/spec/unit/vagrant-proxyconf/cap/util_spec.rb +2 -2
  57. data/spec/unit/vagrant-proxyconf/config/key_mixin_spec.rb +1 -1
  58. data/spec/unit/vagrant-proxyconf/resources/yum_config_spec.rb +14 -0
  59. data/travis/before_install +26 -0
  60. metadata +24 -4
@@ -39,6 +39,7 @@ BEGIN {
39
39
  $1 ~ /^proxy(_username|_password)?$/ {
40
40
  if (main == 1) {
41
41
  $2 = conf[$1]
42
+ NF = 2
42
43
  seen[$1] = 1
43
44
  }
44
45
  }
@@ -1,14 +1,31 @@
1
1
  require 'rspec/its'
2
+ require 'vagrant-proxyconf/config/proxy'
2
3
 
3
- require 'simplecov'
4
- require 'coveralls'
5
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
- SimpleCov::Formatter::HTMLFormatter,
7
- Coveralls::SimpleCov::Formatter
8
- ]
9
- SimpleCov.start do
10
- coverage_dir('tmp/coverage')
11
- add_filter '/spec/'
4
+ PROJECT_DIR = File.absolute_path(__dir__)
5
+
6
+ def fixture_file(filename)
7
+ File.join([PROJECT_DIR, "unit", "fixtures", filename])
8
+ end
9
+
10
+ def load_fixture(filename)
11
+ File.read(filename)
12
+ end
13
+
14
+ def create_config_proxy(config={})
15
+ config[:enabled] = true unless config.has_key?(:enabled)
16
+ config[:ftp] ||= nil
17
+ config[:http] ||= nil
18
+ config[:https] ||= nil
19
+ config[:no_proxy] ||= nil
20
+
21
+ proxy = VagrantPlugins::ProxyConf::Config::Proxy.new
22
+
23
+ # configure proxy
24
+ config.each do |key, value|
25
+ proxy.instance_variable_set("@#{key}", value)
26
+ end
27
+
28
+ proxy
12
29
  end
13
30
 
14
31
  RSpec.configure do |config|
@@ -17,4 +34,5 @@ RSpec.configure do |config|
17
34
  end
18
35
  config.color = true
19
36
  config.tty = true
37
+ config.formatter = :documentation
20
38
  end
@@ -0,0 +1,9 @@
1
+ {
2
+ "proxies": {
3
+ "default": {
4
+ "httpProxy": "http://proxy-server-01.example.com:8080",
5
+ "httpsProxy": "https://proxy-server-01.example.com:8080",
6
+ "noProxy": "localhost,*.example.com,.example.com"
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "proxies": {
3
+ "default": {}
4
+ }
5
+ }
@@ -0,0 +1,9 @@
1
+ PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
2
+ HTTP_PROXY=http://192.168.33.200:8080
3
+ HTTPS_PROXY=
4
+ FTP_PROXY=
5
+ NO_PROXY=
6
+ http_proxy=http://192.168.33.200:8080
7
+ https_proxy=
8
+ ftp_proxy=
9
+ no_proxy=
@@ -0,0 +1,10 @@
1
+ [main]
2
+ debuglevel=2
3
+ plugins=1
4
+ proxy=http://proxy.example.com:3128/
5
+ proxy_username=foo
6
+ proxy_password=bar=baz
7
+ [myrepo]
8
+ name=My Repository
9
+ baseurl=http://myrepo/somewhere
10
+ proxy=http://repoproxy:8080
@@ -0,0 +1,191 @@
1
+ require 'spec_helper'
2
+ require 'vagrant-proxyconf/action/base'
3
+ require 'vagrant-proxyconf/action/configure_apt_proxy'
4
+
5
+ class MyBase < VagrantPlugins::ProxyConf::Action::Base
6
+
7
+ def config_name
8
+ 'my_base'
9
+ end
10
+
11
+ private
12
+
13
+ def configure_machine
14
+ end
15
+
16
+ def unconfigure_machine
17
+ end
18
+
19
+ end
20
+
21
+ def create_base(machine, env)
22
+ base = MyBase.new(nil, env)
23
+ base.instance_variable_set(:@machine, machine)
24
+
25
+ expect(base.config_name).to eq 'my_base'
26
+
27
+ base
28
+ end
29
+
30
+ describe MyBase do
31
+ let(:machine) { double('machine') }
32
+
33
+ describe "#skip?" do
34
+ let(:config) { OpenStruct.new }
35
+ let(:env) { OpenStruct.new }
36
+
37
+ subject do
38
+ base = create_base(machine, env)
39
+ allow(machine).to receive_message_chain(:config, :proxy) { config }
40
+
41
+ base.send(:skip?)
42
+ end
43
+
44
+ context "when attempting to configure a app proxy that is not defined" do
45
+ before(:each) do
46
+ config.enabled = {:foobar => false}
47
+ config.http = 'http://foo-proxy-server:8080'
48
+ config.https = 'http://foo-prxoy-server:8080'
49
+ config.ftp = 'ftp://foo-proxy-server:8080'
50
+ end
51
+
52
+ it { is_expected.to eq false }
53
+ end
54
+
55
+ context "when config.proxy.enabled[:my_base] = false" do
56
+ before(:each) do
57
+ config.enabled = {:my_base => false}
58
+ config.http = 'http://foo-proxy-server:8080'
59
+ config.https = 'http://foo-prxoy-server:8080'
60
+ config.ftp = 'ftp://foo-proxy-server:8080'
61
+ end
62
+
63
+ it { is_expected.to eq true }
64
+ end
65
+
66
+ context "when config.proxy.enabled[:my_base] = true" do
67
+ before(:each) do
68
+ config.enabled = {:my_base => true}
69
+ config.http = 'http://foo-proxy-server:8080'
70
+ config.https = 'http://foo-prxoy-server:8080'
71
+ config.ftp = 'ftp://foo-proxy-server:8080'
72
+ end
73
+
74
+ it { is_expected.to eq false }
75
+ end
76
+
77
+ context "when config.proxy.enabled[:my_base] = {}" do
78
+ before(:each) do
79
+ config.enabled = {}
80
+ config.http = 'http://foo-proxy-server:8080'
81
+ config.https = 'http://foo-prxoy-server:8080'
82
+ config.ftp = 'ftp://foo-proxy-server:8080'
83
+ end
84
+
85
+ it { is_expected.to eq false }
86
+ end
87
+
88
+
89
+ context "when config.proxy.enabled[:my_base] = {:enabled => false, :skip => false}" do
90
+ before(:each) do
91
+ config.enabled = {
92
+ :my_base => {
93
+ :enabled => false,
94
+ :skip => false,
95
+ }
96
+ }
97
+ config.http = 'http://foo-proxy-server:8080'
98
+ config.https = 'http://foo-prxoy-server:8080'
99
+ config.ftp = 'ftp://foo-proxy-server:8080'
100
+ end
101
+
102
+ it { is_expected.to eq false }
103
+ end
104
+
105
+ context "when config.proxy.enabled[:my_base] = {:enabled => true, :skip => false}" do
106
+ before(:each) do
107
+ config.enabled = {
108
+ :my_base => {
109
+ :enabled => true,
110
+ :skip => false,
111
+ }
112
+ }
113
+ config.http = 'http://foo-proxy-server:8080'
114
+ config.https = 'http://foo-prxoy-server:8080'
115
+ config.ftp = 'ftp://foo-proxy-server:8080'
116
+ end
117
+
118
+ it { is_expected.to eq false }
119
+ end
120
+
121
+ context "when config.proxy.enabled[:my_base] = {:enabled => true, :skip => true}" do
122
+ before(:each) do
123
+ config.enabled = {
124
+ :my_base => {
125
+ :enabled => true,
126
+ :skip => true,
127
+ }
128
+ }
129
+ config.http = 'http://foo-proxy-server:8080'
130
+ config.https = 'http://foo-prxoy-server:8080'
131
+ config.ftp = 'ftp://foo-proxy-server:8080'
132
+ end
133
+
134
+ it { is_expected.to eq true }
135
+ end
136
+
137
+ context "when config.proxy.enabled[:my_base] = {:enabled => false, :skip => true}" do
138
+ before(:each) do
139
+ config.enabled = {
140
+ :my_base => {
141
+ :enabled => false,
142
+ :skip => true,
143
+ }
144
+ }
145
+ config.http = 'http://foo-proxy-server:8080'
146
+ config.https = 'http://foo-prxoy-server:8080'
147
+ config.ftp = 'ftp://foo-proxy-server:8080'
148
+ end
149
+
150
+ it { is_expected.to eq true }
151
+ end
152
+
153
+ context "when config.proxy.enabled = false" do
154
+ before(:each) do
155
+ config.enabled = false
156
+ config.http = 'http://foo-proxy-server:8080'
157
+ config.https = 'http://foo-prxoy-server:8080'
158
+ config.ftp = 'ftp://foo-proxy-server:8080'
159
+ end
160
+
161
+ it { is_expected.to eq true }
162
+ end
163
+
164
+ context "when config.proxy.enabled = true " do
165
+ before(:each) do
166
+ config.enabled = true
167
+ config.http = 'http://foo-proxy-server:8080'
168
+ config.https = 'http://foo-prxoy-server:8080'
169
+ config.ftp = 'ftp://foo-proxy-server:8080'
170
+ end
171
+
172
+ it { is_expected.to eq false }
173
+ end
174
+
175
+ context "when config.proxy.enable[:my_base] = {:enabled => true} and :skip key is missing" do
176
+ before(:each) do
177
+ config.enabled = {
178
+ :my_base => {
179
+ :enabled => false,
180
+ },
181
+ }
182
+ config.http = 'http://foo-proxy-server:8080'
183
+ config.https = 'http://foo-prxoy-server:8080'
184
+ config.ftp = 'ftp://foo-proxy-server:8080'
185
+ end
186
+
187
+ it { is_expected.to eq false }
188
+ end
189
+ end
190
+
191
+ end
@@ -8,4 +8,166 @@ describe VagrantPlugins::ProxyConf::Action::ConfigureAptProxy do
8
8
  it { is_expected.to eq 'apt_proxy' }
9
9
  end
10
10
 
11
+ describe "#unconfigure_machine" do
12
+ let(:app) { lambda { |env| } }
13
+ let(:env) { Hash.new }
14
+ let(:machine) { double('machine') }
15
+
16
+ context 'when proxy is disabled' do
17
+ it 'should remove file: "/etc/apt/apt.conf.d/01proxy" and return true' do
18
+ apt_proxy = described_class.new(app, env)
19
+ apt_proxy.instance_variable_set(:@machine, machine)
20
+
21
+ expect(apt_proxy.config_name).to eq 'apt_proxy'
22
+
23
+ # configure test doubles
24
+ allow(machine).to receive_message_chain(:communicate, :sudo).with("rm -f /etc/apt/apt.conf.d/01proxy")
25
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:apt_proxy_conf).and_return(true)
26
+ allow(machine).to receive_message_chain(:guest, :capability).with(:apt_proxy_conf).and_return("/etc/apt/apt.conf.d/01proxy")
27
+ allow(machine).to receive_message_chain(:guest, :name).and_return('non-supported-os')
28
+
29
+ expect(apt_proxy.send(:unconfigure_machine)).to eq true
30
+ end
31
+ end
32
+
33
+ context 'when not on a supported OS' do
34
+ it '#unconfigure_machine should return false' do
35
+ apt_proxy = described_class.new(app, env)
36
+ apt_proxy.instance_variable_set(:@machine, machine)
37
+
38
+ expect(apt_proxy.config_name).to eq 'apt_proxy'
39
+
40
+ # configure test doubles
41
+ allow(machine).to receive_message_chain(:guest, :name).and_return('non-supported-os')
42
+ allow(machine).to receive_message_chain(:guest, :capability?).with(:apt_proxy_conf).and_return(false)
43
+
44
+ expect(apt_proxy.send(:unconfigure_machine)).to eq false
45
+ end
46
+
47
+ end
48
+ end
49
+
50
+ describe "#skip?" do
51
+ let(:machine) { double('machine') }
52
+
53
+ let(:config) { OpenStruct.new }
54
+
55
+ subject do
56
+ apt_proxy = described_class.new(nil, nil)
57
+ apt_proxy.instance_variable_set(:@machine, machine)
58
+
59
+ allow(machine).to receive_message_chain(:config, :proxy) { config }
60
+
61
+ apt_proxy.send(:skip?)
62
+ end
63
+
64
+ context "when config.proxy.enabled[:apt] = false" do
65
+ before(:each) do
66
+ config.enabled = {:apt => false}
67
+ config.http = 'http://foo-proxy-server:8080'
68
+ config.https = 'http://foo-prxoy-server:8080'
69
+ config.ftp = 'ftp://foo-proxy-server:8080'
70
+ end
71
+
72
+ it { is_expected.to eq true }
73
+ end
74
+
75
+ context "when config.proxy.enabled[:apt] = true" do
76
+ before(:each) do
77
+ config.enabled = {:apt => true}
78
+ config.http = 'http://foo-proxy-server:8080'
79
+ config.https = 'http://foo-prxoy-server:8080'
80
+ config.ftp = 'ftp://foo-proxy-server:8080'
81
+ end
82
+
83
+ it { is_expected.to eq false }
84
+ end
85
+
86
+ context "when config.proxy.enabled[:apt] = {:enabled => false, :skip => false}" do
87
+ before(:each) do
88
+ config.enabled = {
89
+ :apt => {
90
+ :enabled => false,
91
+ :skip => false,
92
+ }
93
+ }
94
+ config.http = 'http://foo-proxy-server:8080'
95
+ config.https = 'http://foo-prxoy-server:8080'
96
+ config.ftp = 'ftp://foo-proxy-server:8080'
97
+ end
98
+
99
+ it { is_expected.to eq false }
100
+ end
101
+
102
+ context "when config.proxy.enabled[:apt] = {:enabled => true, :skip => false}" do
103
+ before(:each) do
104
+ config.enabled = {
105
+ :apt => {
106
+ :enabled => true,
107
+ :skip => false,
108
+ }
109
+ }
110
+ config.http = 'http://foo-proxy-server:8080'
111
+ config.https = 'http://foo-prxoy-server:8080'
112
+ config.ftp = 'ftp://foo-proxy-server:8080'
113
+ end
114
+
115
+ it { is_expected.to eq false }
116
+ end
117
+
118
+ context "when config.proxy.enabled[:apt] = {:enabled => true, :skip => true}" do
119
+ before(:each) do
120
+ config.enabled = {
121
+ :apt => {
122
+ :enabled => true,
123
+ :skip => true,
124
+ }
125
+ }
126
+ config.http = 'http://foo-proxy-server:8080'
127
+ config.https = 'http://foo-prxoy-server:8080'
128
+ config.ftp = 'ftp://foo-proxy-server:8080'
129
+ end
130
+
131
+ it { is_expected.to eq true }
132
+ end
133
+
134
+ context "when config.proxy.enabled[:apt] = {:enabled => false, :skip => true}" do
135
+ before(:each) do
136
+ config.enabled = {
137
+ :apt => {
138
+ :enabled => false,
139
+ :skip => true,
140
+ }
141
+ }
142
+ config.http = 'http://foo-proxy-server:8080'
143
+ config.https = 'http://foo-prxoy-server:8080'
144
+ config.ftp = 'ftp://foo-proxy-server:8080'
145
+ end
146
+
147
+ it { is_expected.to eq true }
148
+ end
149
+
150
+ context "when config.proxy.enabled = false" do
151
+ before(:each) do
152
+ config.enabled = false
153
+ config.http = 'http://foo-proxy-server:8080'
154
+ config.https = 'http://foo-prxoy-server:8080'
155
+ config.ftp = 'ftp://foo-proxy-server:8080'
156
+ end
157
+
158
+ it { is_expected.to eq true }
159
+ end
160
+
161
+ context "when config.proxy.enabled = true " do
162
+ before(:each) do
163
+ config.enabled = true
164
+ config.http = 'http://foo-proxy-server:8080'
165
+ config.https = 'http://foo-prxoy-server:8080'
166
+ config.ftp = 'ftp://foo-proxy-server:8080'
167
+ end
168
+
169
+ it { is_expected.to eq false }
170
+ end
171
+ end
172
+
11
173
  end