#!/usr/bin/perl use strict; use warnings; use Test::More 'no_plan'; use Test::MockObject::Extends; use ok "Catalyst::Plugin::Session::AuthOnly"; { package MockApp; use NEXT; use base qw/ Catalyst::Plugin::Session::AuthOnly Catalyst::Plugin::Authentication Catalyst::Plugin::Authentication::Store::Minimal /; my %config = ( authentication => { users => { foo => { password => "secret" }, bar => { password => "secret" }, }, }, ); sub config { return \%config; } } my $c = Test::MockObject::Extends->new("MockApp"); $c->setup; $c->set_true("debug"); my $sid; $c->mock("get_session_id" => sub { $sid }); $c->mock("set_session_id" => sub { $sid = $_[1] }); $c->mock("delete_session_id" => sub { $sid = undef }); $c->set_always("log", my $log = Test::MockObject->new ); $log->mock("debug"=> sub { shift; return; warn "@_" }); $c->set_always( request => { } ); # compat kludge my $user = $c->get_user("foo"); ok( !$sid, "sid unset" ); ok( !$c->user_exists, "user doesn't exist" ); $c->set_authenticated($user); ok( $c->user_exists, "user exists" ); is( $c->user, $user, "correct user" ); ok( $sid, "sid set" ); $c->clear; $c->session->{foo} = "garbage"; $c->called_ok("log"); my $c2 = Test::MockObject::Extends->new("MockApp"); $c2->mock("get_session_id" => sub { $sid }); $c2->mock("set_session_id" => sub { $sid = $_[1] }); $c2->mock("delete_session_id" => sub { $sid = undef }); $c2->set_always("log", $log); $c2->set_true("debug"); $c2->setup; ok( $c2->user_exists(), "user exists in separate request" ); is( $c2->user, $user, "same user" ); $c2->logout; ok( !$sid, "sid deleted" );