spec/unit/client_spec.rb in vmc-0.3.10 vs spec/unit/client_spec.rb in vmc-0.3.12.beta.1
- old
+ new
@@ -18,13 +18,18 @@
it 'should default to local target' do
client = VMC::Client.new
client.target.should == VMC::DEFAULT_TARGET
end
+ it 'should default to use secure protocol' do
+ client = VMC::Client.new
+ client.target.match(/^https/)
+ end
+
it 'should normalize target with no scheme' do
client = VMC::Client.new('api.cloudfoundry.com')
- client.target.should == @target
+ client.target.should == 'http://api.cloudfoundry.com'
end
it 'should properly initialize with auth_token' do
client = VMC::Client.new(@target, @auth_token)
client.target.should == @target
@@ -127,10 +132,24 @@
app.should have_key :name
app.should have_key :services
app.should have_key :instances
end
+ it 'should get a proper list of users' do
+ info_path = "#{@local_target}#{VMC::INFO_PATH}"
+ stub_request(:get, info_path).to_return(File.new(spec_asset('info_authenticated.txt')))
+ users_path = "#{@local_target}#{VMC::USERS_PATH}"
+ stub_request(:get, users_path).to_return(File.new(spec_asset('list_users.txt')))
+ client = VMC::Client.new(@local_target, @auth_token)
+ users = client.users
+ users.should have(4).items
+ user = users.first
+ user.should have_key :email
+ user.should have_key :admin
+ user.should have_key :apps
+ end
+
it 'should get a proper list of services' do
info_path = "#{@local_target}#{VMC::INFO_PATH}"
stub_request(:get, info_path).to_return(File.new(spec_asset('info_authenticated.txt')))
services_path = "#{@local_target}#{VMC::GLOBAL_SERVICES_PATH}"
stub_request(:get, services_path).to_return(File.new(spec_asset('global_service_listings.txt')))
@@ -264,19 +283,32 @@
info = client.info
RestClient.proxy.should == proxy
ENV['http_proxy'] = nil
end
- it 'should set a secure proxy over a normal proxy if one is set' do
+ it 'should use a secure proxy over a normal proxy if one is set' do
+ info_path = "#{@target}#{VMC::INFO_PATH}"
+ stub_request(:get, info_path).to_return(File.new(spec_asset('info_return.txt')))
+ proxy = 'http://proxy.vmware.com:3128'
+ secure_proxy = 'http://secure-proxy.vmware.com:3128'
+ ENV['http_proxy'] = proxy
+ ENV['https_proxy'] = secure_proxy
+ client = VMC::Client.new(@target)
+ info = client.info
+ RestClient.proxy.should == secure_proxy
+ ENV['http_proxy'] = ENV['https_proxy'] = nil
+ end
+
+ it 'should not use a secure proxy for non-secure site' do
info_path = "#{@local_target}#{VMC::INFO_PATH}"
stub_request(:get, info_path).to_return(File.new(spec_asset('info_return.txt')))
proxy = 'http://proxy.vmware.com:3128'
- secure_proxy = 'https://proxy.vmware.com:3128'
+ secure_proxy = 'http://secure-proxy.vmware.com:3128'
ENV['http_proxy'] = proxy
ENV['https_proxy'] = secure_proxy
client = VMC::Client.new(@local_target)
info = client.info
- RestClient.proxy.should == secure_proxy
+ RestClient.proxy.should == proxy
ENV['http_proxy'] = ENV['https_proxy'] = nil
end
# WebMock.allow_net_connect!