Skip to content

Commit

Permalink
Merge pull request #179 from codylane/fix_proxy_disablement
Browse files Browse the repository at this point in the history
bugfix: undefined method []' for nil:NilClass
  • Loading branch information
codylane authored Jan 4, 2019
2 parents 7c0a6af + 46580a7 commit de45529
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/vagrant-proxyconf/action/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,13 @@ def disabled?
app_name = config_name.gsub(/_proxy/, '').to_sym

if enabled.respond_to?(:key)
return false if enabled.has_key?(app_name) == false

# if boolean value, return original behavior as mentioned in Readme
return enabled[app_name] == false if [true, false].include?(enabled[app_name])

return false if enabled[app_name].has_key?(:skip) == false

# otherwise assume new behavior using :enabled as a new hash key
return enabled[app_name][:enabled] == false
end
Expand All @@ -141,9 +145,13 @@ def skip?
app_name = config_name.gsub(/_proxy/, '').to_sym

if enabled.respond_to?(:key)
return false if enabled.has_key?(app_name) == false

# if boolean value, return original behavior as mentioned in Readme
return enabled[app_name] == false if [true, false].include?(enabled[app_name])

return false if enabled[app_name].has_key?(:skip) == false

# otherwise assume new behavior using :enabled as a new hash key
return enabled[app_name][:skip] == true
end
Expand Down
191 changes: 191 additions & 0 deletions spec/unit/vagrant-proxyconf/action/base_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
require 'spec_helper'
require 'vagrant-proxyconf/action/base'
require 'vagrant-proxyconf/action/configure_apt_proxy'

class MyBase < VagrantPlugins::ProxyConf::Action::Base

def config_name
'my_base'
end

private

def configure_machine
end

def unconfigure_machine
end

end

def create_base(machine, env)
base = MyBase.new(nil, env)
base.instance_variable_set(:@machine, machine)

expect(base.config_name).to eq 'my_base'

base
end

describe MyBase do
let(:machine) { double('machine') }

describe "#skip?" do
let(:config) { OpenStruct.new }
let(:env) { OpenStruct.new }

subject do
base = create_base(machine, env)
allow(machine).to receive_message_chain(:config, :proxy) { config }

base.send(:skip?)
end

context "when attempting to configure a app proxy that is not defined" do
before(:each) do
config.enabled = {:foobar => false}
config.http = 'http://foo-proxy-server:8080'
config.https = 'http://foo-prxoy-server:8080'
config.ftp = 'ftp://foo-proxy-server:8080'
end

it { is_expected.to eq false }
end

context "when config.proxy.enabled[:my_base] = false" do
before(:each) do
config.enabled = {:my_base => false}
config.http = 'http://foo-proxy-server:8080'
config.https = 'http://foo-prxoy-server:8080'
config.ftp = 'ftp://foo-proxy-server:8080'
end

it { is_expected.to eq true }
end

context "when config.proxy.enabled[:my_base] = true" do
before(:each) do
config.enabled = {:my_base => true}
config.http = 'http://foo-proxy-server:8080'
config.https = 'http://foo-prxoy-server:8080'
config.ftp = 'ftp://foo-proxy-server:8080'
end

it { is_expected.to eq false }
end

context "when config.proxy.enabled[:my_base] = {}" do
before(:each) do
config.enabled = {}
config.http = 'http://foo-proxy-server:8080'
config.https = 'http://foo-prxoy-server:8080'
config.ftp = 'ftp://foo-proxy-server:8080'
end

it { is_expected.to eq false }
end


context "when config.proxy.enabled[:my_base] = {:enabled => false, :skip => false}" do
before(:each) do
config.enabled = {
:my_base => {
:enabled => false,
:skip => false,
}
}
config.http = 'http://foo-proxy-server:8080'
config.https = 'http://foo-prxoy-server:8080'
config.ftp = 'ftp://foo-proxy-server:8080'
end

it { is_expected.to eq false }
end

context "when config.proxy.enabled[:my_base] = {:enabled => true, :skip => false}" do
before(:each) do
config.enabled = {
:my_base => {
:enabled => true,
:skip => false,
}
}
config.http = 'http://foo-proxy-server:8080'
config.https = 'http://foo-prxoy-server:8080'
config.ftp = 'ftp://foo-proxy-server:8080'
end

it { is_expected.to eq false }
end

context "when config.proxy.enabled[:my_base] = {:enabled => true, :skip => true}" do
before(:each) do
config.enabled = {
:my_base => {
:enabled => true,
:skip => true,
}
}
config.http = 'http://foo-proxy-server:8080'
config.https = 'http://foo-prxoy-server:8080'
config.ftp = 'ftp://foo-proxy-server:8080'
end

it { is_expected.to eq true }
end

context "when config.proxy.enabled[:my_base] = {:enabled => false, :skip => true}" do
before(:each) do
config.enabled = {
:my_base => {
:enabled => false,
:skip => true,
}
}
config.http = 'http://foo-proxy-server:8080'
config.https = 'http://foo-prxoy-server:8080'
config.ftp = 'ftp://foo-proxy-server:8080'
end

it { is_expected.to eq true }
end

context "when config.proxy.enabled = false" do
before(:each) do
config.enabled = false
config.http = 'http://foo-proxy-server:8080'
config.https = 'http://foo-prxoy-server:8080'
config.ftp = 'ftp://foo-proxy-server:8080'
end

it { is_expected.to eq true }
end

context "when config.proxy.enabled = true " do
before(:each) do
config.enabled = true
config.http = 'http://foo-proxy-server:8080'
config.https = 'http://foo-prxoy-server:8080'
config.ftp = 'ftp://foo-proxy-server:8080'
end

it { is_expected.to eq false }
end

context "when config.proxy.enable[:my_base] = {:enabled => true} and :skip key is missing" do
before(:each) do
config.enabled = {
:my_base => {
:enabled => false,
},
}
config.http = 'http://foo-proxy-server:8080'
config.https = 'http://foo-prxoy-server:8080'
config.ftp = 'ftp://foo-proxy-server:8080'
end

it { is_expected.to eq false }
end
end

end

0 comments on commit de45529

Please sign in to comment.