class Devise::RadiusAuthenticatable::TestHelpers::RadiusServer
Stub RadiusServer
that allows testing of radius authentication without a real server.
Attributes
Public Class Methods
# File lib/devise/radius_authenticatable/test_helpers.rb, line 45 def initialize clear_users clear_request end
Public Instance Methods
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.
# 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
Accessor to retrieve the attributes configured for the specified user.
# File lib/devise/radius_authenticatable/test_helpers.rb, line 86 def attributes(username) @users[username][:attributes] end
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.
# 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 the request information that is stored.
# File lib/devise/radius_authenticatable/test_helpers.rb, line 59 def clear_request @url = nil @options = nil end
Clear the users that have been configured for the radius server.
# File lib/devise/radius_authenticatable/test_helpers.rb, line 81 def clear_users @users = {} end
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.
# File lib/devise/radius_authenticatable/test_helpers.rb, line 53 def create_request(url, options) @url = url @options = options end