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
|
#!perl
use warnings;
use strict;
use Test::More;
use Test::Fatal;
use Redis::Fast;
use lib 't/tlib';
use Test::SpawnRedisServer;
use constant SSL_AVAILABLE => eval { require IO::Socket::SSL };
my $password = 'very-very-long-strong-password';
my ($c, $t, $srv) = redis(
password => $password,
);
my $use_ssl = $t ? SSL_AVAILABLE : 0;
END {
$c->() if $c;
$t->() if $t;
}
subtest 'no password' => sub {
my $o;
is(
exception { $o = Redis::Fast->new(server => $srv, ssl => $use_ssl, SSL_verify_mode => 0) },
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', ssl => $use_ssl, SSL_verify_mode => 0) },
qr/Redis server refused password/, 'connect is fail',
);
};
subtest 'correct password' => sub {
my $o;
is(
exception { $o = Redis::Fast->new(server => $srv, password => $password, ssl => $use_ssl, SSL_verify_mode => 0) },
undef, 'connect is success',
);
is(
exception { $o->get('foo') },
undef,
'can exeecute all command',
);
};
## All done
done_testing();
|