Skip to content

Commit

Permalink
[openstack] Authentication Mocks
Browse files Browse the repository at this point in the history
Signed-off-by: Nelvin Driz <nelvindriz@live.com>
  • Loading branch information
Keoven committed Sep 28, 2012
1 parent 8beec31 commit 7c72e53
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/fog/core/time.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'time'

module Fog
class Time < ::Time

Expand Down
19 changes: 18 additions & 1 deletion lib/fog/openstack/compute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,13 @@ class OpenStack < Fog::Service
# 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|
Expand Down Expand Up @@ -205,6 +209,19 @@ def self.reset
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
Expand Down
37 changes: 32 additions & 5 deletions lib/fog/openstack/identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class OpenStack < Fog::Service


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] = {
Expand All @@ -69,6 +74,26 @@ def self.reset

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
Expand All @@ -91,11 +116,13 @@ def reset_data
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

Expand Down
10 changes: 10 additions & 0 deletions lib/fog/openstack/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ def self.reset
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]}
Expand Down
10 changes: 10 additions & 0 deletions lib/fog/openstack/volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ def self.reset
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]}
Expand Down

0 comments on commit 7c72e53

Please sign in to comment.