mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[rackspace|monitoring] updating to re-authenticate token on expiration; adding monitoring authentication tests
This commit is contained in:
parent
d6cf9817f4
commit
ff5a5bbabd
2 changed files with 84 additions and 15 deletions
|
@ -16,7 +16,7 @@ module Fog
|
||||||
requires :rackspace_api_key, :rackspace_username
|
requires :rackspace_api_key, :rackspace_username
|
||||||
recognizes :rackspace_auth_url
|
recognizes :rackspace_auth_url
|
||||||
recognizes :persistent
|
recognizes :persistent
|
||||||
recognizes :rackspace_service_url
|
recognizes :rackspace_monitoring_url
|
||||||
recognizes :rackspace_region
|
recognizes :rackspace_region
|
||||||
|
|
||||||
model_path 'fog/rackspace/models/monitoring'
|
model_path 'fog/rackspace/models/monitoring'
|
||||||
|
@ -90,14 +90,11 @@ module Fog
|
||||||
@rackspace_username = options[:rackspace_username]
|
@rackspace_username = options[:rackspace_username]
|
||||||
@rackspace_auth_url = options[:rackspace_auth_url]
|
@rackspace_auth_url = options[:rackspace_auth_url]
|
||||||
@connection_options = options[:connection_options] || {}
|
@connection_options = options[:connection_options] || {}
|
||||||
|
@rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_monitoring_url])
|
||||||
|
|
||||||
authenticate
|
authenticate
|
||||||
|
|
||||||
@persistent = options[:persistent] || false
|
@persistent = options[:persistent] || false
|
||||||
|
|
||||||
@connection_options[:headers] ||= {}
|
|
||||||
@connection_options[:headers].merge!({ 'Content-Type' => 'application/json', 'X-Auth-Token' => auth_token })
|
|
||||||
|
|
||||||
@connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
|
@connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -105,13 +102,14 @@ module Fog
|
||||||
@connection.reset
|
@connection.reset
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def endpoint_uri(service_endpoint_url=nil)
|
||||||
|
@uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_monitoring_url)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def request(params)
|
def request(params, parse_json = true, &block)
|
||||||
begin
|
super(params, parse_json, &block)
|
||||||
response = @connection.request(params.merge!({
|
|
||||||
:path => "#{endpoint_uri.path}/#{params[:path]}"
|
|
||||||
}))
|
|
||||||
rescue Excon::Errors::BadRequest => error
|
rescue Excon::Errors::BadRequest => error
|
||||||
raise BadRequest.slurp error
|
raise BadRequest.slurp error
|
||||||
rescue Excon::Errors::Conflict => error
|
rescue Excon::Errors::Conflict => error
|
||||||
|
@ -120,11 +118,10 @@ module Fog
|
||||||
raise NotFound.slurp(error, region)
|
raise NotFound.slurp(error, region)
|
||||||
rescue Excon::Errors::ServiceUnavailable => error
|
rescue Excon::Errors::ServiceUnavailable => error
|
||||||
raise ServiceUnavailable.slurp error
|
raise ServiceUnavailable.slurp error
|
||||||
end
|
rescue Excon::Errors::InternalServerError => error
|
||||||
unless response.body.empty?
|
raise InternalServerError.slurp error
|
||||||
response.body = Fog::JSON.decode(response.body)
|
rescue Excon::Errors::HTTPStatusError => error
|
||||||
end
|
raise ServiceError.slurp error
|
||||||
response
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def authenticate
|
def authenticate
|
||||||
|
|
72
tests/rackspace/monitoring_tests.rb
Normal file
72
tests/rackspace/monitoring_tests.rb
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
Shindo.tests('Fog::Rackspace::Monitoring', ['rackspace','rackspace_monitoring']) do
|
||||||
|
|
||||||
|
def assert_method(url, method)
|
||||||
|
@service.instance_variable_set "@rackspace_auth_url", url
|
||||||
|
returns(method) { @service.send :authentication_method }
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('#authentication_method') do
|
||||||
|
@service = Fog::Rackspace::Monitoring.new
|
||||||
|
|
||||||
|
assert_method nil, :authenticate_v2
|
||||||
|
|
||||||
|
assert_method 'auth.api.rackspacecloud.com', :authenticate_v1 # chef's default auth endpoint
|
||||||
|
|
||||||
|
assert_method 'https://identity.api.rackspacecloud.com', :authenticate_v1
|
||||||
|
assert_method 'https://identity.api.rackspacecloud.com/v1', :authenticate_v1
|
||||||
|
assert_method 'https://identity.api.rackspacecloud.com/v1.1', :authenticate_v1
|
||||||
|
assert_method 'https://identity.api.rackspacecloud.com/v2.0', :authenticate_v2
|
||||||
|
|
||||||
|
assert_method 'https://lon.identity.api.rackspacecloud.com', :authenticate_v1
|
||||||
|
assert_method 'https://lon.identity.api.rackspacecloud.com/v1', :authenticate_v1
|
||||||
|
assert_method 'https://lon.identity.api.rackspacecloud.com/v1.1', :authenticate_v1
|
||||||
|
assert_method 'https://lon.identity.api.rackspacecloud.com/v2.0', :authenticate_v2
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
tests('current authentation') do
|
||||||
|
pending if Fog.mocking?
|
||||||
|
|
||||||
|
tests('variables populated').succeeds do
|
||||||
|
@service = Fog::Rackspace::Monitoring.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0', :connection_options => {:ssl_verify_peer => true}
|
||||||
|
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||||
|
returns(false, "path populated") { @service.instance_variable_get("@uri").host.nil? }
|
||||||
|
identity_service = @service.instance_variable_get("@identity_service")
|
||||||
|
returns(false, "identity service was used") { identity_service.nil? }
|
||||||
|
returns(true, "connection_options are passed") { identity_service.instance_variable_get("@connection_options").has_key?(:ssl_verify_peer) }
|
||||||
|
@service.list_entities
|
||||||
|
end
|
||||||
|
tests('custom endpoint') do
|
||||||
|
@service = Fog::Rackspace::Monitoring.new :rackspace_auth_url => 'https://identity.api.rackspacecloud.com/v2.0',
|
||||||
|
:rackspace_monitoring_url => 'https://my-custom-endpoint.com'
|
||||||
|
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||||
|
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('default auth') do
|
||||||
|
pending if Fog.mocking?
|
||||||
|
|
||||||
|
tests('no params').succeeds do
|
||||||
|
@service = Fog::Rackspace::Monitoring.new
|
||||||
|
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||||
|
returns(true) { (@service.instance_variable_get("@uri").host =~ /monitoring.api.rackspacecloud.com/) != nil }
|
||||||
|
@service.list_entities
|
||||||
|
end
|
||||||
|
tests('custom endpoint') do
|
||||||
|
@service = Fog::Rackspace::Monitoring.new :rackspace_monitoring_url => 'https://my-custom-endpoint.com'
|
||||||
|
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||||
|
returns(true, "uses custom endpoint") { (@service.instance_variable_get("@uri").host =~ /my-custom-endpoint\.com/) != nil }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('reauthentication') do
|
||||||
|
pending if Fog.mocking?
|
||||||
|
|
||||||
|
@service = Fog::Rackspace::Monitoring.new
|
||||||
|
returns(true, "auth token populated") { !@service.send(:auth_token).nil? }
|
||||||
|
@service.instance_variable_set("@auth_token", "bad_token")
|
||||||
|
returns(true) { [200, 203].include? @service.list_entities.status }
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue