Module: Devise::RadiusAuthenticatable::TestHelpers

Defined in:
lib/devise/radius_authenticatable/test_helpers.rb

Overview

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.

Defined Under Namespace

Classes: RadiusServer

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(mod) ⇒ Object


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# 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

Instance Method Details

#clear_radius_requestObject


34
35
36
# File 'lib/devise/radius_authenticatable/test_helpers.rb', line 34

def clear_radius_request
  RadiusServer.instance.clear_request
end

#clear_radius_usersObject


30
31
32
# File 'lib/devise/radius_authenticatable/test_helpers.rb', line 30

def clear_radius_users
  RadiusServer.instance.clear_users
end

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


26
27
28
# 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

#radius_serverObject


22
23
24
# File 'lib/devise/radius_authenticatable/test_helpers.rb', line 22

def radius_server
  RadiusServer.instance
end