File: 02module_auth.t

package info (click to toggle)
libbot-basicbot-pluggable-perl 1.30%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 516 kB
  • sloc: perl: 3,153; makefile: 17
file content (70 lines) | stat: -rwxr-xr-x 2,422 bytes parent folder | download | duplicates (5)
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
67
68
69
70
#!/usr/bin/perl
use warnings;
use strict;

use Test::More tests => 27;
use Test::Bot::BasicBot::Pluggable;

my $bot = Test::Bot::BasicBot::Pluggable->new();

ok( my $auth = $bot->load('Auth'), "created auth module" );

is(
    $bot->tell_private("!auth"),
    "Usage: !auth <username> <password>",
    "auth without arguments"
);
is(
    $bot->tell_private("!adduser"),
    "Usage: !adduser <username> <password>",
    "adduser without arguments"
);
is(
    $bot->tell_private("!deluser"),
    "Usage: !deluser <username>",
    "deluser without arguments"
);
is(
    $bot->tell_private("!adduser foo bar"),
    "You need to authenticate.",
    "adding users without authentication"
);
is(
    $bot->tell_private("!deluser foo"),
    "You need to authenticate.",
    "deleting users without authentication"
);

ok( !$auth->authed('test_user'),              "test_user not authed yet" );
ok( $bot->tell_private("!auth admin muppet"), "sent bad login" );
ok( !$auth->authed('test_user'),              "test_user not authed yet" );
ok( $bot->tell_private("!auth admin julia"),  "sent good login" );
ok( $auth->authed('test_user'),               "test_user authed now" );

ok( $bot->tell_private("!adduser test_user test_user"),
    "added test_user user" );
ok( $bot->tell_private("!auth test_user fred"), "not logged in as test_user" );
ok( !$auth->authed('test_user'),                "not still authed" );
ok( $bot->tell_private("!auth test_user test_user"), "logged in as test_user" );
ok( $auth->authed('test_user'),                      "still authed" );

ok( $bot->tell_private("!deluser admin"),    "deleted admin user" );
ok( $bot->tell_private("!auth admin julia"), "tried login" );
ok( !$auth->authed('test_user'),             "not authed" );

ok( $bot->tell_private("!auth test_user test_user"), "logged in as test_user" );
ok( $bot->tell_private("!password test_user dave"),    "changed password" );
ok( $bot->tell_private("!auth test_user dave"),      "tried login" );
ok( $auth->authed('test_user'),                      "authed" );

is( $bot->tell_private("auth test_user dave"),
    "", "ignore commands without leading !" );
is( $bot->tell_indirect("!auth test_user dave"), "", "ignore public commands" );

is( $bot->tell_private("!users"), "Users: test_user.", "listing of users" );

like(
    $bot->tell_direct("help Auth"),
qr/Authenticator for admin-level commands. Usage:.+/,
    'checking help text'
);