Add configuration vars for derived paths, too.
[blerg.git] / lib / perl / Blerg-Database / t / auth.t
1 use File::Path qw/remove_tree/;
2 use strict;
3 use warnings;
4
5 use Test::More tests => 17;
6 BEGIN { use_ok('Blerg::Database') };
7
8 ### Setup
9 my $test_user = 'barfy';
10 my $test_dir = "/tmp/blerg_test_$$";
11 mkdir $test_dir;
12 chdir $test_dir;
13 mkdir 'data';
14 mkdir 'hash_tags';
15 mkdir 'ref_tags';
16 my ($ptr, $password, $n);
17 $password = 'blargh';
18 $n = 0;
19
20 $ptr = Blerg::Database->open($test_user);
21 $ptr->close;
22
23 ### Auth (C interface)
24 is(   Blerg::Database::auth_set_password($test_user, $password), 1 );
25 isnt( Blerg::Database::auth_set_password('fakeuser', $password), 1 );
26
27 is(   Blerg::Database::auth_check_password($test_user, $password), 1 );
28 isnt( Blerg::Database::auth_check_password('fakeuser', $password), 1 );
29 isnt( Blerg::Database::auth_check_password($test_user, 'wrongpass'), 1 );
30
31 my $token = Blerg::Database::auth_login($test_user, $password);
32 ok( defined $token );
33 ok( length($token) == 32 );
34 ok( Blerg::Database::auth_check_token($test_user, $token) );
35 isnt( Blerg::Database::auth_check_token($test_user, 'badtoken'), 1 );
36 isnt( Blerg::Database::auth_check_token('fakeuser', $token), 1 );
37 ok( Blerg::Database::auth_logout($test_user, $token) );
38
39 $token = Blerg::Database::auth_login($test_user, 'wrongpass');
40 ok( not defined $token );
41
42 $token = Blerg::Database::auth_login('wronguser', $password);
43 ok( not defined $token );
44
45 isnt( Blerg::Database::auth_logout($test_user, 'badtoken'), 1 );
46 isnt( Blerg::Database::auth_logout('fakeuser', 'badtoken'), 1 );
47
48 Blerg::Database::auth_set_password($test_user, $password . 'X');
49 ok( Blerg::Database::auth_check_password($test_user, $password . 'X') );
50
51 END {
52         chdir;
53         remove_tree "/tmp/blerg_test_$$";
54 }