1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[openstack] Authentication Mocks

Signed-off-by: Nelvin Driz <nelvindriz@live.com>
This commit is contained in:
Nelvin Driz 2012-08-14 16:32:23 +08:00
parent 8beec31665
commit 7c72e5394f
5 changed files with 72 additions and 6 deletions

View file

@ -1,3 +1,5 @@
require 'time'
module Fog
class Time < ::Time

View file

@ -152,9 +152,13 @@ module Fog
# Hosts
request :list_hosts
request :get_host_details
class Mock
attr_reader :auth_token
attr_reader :auth_token_expiration
attr_reader :current_user
attr_reader :current_tenant
def self.data
@data ||= Hash.new do |hash, key|
@ -205,6 +209,19 @@ module Fog
def initialize(options={})
@openstack_username = options[:openstack_username]
@openstack_tenant = options[:openstack_tenant]
@openstack_auth_uri = URI.parse(options[:openstack_auth_url])
@auth_token = Fog::Mock.random_base64(64)
@auth_token_expiration = (Time.now.utc + 86400).iso8601
management_url = URI.parse(options[:openstack_auth_url])
management_url.port = 8774
management_url.path = '/v1.1/1'
@openstack_management_url = management_url.to_s
identity_public_endpoint = URI.parse(options[:openstack_auth_url])
identity_public_endpoint.port = 5000
@openstack_identity_public_endpoint = identity_public_endpoint.to_s
end
def data

View file

@ -53,6 +53,11 @@ module Fog
class Mock
attr_reader :auth_token
attr_reader :auth_token_expiration
attr_reader :current_user
attr_reader :current_tenant
def self.data
@data ||= Hash.new do |hash, key|
hash[key] = {
@ -69,6 +74,26 @@ module Fog
def initialize(options={})
@openstack_username = options[:openstack_username]
@openstack_auth_uri = URI.parse(options[:openstack_auth_url])
@openstack_management_url = @openstack_auth_uri.to_s
@current_user_id = 1
@current_user = {
'username' => 'admin',
'name' => 'admin',
'id' => 1,
'roles' => [
{ 'id' => 1, 'name' => 'admin' },
{ 'id' => 2, 'name' => 'Member' }
]
}
@auth_token = Fog::Mock.random_base64(64)
@auth_token_expiration = (Time.now.utc + 86400).iso8601
@current_tenant = {
'id' => 1,
'name' => 'admin'
}
unless self.data[:users].values.detect {|user| user['name'] == @openstack_username}
id = Fog::Mock.random_numbers(6).to_s
@ -91,11 +116,13 @@ module Fog
end
def credentials
{ :provider => 'openstack',
:openstack_auth_url => @openstack_auth_uri.to_s,
:openstack_auth_token => @auth_token,
:openstack_management_url => @openstack_management_url,
:openstack_current_user_id => @openstack_current_user_id}
{ :provider => 'openstack',
:openstack_auth_url => @openstack_auth_uri.to_s,
:openstack_auth_token => @auth_token,
:openstack_management_url => @openstack_management_url,
:openstack_current_user_id => @openstack_current_user_id,
:current_user => @current_user,
:current_tenant => @current_tenant}
end
end

View file

@ -49,6 +49,16 @@ module Fog
def initialize(options={})
require 'multi_json'
@openstack_username = options[:openstack_username]
@openstack_tenant = options[:openstack_tenant]
@openstack_auth_uri = URI.parse(options[:openstack_auth_url])
@auth_token = Fog::Mock.random_base64(64)
@auth_token_expiration = (Time.now.utc + 86400).iso8601
management_url = URI.parse(options[:openstack_auth_url])
management_url.port = 9292
management_url.path = '/v1'
@openstack_management_url = management_url.to_s
@data ||= { :users => {} }
unless @data[:users].find {|u| u['name'] == options[:openstack_username]}

View file

@ -48,6 +48,16 @@ module Fog
def initialize(options={})
require 'multi_json'
@openstack_username = options[:openstack_username]
@openstack_tenant = options[:openstack_tenant]
@openstack_auth_uri = URI.parse(options[:openstack_auth_url])
@auth_token = Fog::Mock.random_base64(64)
@auth_token_expiration = (Time.now.utc + 86400).iso8601
management_url = URI.parse(options[:openstack_auth_url])
management_url.port = 8776
management_url.path = '/v1'
@openstack_management_url = management_url.to_s
@data ||= { :users => {} }
unless @data[:users].find {|u| u['name'] == options[:openstack_username]}