Skip to content

Commit

Permalink
Merge 031408d into a54c18a
Browse files Browse the repository at this point in the history
  • Loading branch information
mackee committed Feb 16, 2014
2 parents a54c18a + 031408d commit f9aacde
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 12 deletions.
8 changes: 4 additions & 4 deletions lib/Ark/Plugin/Session/State/Cookie.pm
Expand Up @@ -41,9 +41,9 @@ has cookie_expires => (
my $self = shift;
exists $self->class_config->{cookie_expires}
? $self->class_config->{cookie_expires}
: exists $self->app->config->{'Plugin::Session'}->{expires}
? $self->app->config->{'Plugin::Session'}->{expires}
: '+1d'; # 1day
: exists $self->app->config->{'Plugin::Session'}->{expire}
? $self->app->config->{'Plugin::Session'}->{expire}
: '60 * 60 * 24'; # 1day
},
);

Expand Down Expand Up @@ -132,7 +132,7 @@ sub make_cookie {

my $cookie = {
value => $sid,
expires => $self->cookie_expires,
expires => time + $self->cookie_expires,
secure => $self->cookie_secure,
$self->cookie_domain ? (domain => $self->cookie_domain) : (),
$self->cookie_path ? (path => $self->cookie_path) : (),
Expand Down
2 changes: 1 addition & 1 deletion t/plugin_csrf_defender.t
Expand Up @@ -14,7 +14,7 @@ use Test::More;
/;

conf 'Plugin::Session::State::Cookie' => {
cookie_expires => '+3d',
cookie_expires => 60*60*24 * 3,
};

package TestApp::Controller::Root;
Expand Down
2 changes: 1 addition & 1 deletion t/plugin_csrf_defender_error_action.t
Expand Up @@ -14,7 +14,7 @@ use Test::More;
/;

config 'Plugin::Session::State::Cookie' => {
cookie_expires => '+3d',
cookie_expires => 60*60*24 * 3,
};

config 'Plugin::CSRFDefender' => {
Expand Down
2 changes: 1 addition & 1 deletion t/plugin_csrf_defender_filter_form.t
Expand Up @@ -14,7 +14,7 @@ use Test::More;
/;

conf 'Plugin::Session::State::Cookie' => {
cookie_expires => '+3d',
cookie_expires => 60*60*24 * 3,
};
conf 'Plugin::CSRFDefender' => {
filter_form => 1,
Expand Down
2 changes: 1 addition & 1 deletion t/plugin_csrf_defender_with_options.t
Expand Up @@ -14,7 +14,7 @@ use Test::More;
/;

config 'Plugin::Session::State::Cookie' => {
cookie_expires => '+3d',
cookie_expires => 60*60*24 * 3,
};

config 'Plugin::CSRFDefender' => {
Expand Down
2 changes: 1 addition & 1 deletion t/plugin_session.t
Expand Up @@ -13,7 +13,7 @@ use Test::More;
/;

conf 'Plugin::Session::State::Cookie' => {
cookie_expires => '+3d',
cookie_expires => 60*60*24 * 3,
};

package TestApp::Controller::Root;
Expand Down
21 changes: 18 additions & 3 deletions t/plugin_session_expire.t
Expand Up @@ -2,6 +2,7 @@ use strict;
use warnings;
use Test::More;

my $expires = 60 * 60 * 24;
{
package TestApp;
use Ark;
Expand All @@ -13,7 +14,7 @@ use Test::More;
/;

conf 'Plugin::Session::State::Cookie' => {
cookie_expires => undef,
cookie_expires => $expires, #+1d
};

package TestApp::Controller::Root;
Expand All @@ -33,8 +34,22 @@ use Ark::Test 'TestApp',
reuse_connection => 1;

{
my @MON = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
my @WDAY = qw( Sun Mon Tue Wed Thu Fri Sat );
my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime(time + $expires);
$year += 1900;
my $expected_expires_str =
sprintf(
"%s, %02d-%s-%04d %02d:%02d:%02d GMT",
$WDAY[$wday], $mday, $MON[$mon], $year, $hour, $min, $sec
);

my $res = request(GET => '/test_set');
like( $res->header('Set-Cookie'), qr/testapp_session=/, 'session id ok');
unlike( $res->header('Set-Cookie'), qr/expires=/, 'session expires ok');
my $cookie_header = $res->header('Set-Cookie');
like( $cookie_header, qr/testapp_session=/, 'session id ok');
like( $cookie_header, qr/expires=/, 'session expires ok');
my ($expires_date) = $cookie_header =~ /expires=(.*)$/;
is ($expires_date, $expected_expires_str, 'session expires date ok');
}

done_testing;

0 comments on commit f9aacde

Please sign in to comment.