| 1 |
#!/usr/bin/perl |
|---|
| 2 |
use warnings; |
|---|
| 3 |
use strict; |
|---|
| 4 |
use lib qw(./lib); |
|---|
| 5 |
|
|---|
| 6 |
use Test::More no_plan => 1; |
|---|
| 7 |
|
|---|
| 8 |
use Bot::BasicBot::Pluggable; |
|---|
| 9 |
use Bot::BasicBot::Pluggable::Module::Auth; |
|---|
| 10 |
|
|---|
| 11 |
our $store; |
|---|
| 12 |
no warnings 'redefine'; |
|---|
| 13 |
sub Bot::BasicBot::Pluggable::Module::store { |
|---|
| 14 |
$store ||= Bot::BasicBot::Pluggable::Store->new; |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
ok(my $auth = Bot::BasicBot::Pluggable::Module::Auth->new(), "created auth module"); |
|---|
| 18 |
|
|---|
| 19 |
ok(!$auth->authed('bob'), "bob not authed yet"); |
|---|
| 20 |
ok(command("!auth admin muppet"), "sent bad login"); |
|---|
| 21 |
ok(!$auth->authed('bob'), "bob not authed yet"); |
|---|
| 22 |
ok(command("!auth admin julia"), "sent good login"); |
|---|
| 23 |
ok($auth->authed('bob'), "bob authed now"); |
|---|
| 24 |
|
|---|
| 25 |
ok(command("!adduser bob bob"), "added bob user"); |
|---|
| 26 |
ok(command("!auth bob fred"), "not logged in as bob"); |
|---|
| 27 |
ok(!$auth->authed('bob'), "not still authed"); |
|---|
| 28 |
ok(command("!auth bob bob"), "logged in as bob"); |
|---|
| 29 |
ok($auth->authed('bob'), "still authed"); |
|---|
| 30 |
|
|---|
| 31 |
ok(command("!deluser admin"), "deleted admin user"); |
|---|
| 32 |
ok(command("!auth admin julia"), "tried login"); |
|---|
| 33 |
ok(!$auth->authed('bob'), "not authed"); |
|---|
| 34 |
|
|---|
| 35 |
ok(command("!auth bob bob"), "logged in as bob"); |
|---|
| 36 |
ok(command("!passwd bob dave"), "changed password"); |
|---|
| 37 |
ok(command("!auth bob dave"), "tried login"); |
|---|
| 38 |
ok($auth->authed('bob'), "authed"); |
|---|
| 39 |
|
|---|
| 40 |
sub command { |
|---|
| 41 |
my $body = shift; |
|---|
| 42 |
my $response = $auth->said( { |
|---|
| 43 |
address => 1, body => $body, who => 'bob' |
|---|
| 44 |
}, 1 ); |
|---|
| 45 |
#warn "$response\n"; |
|---|
| 46 |
return $response; |
|---|
| 47 |
} |
|---|