add 5.7 compatibility for pt-show-grants

This commit is contained in:
frank-cizmich
2016-02-18 17:50:11 -03:00
parent 1f77f47251
commit 219b70b366
9 changed files with 2569 additions and 18 deletions

View File

@@ -49,29 +49,64 @@ $modes->restore_original_modes;
$output = output(
sub { pt_show_grants::main('-F', $cnf, qw(--only bob --no-header)); }
);
my $expected_57 = <<'END_OUTPUT_1';
-- Grants for 'bob'@'%'
CREATE USER IF NOT EXISTS 'bob'@'%';
ALTER USER 'bob'@'%' IDENTIFIED WITH 'mysql_native_password' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK;
GRANT USAGE ON *.* TO 'bob'@'%';
-- Grants for 'bob'@'192.168.1.1'
CREATE USER IF NOT EXISTS 'bob'@'192.168.1.1';
ALTER USER 'bob'@'192.168.1.1' IDENTIFIED WITH 'mysql_native_password' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK;
GRANT USAGE ON *.* TO 'bob'@'192.168.1.1';
-- Grants for 'bob'@'localhost'
CREATE USER IF NOT EXISTS 'bob'@'localhost';
ALTER USER 'bob'@'localhost' IDENTIFIED WITH 'mysql_native_password' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK;
GRANT USAGE ON *.* TO 'bob'@'localhost';
END_OUTPUT_1
my $expected_56 = <<'END_OUTPUT_2';
-- Grants for 'bob'@'%'
GRANT USAGE ON *.* TO 'bob'@'%';
-- Grants for 'bob'@'192.168.1.1'
GRANT USAGE ON *.* TO 'bob'@'192.168.1.1';
-- Grants for 'bob'@'localhost'
GRANT USAGE ON *.* TO 'bob'@'localhost';
END_OUTPUT_2
my $expected = $sandbox_version < '5.7' ? $expected_56 : $expected_57;
is(
$output,
"-- Grants for 'bob'\@'%'
GRANT USAGE ON *.* TO 'bob'\@'%';
-- Grants for 'bob'\@'192.168.1.1'
GRANT USAGE ON *.* TO 'bob'\@'192.168.1.1';
-- Grants for 'bob'\@'localhost'
GRANT USAGE ON *.* TO 'bob'\@'localhost';
",
$expected,
'--only user gets grants for user on all hosts (issue 551)'
);
$output = output(
sub { pt_show_grants::main('-F', $cnf, qw(--only bob@192.168.1.1 --no-header)); }
);
$expected_57 = <<'END_OUTPUT_3';
-- Grants for 'bob'@'192.168.1.1'
CREATE USER IF NOT EXISTS 'bob'@'192.168.1.1';
ALTER USER 'bob'@'192.168.1.1' IDENTIFIED WITH 'mysql_native_password' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK;
GRANT USAGE ON *.* TO 'bob'@'192.168.1.1';
END_OUTPUT_3
$expected_56 = <<'END_OUTPUT_4';
-- Grants for 'bob'@'192.168.1.1'
GRANT USAGE ON *.* TO 'bob'@'192.168.1.1';
END_OUTPUT_4
$expected = $sandbox_version < '5.7' ? $expected_56 : $expected_57;
is(
$output,
"-- Grants for 'bob'\@'192.168.1.1'
GRANT USAGE ON *.* TO 'bob'\@'192.168.1.1';
",
$expected,
'--only user@host'
);
diag(`/tmp/12345/use -u root -e "DROP USER 'bob'\@'%'"`);
diag(`/tmp/12345/use -u root -e "DROP USER 'bob'\@'localhost'"`);
diag(`/tmp/12345/use -u root -e "DROP USER 'bob'\@'192.168.1.1'"`);

View File

