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
|
#!perl
use warnings;
use strict;
use Test::More;
use Test::Fatal;
use Redis::Fast;
use lib 't/tlib';
use Test::SpawnRedisServer;
my $password = 'very-very-long-strong-password';
my ($c, $srv) = redis(
password => $password,
);
END { $c->() if $c }
subtest 'no password' => sub {
my $o;
is(
exception { $o = Redis::Fast->new(server => $srv) },
undef, 'connect is success',
);
like(
exception { $o->get('foo') },
qr/\[get\] (NOAUTH Authentication required|ERR operation not permitted)/,
'but cannot execute any command except `auth`',
);
};
subtest 'wrong password' => sub {
my $o;
like(
exception { $o = Redis::Fast->new(server => $srv, password => 'wrong-password') },
qr/Redis server refused password/, 'connect is fail',
);
};
subtest 'correct password' => sub {
my $o;
is(
exception { $o = Redis::Fast->new(server => $srv, password => $password) },
undef, 'connect is success',
);
is(
exception { $o->get('foo') },
undef,
'can exeecute all command',
);
};
## All done
done_testing();
|