-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #686 from percona/pt-2247
Pt 2247
- Loading branch information
Showing
2 changed files
with
107 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env perl | ||
|
||
BEGIN { | ||
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n" | ||
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH}; | ||
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib"; | ||
}; | ||
|
||
use strict; | ||
use warnings FATAL => 'all'; | ||
use English qw(-no_match_vars); | ||
use Test::More; | ||
|
||
use PerconaTest; | ||
use Sandbox; | ||
use SqlModes; | ||
use VersionParser; | ||
require "$trunk/bin/pt-show-grants"; | ||
|
||
my $dp = new DSNParser(opts=>$dsn_opts); | ||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); | ||
my $dbh = $sb->get_dbh_for('master'); | ||
|
||
if ( !$dbh ) { | ||
plan skip_all => 'Cannot connect to sandbox master'; | ||
} | ||
|
||
if ( VersionParser->new($dbh)->flavor !~ m/maria/i ) { | ||
plan skip_all => "This test requires MariaDB"; | ||
} | ||
|
||
$sb->wipe_clean($dbh); | ||
|
||
my $output; | ||
my $cnf = '/tmp/12345/my.sandbox.cnf'; | ||
|
||
diag(`/tmp/12345/use -u root -e "CREATE USER 'sally'\@'%' IDENTIFIED BY 'A005?>6LZe1'"`); | ||
|
||
ok( | ||
`/tmp/12345/use -s -u sally -p'A005?>6LZe1' -e "SELECT 1" 2>/dev/null`, | ||
'User sally can log in before tests' | ||
); | ||
|
||
$output = output( | ||
sub { pt_show_grants::main('-F', $cnf, qw(--only sally)); } | ||
); | ||
|
||
like( | ||
$output, | ||
qr/CREATE USER IF NOT EXISTS `sally`@`%`;/, | ||
'CREATE USER printed' | ||
) or diag($output); | ||
|
||
like( | ||
$output, | ||
qr/ALTER USER `sally`@`%` IDENTIFIED BY PASSWORD '\*A5C09B5E9542E3C716E3E0A711336D9ABB48D89F';/, | ||
'ALTER USER printed' | ||
) or diag($output); | ||
|
||
diag(`/tmp/12345/use -u root -e "DROP USER 'sally'\@'%'"`); | ||
open(my $pipe, '|-', '/tmp/12345/use -u root'); | ||
print $pipe $output; | ||
close($pipe); | ||
|
||
ok( | ||
`/tmp/12345/use -s -u sally -p'A005?>6LZe1' -e "SELECT 1" 2>/dev/null`, | ||
'User sally can log in' | ||
) or diag($output); | ||
|
||
diag(`/tmp/12345/use -u root -e "DROP USER 'sally'\@'%'"`); | ||
|
||
# ############################################################################# | ||
# Done. | ||
# ############################################################################# | ||
$sb->wipe_clean($dbh); | ||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); | ||
done_testing; |