Class: Devise::RadiusAuthenticatable::TestHelpers::RadiusServer

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/devise/radius_authenticatable/test_helpers.rb

Overview

Stub RadiusServer that allows testing of radius authentication without a real server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRadiusServer


45
46
47
48
# File 'lib/devise/radius_authenticatable/test_helpers.rb', line 45

def initialize
  clear_users
  clear_request
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options


43
44
45
# File 'lib/devise/radius_authenticatable/test_helpers.rb', line 43

def options
  @options
end

#urlObject (readonly)

Returns the value of attribute url


43
44
45
# File 'lib/devise/radius_authenticatable/test_helpers.rb', line 43

def url
  @url
end

Instance Method Details

#add_user(username, password, attributes = {}) ⇒ Object

Add a user to the radius server to use for authentication purposes. A couple of default attributes will be returned in the auth response if no attributes are supplied when creating the user.


67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/devise/radius_authenticatable/test_helpers.rb', line 67

def add_user(username, password, attributes = {})
  @users[username] = {}
  @users[username][:password] = password
  if attributes.empty?
    @users[username][:attributes] = {
      'User-Name' => username,
      'Filter-Id' => 60
    }
  else
    @users[username][:attributes] = attributes
  end
end

#attributes(username) ⇒ Object

Accessor to retrieve the attributes configured for the specified user.


86
87
88
# File 'lib/devise/radius_authenticatable/test_helpers.rb', line 86

def attributes(username)
  @users[username][:attributes]
end

#authenticate(username, password) ⇒ Object

Called to perform authentication using the specified username and password. If the authentication is successful, an Access-Accept is returned along with the radius attributes configured for the user. If authentication fails, an Access-Reject is returned.


94
95
96
97
98
99
100
# File 'lib/devise/radius_authenticatable/test_helpers.rb', line 94

def authenticate(username, password)
  if @users[username] && @users[username][:password] == password
    { :code => 'Access-Accept' }.merge(@users[username][:attributes])
  else
    { :code => 'Access-Reject' }
  end
end

#clear_requestObject

Clear the request information that is stored.


59
60
61
62
# File 'lib/devise/radius_authenticatable/test_helpers.rb', line 59

def clear_request
  @url = nil
  @options = nil
end

#clear_usersObject

Clear the users that have been configured for the radius server.


81
82
83
# File 'lib/devise/radius_authenticatable/test_helpers.rb', line 81

def clear_users
  @users = {}
end

#create_request(url, options) ⇒ Object

Stores the information about the radius request that would have been sent to the radius server. This information can be queried to determine that the proper information is being sent.


53
54
55
56
# File 'lib/devise/radius_authenticatable/test_helpers.rb', line 53

def create_request(url, options)
  @url = url
  @options = options
end