@@ -102,49 +102,56 @@ $modes->del('NO_AUTO_CREATE_USER');
diag(`/tmp/12345/use -u root -e "GRANT SELECT(DateCreated, PckPrice, PaymentStat, SANumber) ON test.t TO 'sally'\@'%'"`);
diag(`/tmp/12345/use -u root -e "GRANT SELECT(city_id), INSERT(city) ON sakila.city TO 'sally'\@'%'"`);
$modes->restore_original_modes();
my $postfix = $sandbox_version < '5.7' ? '' : '-57';
ok(
no_diff(
sub { pt_show_grants::main('-F', $cnf, qw(--only sally --no-header)) },
"t/pt-show-grants/samples/column-grants.txt",
"t/pt-show-grants/samples/column-grants$postfix.txt",
stderr => 1,
),
"Column-level grants (bug 866075)"
);
ok(
no_diff(
sub { pt_show_grants::main('-F', $cnf, qw(--only sally --no-header),
qw(--separate)) },
"t/pt-show-grants/samples/column-grants-separate.txt",
"t/pt-show-grants/samples/column-grants-separate$postfix.txt",
stderr => 1,
),
),
"Column-level grants --separate (bug 866075)"
);
ok(
no_diff(
sub { pt_show_grants::main('-F', $cnf, qw(--only sally --no-header),
qw(--separate --revoke)) },
"t/pt-show-grants/samples/column-grants-separate-revoke.txt",
"t/pt-show-grants/samples/column-grants-separate-revoke$postfix.txt",
stderr => 1,
),
"Column-level grants --separate --revoke (bug 866075)"
);
diag(`/tmp/12345/use -u root -e "GRANT SELECT ON sakila.city TO 'sally'\@'%'"`);
ok(
no_diff(
sub { pt_show_grants::main('-F', $cnf, qw(--only sally --no-header)) },
"t/pt-show-grants/samples/column-grants-combined.txt",
"t/pt-show-grants/samples/column-grants-combined$postfix.txt",
stderr => 1,
keep_output => 1,
),
"Column-level grants combined with table-level grants on the same table (bug 866075)"
);
diag(`/tmp/12345/use -u root -e "DROP USER 'sally'\@'%'"`);
DONE:
# #############################################################################
# Done.
# #############################################################################

View File

@@ -63,7 +63,7 @@ like(
$output,
qr/REVOKE USAGE ON \*\.\* FROM ''\@'';/,
'Prints revoke for anonymous user (issue 445)'
);
) or diag($output);
diag(`/tmp/12345/use -u root -e "DROP USER ''\@''"`);
$output = `/tmp/12345/use -e "SELECT user FROM mysql.user WHERE user = ''"`;

View File

@@ -0,0 +1,6 @@
-- Grants for 'sally'@'%'
CREATE USER IF NOT EXISTS 'sally'@'%';
ALTER USER 'sally'@'%' IDENTIFIED WITH 'mysql_native_password' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK;
GRANT INSERT (city), SELECT (city_id) ON `sakila`.`city` TO 'sally'@'%';
GRANT SELECT (SANumber, DateCreated, PaymentStat, PckPrice) ON `test`.`t` TO 'sally'@'%';
GRANT USAGE ON *.* TO 'sally'@'%';

View File

@@ -0,0 +1,6 @@
-- Grants for 'sally'@'%'
CREATE USER IF NOT EXISTS 'sally'@'%';
ALTER USER 'sally'@'%' IDENTIFIED WITH 'mysql_native_password' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK;
GRANT INSERT (city), SELECT, SELECT (city_id) ON `sakila`.`city` TO 'sally'@'%';
GRANT SELECT (SANumber, DateCreated, PaymentStat, PckPrice) ON `test`.`t` TO 'sally'@'%';
GRANT USAGE ON *.* TO 'sally'@'%';

View File

@@ -0,0 +1,7 @@
-- Grants for 'sally'@'%'
CREATE USER IF NOT EXISTS 'sally'@'%';
ALTER USER 'sally'@'%' IDENTIFIED WITH 'mysql_native_password' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK;
GRANT INSERT (city) ON `sakila`.`city` TO 'sally'@'%';
GRANT SELECT (SANumber, DateCreated, PaymentStat, PckPrice) ON `test`.`t` TO 'sally'@'%';
GRANT SELECT (city_id) ON `sakila`.`city` TO 'sally'@'%';
GRANT USAGE ON *.* TO 'sally'@'%';

View File

@@ -0,0 +1,12 @@
-- Revoke statements for 'sally'@'%'
REVOKE INSERT (city) ON `sakila`.`city` FROM 'sally'@'%';
REVOKE SELECT (SANumber, DateCreated, PaymentStat, PckPrice) ON `test`.`t` FROM 'sally'@'%';
REVOKE SELECT (city_id) ON `sakila`.`city` FROM 'sally'@'%';
REVOKE USAGE ON *.* FROM 'sally'@'%';
-- Grants for 'sally'@'%'
CREATE USER IF NOT EXISTS 'sally'@'%';
ALTER USER 'sally'@'%' IDENTIFIED WITH 'mysql_native_password' REQUIRE NONE PASSWORD EXPIRE DEFAULT ACCOUNT UNLOCK;
GRANT INSERT (city) ON `sakila`.`city` TO 'sally'@'%';
GRANT SELECT (SANumber, DateCreated, PaymentStat, PckPrice) ON `test`.`t` TO 'sally'@'%';
GRANT SELECT (city_id) ON `sakila`.`city` TO 'sally'@'%';
GRANT USAGE ON *.* TO 'sally'@'%';