Files
percona-toolkit/t/pt-show-grants/pt-2247.t
Sveta Smirnova f3f4943d52 PT-2247 - pt-show-grants does not CREATE USER
- Removed option print_identified_with_as_hex, because it was already
  implemented in the PT-2190 fix
- Simplified patch
- Kept CREATE USER/ALTER USER sequence and extra DELETE from mysql.user
  table
- Added test case
2024-05-17 02:34:53 +03:00

78 lines
2.0 KiB
Perl

#!/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;