prepare for release of C::P::Authentication::Store::Htpasswd
[catagits/Catalyst-Authentication-Store-Htpasswd.git] / t / backend.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 19;
7
8 use File::Temp qw/tempfile/;
9
10 my $m; BEGIN { use_ok($m = "Catalyst::Plugin::Authentication::Store::Htpasswd::Backend") }
11
12 (undef, my $tmp) = tempfile();
13
14 my $passwd = Authen::Htpasswd->new($tmp);
15
16 $passwd->add_user("user", "s3cr3t");
17
18 can_ok($m, "new");
19 isa_ok(my $o = $m->new( $passwd ), $m);
20
21 can_ok($m, "file");
22 isa_ok( $o->file, "Authen::Htpasswd");
23
24 can_ok( $m, "user_supports");
25 ok( $m->user_supports(qw/password self_check/), "user_supports self check" );
26
27 can_ok($m, "get_user");
28 isa_ok( my $u = $o->get_user("user"), "Catalyst::Plugin::Authentication::Store::Htpasswd::User");
29 isa_ok( $u, "Catalyst::Plugin::Authentication::User");
30
31 can_ok( $u, "supports");
32 ok( $u->supports(qw/password self_check/), "htpasswd users check their own passwords");
33
34 can_ok( $u, "check_password");
35 ok( $u->check_password( "s3cr3t" ), "password is s3cr3t");
36
37 ok( $m->user_supports(qw/session/), "user_supports session");
38
39 is( $u->store, $o, "can get store");
40
41 can_ok( $m, "from_session" );
42 can_ok( $u, "for_session" );
43
44 my $recovered = $u->store->from_session( undef, $u->for_session );
45
46 is( $recovered->username, $u->username, "recovery from session works");