1 use File::Path qw/remove_tree/;
5 use Test::More tests => 21;
6 BEGIN { use_ok('Blerg::Database') };
9 my $test_user = 'barfy';
10 my $test_dir = "/tmp/blerg_test_$$";
17 $ENV{BLERG_PATH} = $test_dir;
18 Blerg::Database::init();
20 my ($ptr, $password, $n);
24 $ptr = Blerg::Database->open($test_user);
27 ### Auth (C interface)
28 is( Blerg::Database::auth_set_password($test_user, $password), 1 );
29 isnt( Blerg::Database::auth_set_password('fakeuser', $password), 1 );
31 is( Blerg::Database::auth_check_password($test_user, $password), 1 );
32 isnt( Blerg::Database::auth_check_password('fakeuser', $password), 1 );
33 isnt( Blerg::Database::auth_check_password($test_user, 'wrongpass'), 1 );
35 my $token = Blerg::Database::auth_login($test_user, $password);
37 ok( length($token) == 32 );
38 ok( Blerg::Database::auth_check_token($test_user, $token) );
39 isnt( Blerg::Database::auth_check_token($test_user, 'badtoken'), 1 );
40 isnt( Blerg::Database::auth_check_token('fakeuser', $token), 1 );
41 ok( Blerg::Database::auth_logout($test_user, $token) );
43 $token = Blerg::Database::auth_login($test_user, 'wrongpass');
44 ok( not defined $token );
46 $token = Blerg::Database::auth_login('wronguser', $password);
47 ok( not defined $token );
49 isnt( Blerg::Database::auth_logout($test_user, 'badtoken'), 1 );
50 isnt( Blerg::Database::auth_logout('fakeuser', 'badtoken'), 1 );
52 my $counter1 = Blerg::Database::auth_get_counter('fakeuser');
53 ok( !defined $counter1 );
55 $counter1 = Blerg::Database::auth_get_counter($test_user);
56 ok( defined $counter1 );
59 Blerg::Database::auth_set_password($test_user, $password . 'X');
60 ok( Blerg::Database::auth_check_password($test_user, $password . 'X') );
62 my $counter2 = Blerg::Database::auth_get_counter($test_user);
63 ok( $counter1 != $counter2 );
67 remove_tree "/tmp/blerg_test_$$";