forked from UPC/ravada
-
Notifications
You must be signed in to change notification settings - Fork 0
/
60_user_sql.t
66 lines (46 loc) · 2.06 KB
/
60_user_sql.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use warnings;
use strict;
use Data::Dumper;
use Test::More;
use lib 't/lib';
use Test::Ravada;
use_ok('Ravada');
use_ok('Ravada::Auth::SQL');
my $ravada = Ravada->new(connector => connector(), config => 't/etc/ravada.conf');
$ravada->_install();
Ravada::Auth::SQL::add_user(name => 'root', password => 'root', is_admin => 1);
Ravada::Auth::enable_LDAP(0);
{
my $user_fail;
eval { $user_fail = Ravada::Auth::SQL->new(name => 'root',password => 'fail')};
ok(!$user_fail,"User should fail, got ".Dumper($user_fail));
}
{
my $user = Ravada::Auth::SQL->new(name => 'root',password => 'root');
ok($user);
ok($user->id, "User ".$user->name." has no id");
ok($user->is_admin,"User ".$user->name." should be admin ".Dumper($user->{_data}));
my $user2 = Ravada::Auth::SQL->search_by_id($user->id );
ok($user2, "I can't open user with id") or return;
ok($user2->id eq $user->id ,"Expecting user id=".$user->id." , got ".$user2->id);
ok($user2->name eq $user->name,"Expecting user name =".$user->name." , got ".$user2->name);
ok($user2->is_admin,"User ".$user2->name." should be admin ".Dumper($user2->{_data}));
my $user3 = Ravada::Auth::login('root','root');
ok($user3,"No user returned from Ravada::Auth::login");
ok(ref $user && ref($user3) eq 'Ravada::Auth::SQL');
ok($user3->is_admin,"User ".$user3->name." should be admin ".Dumper($user3->{_data}));
}
Ravada::Auth::SQL::add_user(name => 'mcnulty', password => 'jameson');
{
my $mcnulty= Ravada::Auth::SQL->new(name => 'mcnulty',password => 'jameson');
ok($mcnulty);
ok(!$mcnulty->is_admin,"User ".$mcnulty->name." should not be admin "
.Dumper($mcnulty->{_data}));
my @messages = $mcnulty->messages();
ok(!scalar @messages);
my $user3 = Ravada::Auth::login('mcnulty','jameson');
ok($user3,"No user returned from Ravada::Auth::login");
ok(ref $user3 && ref($user3) eq 'Ravada::Auth::SQL');
ok(!$user3->is_admin,"User ".$user3->name." should not be admin ".Dumper($user3->{_data}));
}
done_testing();