25
25
#include < algorithm>
26
26
#include < array>
27
27
#include < set>
28
- #include < unordered_set>
29
28
30
29
// needs to be included first for FRIEND_TEST
31
30
#include " unittest/gprod_clean.h"
32
31
33
32
#include " modules/util/dump/schema_dumper.h"
34
33
35
- #include " modules/util/load/dump_loader.h"
36
34
#include " mysqlshdk/libs/db/mysql/session.h"
37
35
#include " mysqlshdk/libs/storage/backend/file.h"
38
36
#include " mysqlshdk/libs/utils/utils_file.h"
@@ -789,30 +787,10 @@ TEST_F(Schema_dumper_test, dump_filtered_grants) {
789
787
" CREATE USER IF NOT EXISTS 'admin2'@'localhost' IDENTIFIED BY 'pwd';" );
790
788
session->execute (
791
789
" GRANT ALL ON *.* TO 'admin2'@'localhost' WITH GRANT OPTION;" );
792
- session->execute (
793
- " CREATE USER IF NOT EXISTS 'superfirst'@'localhost' IDENTIFIED BY "
794
- " 'pwd';" );
795
- session->execute (
796
- " GRANT SUPER, LOCK TABLES ON *.* TO 'superfirst'@'localhost';" );
797
- session->execute (
798
- " CREATE USER IF NOT EXISTS 'superafter'@'localhost' IDENTIFIED BY "
799
- " 'pwd';" );
800
- session->execute (
801
- " GRANT INSERT,super, UPDATE ON *.* TO 'superafter'@'localhost';" );
802
- session->execute (
803
- " CREATE USER IF NOT EXISTS 'superonly'@'localhost' IDENTIFIED BY "
804
- " 'pwd';" );
805
- session->execute (" GRANT SUPER, RELOAD ON *.* TO 'superonly'@'localhost';" );
806
790
session->execute (
807
791
" CREATE USER IF NOT EXISTS 'dumptestuser'@'localhost' IDENTIFIED BY "
808
792
" 'pwd';" );
809
793
session->execute (" GRANT SELECT ON * . * TO 'dumptestuser'@'localhost';" );
810
- session->execute (
811
- " CREATE USER IF NOT EXISTS 'abr@dab'@'localhost' IDENTIFIED BY "
812
- " 'pwd';" );
813
- session->execute (
814
- " GRANT INSERT,SUPER,FILE,LOCK TABLES , reload, "
815
- " SELECT ON * . * TO 'abr@dab'@'localhost';" );
816
794
std::string partial_revoke = " ON" ;
817
795
if (_target_server_version >= mysqlshdk::utils::Version (8 , 0 , 20 )) {
818
796
partial_revoke = session->query (" show variables like 'partial_revokes';" )
@@ -907,34 +885,13 @@ TEST_F(Schema_dumper_test, dump_filtered_grants) {
907
885
EXPECT_THAT (out,
908
886
AnyOf (HasSubstr (dumptestuser),
909
887
HasSubstr (shcore::str_replace (dumptestuser, " '" , " `" ))));
910
- EXPECT_THAT (out, HasSubstr (" -- begin user 'abr@dab'@'localhost'" ));
911
888
912
889
if (_target_server_version >= mysqlshdk::utils::Version (8 , 0 , 20 )) {
913
890
EXPECT_THAT (out,
914
891
HasSubstr (" GRANT SELECT ON *.* TO `dumptestuser`@`localhost`" ));
915
- EXPECT_THAT (
916
- out,
917
- HasSubstr (" GRANT LOCK TABLES ON *.* TO `superfirst`@`localhost`;" ));
918
- EXPECT_THAT (
919
- out,
920
- HasSubstr (" GRANT INSERT, UPDATE ON *.* TO `superafter`@`localhost`;" ));
921
- EXPECT_THAT (out, Not (HasSubstr (" TO `superonly`@`localhost`;" )));
922
- EXPECT_THAT (out, HasSubstr (R"( -- begin grants 'abr@dab'@'localhost'
923
- GRANT SELECT, INSERT, LOCK TABLES ON *.* TO `abr@dab`@`localhost`;
924
- -- end grants 'abr@dab'@'localhost')" ));
925
892
} else {
926
893
EXPECT_THAT (
927
894
out, HasSubstr (" GRANT SELECT ON *.* TO 'dumptestuser'@'localhost';" ));
928
- EXPECT_THAT (
929
- out,
930
- HasSubstr (" GRANT LOCK TABLES ON *.* TO 'superfirst'@'localhost';" ));
931
- EXPECT_THAT (
932
- out,
933
- HasSubstr (" GRANT INSERT, UPDATE ON *.* TO 'superafter'@'localhost';" ));
934
- EXPECT_THAT (out, Not (HasSubstr (" TO 'superonly'@'localhost';" )));
935
- EXPECT_THAT (out, HasSubstr (R"( -- begin grants 'abr@dab'@'localhost'
936
- GRANT SELECT, INSERT, LOCK TABLES ON *.* TO 'abr@dab'@'localhost';
937
- -- end grants 'abr@dab'@'localhost')" ));
938
895
}
939
896
EXPECT_THAT (out, Not (HasSubstr (" SUPER" )));
940
897
@@ -945,11 +902,7 @@ GRANT SELECT, INSERT, LOCK TABLES ON *.* TO 'abr@dab'@'localhost';
945
902
testutil->call_mysqlsh_c ({_mysql_uri, " --sql" , " -f" , file_path});
946
903
EXPECT_TRUE (output_handler.std_err .empty ());
947
904
948
- session->execute (" drop user 'superfirst'@'localhost';" );
949
- session->execute (" drop user 'superafter'@'localhost';" );
950
- session->execute (" drop user 'superonly'@'localhost';" );
951
905
session->execute (" drop user 'dumptestuser'@'localhost';" );
952
- session->execute (" drop user 'abr@dab'@'localhost';" );
953
906
if (_target_server_version >= mysqlshdk::utils::Version (8 , 0 , 20 )) {
954
907
session->execute (" DROP ROLE da_dumper" );
955
908
session->execute (" DROP USER `dave`@`%`" );
@@ -958,6 +911,74 @@ GRANT SELECT, INSERT, LOCK TABLES ON *.* TO 'abr@dab'@'localhost';
958
911
}
959
912
}
960
913
914
+ TEST_F (Schema_dumper_test, dump_filtered_grants_super_priv) {
915
+ // Skip if version >= 8.4. Super has been removed in 8.4.
916
+ if (_target_server_version >= mysqlshdk::utils::Version (8 , 4 )) {
917
+ SKIP_TEST (" SUPER has been removed in 8.4." );
918
+ };
919
+
920
+ session->execute (
921
+ " CREATE USER IF NOT EXISTS 'superfirst'@'localhost' IDENTIFIED BY "
922
+ " 'pwd';" );
923
+ session->execute (" GRANT SUPER ON *.* TO 'superfirst'@'localhost';" );
924
+ session->execute (" GRANT LOCK TABLES ON *.* TO 'superfirst'@'localhost';" );
925
+ session->execute (
926
+ " CREATE USER IF NOT EXISTS 'superafter'@'localhost' IDENTIFIED BY "
927
+ " 'pwd';" );
928
+ session->execute (" GRANT INSERT, UPDATE ON *.* TO 'superafter'@'localhost';" );
929
+ session->execute (" GRANT SUPER ON *.* TO 'superafter'@'localhost';" );
930
+ session->execute (
931
+ " CREATE USER IF NOT EXISTS 'superonly'@'localhost' IDENTIFIED BY "
932
+ " 'pwd';" );
933
+ session->execute (" GRANT RELOAD ON *.* TO 'superonly'@'localhost';" );
934
+ session->execute (" GRANT SUPER ON *.* TO 'superonly'@'localhost';" );
935
+ session->execute (
936
+ " CREATE USER IF NOT EXISTS 'abr@dab'@'localhost' IDENTIFIED BY "
937
+ " 'pwd';" );
938
+ session->execute (
939
+ " GRANT INSERT,SUPER,FILE,LOCK TABLES , reload, "
940
+ " SELECT ON * . * TO 'abr@dab'@'localhost';" );
941
+
942
+ Schema_dumper sd (session);
943
+ sd.opt_mysqlaas = true ;
944
+ sd.opt_strip_restricted_grants = true ;
945
+ Filtering_options filters;
946
+ filters.users ().exclude (
947
+ std::array{" mysql.infoschema" , " mysql.session" , " mysql.sys" , " root" });
948
+ EXPECT_GE (sd.dump_grants (file.get (), filters).size (), 3 );
949
+ EXPECT_TRUE (output_handler.std_err .empty ());
950
+ wipe_all ();
951
+ file->flush ();
952
+ file->close ();
953
+ auto out = testutil->cat_file (file_path);
954
+
955
+ EXPECT_THAT (
956
+ out, HasSubstr (" GRANT LOCK TABLES ON *.* TO 'superfirst'@'localhost';" ));
957
+ EXPECT_THAT (
958
+ out,
959
+ HasSubstr (" GRANT INSERT, UPDATE ON *.* TO 'superafter'@'localhost';" ));
960
+ EXPECT_THAT (out, Not (HasSubstr (" TO 'superonly'@'localhost';" )));
961
+
962
+ EXPECT_THAT (out, HasSubstr (" -- begin user 'abr@dab'@'localhost'" ));
963
+ EXPECT_THAT (out, HasSubstr (R"( -- begin grants 'abr@dab'@'localhost'
964
+ GRANT SELECT, INSERT, LOCK TABLES ON *.* TO 'abr@dab'@'localhost';
965
+ -- end grants 'abr@dab'@'localhost')" ));
966
+
967
+ EXPECT_THAT (out, Not (HasSubstr (" SUPER" )));
968
+
969
+ EXPECT_THAT (out, Not (HasSubstr (" 'root'" )));
970
+ EXPECT_THAT (out, Not (HasSubstr (" EXISTS 'mysql" )));
971
+
972
+ wipe_all ();
973
+ testutil->call_mysqlsh_c ({_mysql_uri, " --sql" , " -f" , file_path});
974
+ EXPECT_TRUE (output_handler.std_err .empty ());
975
+
976
+ session->execute (" drop user 'superfirst'@'localhost';" );
977
+ session->execute (" drop user 'superafter'@'localhost';" );
978
+ session->execute (" drop user 'superonly'@'localhost';" );
979
+ session->execute (" drop user 'abr@dab'@'localhost';" );
980
+ }
981
+
961
982
TEST_F (Schema_dumper_test, opt_mysqlaas) {
962
983
Schema_dumper sd (session);
963
984
sd.opt_mysqlaas = true ;
0 commit comments