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