Created
September 17, 2009 23:16
-
-
Save nekoya/188779 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Test::Base; | |
{ | |
package T1; | |
use Ark; | |
use_model 'T1::Models'; | |
use Digest::SHA1 'sha1_hex'; | |
use_plugins qw/ | |
Session | |
Session::State::Cookie | |
Session::Store::Memory | |
Authentication | |
Authentication::Credential::Password | |
Authentication::Store::Minimal | |
/; | |
conf 'Plugin::Authentication::Credential::Password' => { | |
#digest_model => 'Digest', | |
password_type => 'hashed', | |
password_pre_salt => 'pre', | |
password_post_salt => 'post', | |
}; | |
conf 'Plugin::Authentication::Store::Minimal' => { | |
users => { | |
user1 => { | |
username => 'user1', password => sha1_hex('pre'.'pass1'.'post'), | |
}, | |
user2 => { | |
username => 'user2', password => sha1_hex('pre'.'pass2'.'post'), | |
}, | |
}, | |
}; | |
package T1::Models; | |
use Ark::Models -Base; | |
register Digest => sub { | |
shift->ensure_class_loaded('Digest::SHA1'); | |
Digest::SHA1->new; | |
}; | |
package T1::Controller::Root; | |
use Ark 'Controller'; | |
__PACKAGE__->config->{namespace} = ''; | |
sub index :Path { | |
my ($self, $c) = @_; | |
if ($c->user && $c->user->authenticated) { | |
$c->res->body( 'logined: ' . $c->user->obj->{username} ); | |
} | |
else { | |
$c->res->body( 'require login' ); | |
} | |
} | |
sub login :Local { | |
my ($self, $c) = @_; | |
if (my $user = $c->authenticate({ username => 'user1', password => 'pass1' })) { | |
$c->res->body( 'login done' ); | |
} | |
} | |
} | |
plan 'no_plan'; | |
use Ark::Test 'T1', | |
components => [qw/Controller::Root/], | |
reuse_connection => 1; | |
is(get('/'), 'require login', 'not login ok'); | |
is(get('/login'), 'login done', 'login ok'); | |
is(get('/'), 'logined: user1', 'logined ok'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment