module Devise::RadiusAuthenticatable::TestHelpers
The Devise::RadiusAuthenticatable::TestHelpers
module provides a very simple stub server through the RadiusServer
class. It modifies the Radiustar::Request.new method to create a request in the stub server that can be used to check that the proper information is passed to the radius server. It also modifies the Radiustar::Request#authenticate method to perform authentication against the stub server.
The RadiusServer
class offers a simple interface for creating users prior to your tests. The create_radius_user
method allows for the creation of a radius user within the stub server. The radius_server
method provides the RadiusServer
instance that test assertions can be performed against.
The stub server is a singleton class to provide easy access. This means that it needs to have all state cleared out between tests. The clear_radius_users
and clear_radius_request
methods offer an easy way to clear the user and request info out of the server between tests.
Public Class Methods
# File lib/devise/radius_authenticatable/test_helpers.rb, line 103 def self.included(mod) Radiustar::Request.class_eval do def initialize(url, options = {}) Devise::RadiusAuthenticatable::TestHelpers::RadiusServer.instance. create_request(url, options) end def authenticate(username, password, secret) Devise::RadiusAuthenticatable::TestHelpers::RadiusServer.instance. authenticate(username, password) end end if mod.respond_to?(:after) mod.after(:each) do Devise::RadiusAuthenticatable::TestHelpers::RadiusServer.instance. clear_request Devise::RadiusAuthenticatable::TestHelpers::RadiusServer.instance.clear_users end end end
# File lib/devise/radius_authenticatable/test_helpers.rb, line 105 def initialize(url, options = {}) Devise::RadiusAuthenticatable::TestHelpers::RadiusServer.instance. create_request(url, options) end
Public Instance Methods
# File lib/devise/radius_authenticatable/test_helpers.rb, line 110 def authenticate(username, password, secret) Devise::RadiusAuthenticatable::TestHelpers::RadiusServer.instance. authenticate(username, password) end
# File lib/devise/radius_authenticatable/test_helpers.rb, line 34 def clear_radius_request RadiusServer.instance.clear_request end
# File lib/devise/radius_authenticatable/test_helpers.rb, line 30 def clear_radius_users RadiusServer.instance.clear_users end
# File lib/devise/radius_authenticatable/test_helpers.rb, line 26 def create_radius_user(username, password, attributes = {}) RadiusServer.instance.add_user(username, password, attributes) end
# File lib/devise/radius_authenticatable/test_helpers.rb, line 22 def radius_server RadiusServer.instance end