Sha256: 0937fa92e0fea4bc7a20583dc5bbb6057a171c636a29e6802e7f309861aaf5a9

Contents?: true

Size: 1.98 KB

Versions: 4

Compression:

Stored size: 1.98 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
    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

4 entries across 4 versions & 1 rubygems

Version Path
ixtlan-0.4.3 spec/session_timeout_spec.rb
ixtlan-0.4.2 spec/session_timeout_spec.rb
ixtlan-0.4.1 spec/session_timeout_spec.rb
ixtlan-0.4.0 spec/session_timeout_spec.rb