Sha256: 06641d2eb4c9d160ba899c429fcd3b3d31d32600e02fa3b0504106220b09f507

Contents?: true

Size: 1.99 KB

Versions: 6

Compression:

Stored size: 1.99 KB

Contents

require 'pathname'
require Pathname(__FILE__).dirname + 'spec_helper.rb'

require 'ixtlan/rails/session_timeout'

class Controller
  include Ixtlan::Rails::SessionTimeout
end

describe Ixtlan::Rails::SessionTimeout do

  before :each do
    Ixtlan::Models::User.all.destroy!
    @controller = Controller.new
    @log = StringIO.new
    Slf4r::LoggerFacade4RubyLogger.file = @log
  end

  it 'should expire due to idle timeout' do
    @controller.send(:check_session_expiry).should be_true
    @controller.session.empty?.should be_false
    @controller.rendered.should be_nil
    @log.string.size.should == 0
    sleep 1
    @controller.send(:check_session_expiry).should be_false
    @controller.session.empty?.should be_true
    @controller.rendered.should be_true
    @log.string.size.should_not == 0
    @log.string.should =~ /session timeout/
  end

  it 'should expire due to IP change' do
    @controller.request.headers['REMOTE_ADDR'] = "first.ip"
    @controller.send(:check_session_ip_binding).should be_true
    @controller.session.empty?.should be_false
    @controller.rendered.should be_nil
    @log.string.size.should == 0
    @controller.request.headers['REMOTE_ADDR'] = "second.ip"
    @controller.send(:check_session_ip_binding).should be_false
    @controller.session.empty?.should be_true
    @controller.rendered.should be_true
    @log.string.size.should_not == 0
    @log.string.should =~ /IP changed/
  end

  it 'should expire due to IP change' do
    @controller.request.headers['HTTP_USER_AGENT'] = "mozilla"
    @controller.send(:check_session_browser_signature).should be_true
    @controller.session.empty?.should be_false
    @controller.rendered.should be_nil
    @log.string.size.should == 0
    @controller.request.headers['HTTP_USER_AGENT'] = "iron"
    @controller.send(:check_session_browser_signature).should be_false
    @controller.session.empty?.should be_true
    @controller.rendered.should be_true
    @log.string.size.should_not == 0
    @log.string.should =~ /browser signature changed/
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ixtlan-0.4.0.pre5 spec/session_timeout_spec.rb
ixtlan-0.4.0.pre4 spec/session_timeout_spec.rb
ixtlan-0.4.0.pre3 spec/session_timeout_spec.rb
ixtlan-0.4.0.pre2 spec/session_timeout_spec.rb
ixtlan-0.4.0.pre spec/session_timeout_spec.rb
ixtlan-0.3.0 spec/session_timeout_spec.rb