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