Class: Rack::Webauth::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-webauth/test.rb

Overview

Middleware to use for testing in situations where WebAuth is not available, such as development environments.

Example:

use(Rack::Webauth::Test,
    :user => "test-user",
    :mail => "[email protected]")

use(Rack::Webauth)

run lambda {|env|
  env["WEBAUTH_USER"] #=> "test-user"
  env["WEBAUTH_LDAP_MAIL"] #=> "[email protected]"
  env[Rack::Webauth::NS]. #=> "test-user"
  env[Rack::Webauth::NS].attributes['mail'] #=> "[email protected]"
}

In order to work correctly, Rack::Webauth::Test must come before Rack::Webauth in the middleware stack.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, env_vars) ⇒ Test

Returns a new instance of Test


27
28
29
# File 'lib/rack-webauth/test.rb', line 27

def initialize(app, env_vars)
  @app, @env_vars = app, env_vars
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app


25
26
27
# File 'lib/rack-webauth/test.rb', line 25

def app
  @app
end

#env_varsObject (readonly)

Returns the value of attribute env_vars


25
26
27
# File 'lib/rack-webauth/test.rb', line 25

def env_vars
  @env_vars
end

Instance Method Details

#call(env) ⇒ Object


31
32
33
34
35
36
# File 'lib/rack-webauth/test.rb', line 31

def call(env)
  env_vars.each_pair do |key, value|
    add_to_env(env, key, value)
  end
  app.call(env)
end