Commit | Line | Data |
e8a7c384 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
cedb9fb4 |
6 | use Test::More tests => 19; |
e8a7c384 |
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 | |
3e0bbcff |
14 | my $passwd = Authen::Htpasswd->new($tmp); |
e8a7c384 |
15 | |
3e0bbcff |
16 | $passwd->add_user("user", "s3cr3t"); |
e8a7c384 |
17 | |
e8a7c384 |
18 | can_ok($m, "new"); |
19 | isa_ok(my $o = $m->new( $passwd ), $m); |
20 | |
21 | can_ok($m, "file"); |
3e0bbcff |
22 | isa_ok( $o->file, "Authen::Htpasswd"); |
e8a7c384 |
23 | |
e8a7c384 |
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 | |
039544ff |
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"); |