You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

337 lines
9.6 KiB

  1. --source include/have_plugin_auth.inc
  2. --source include/not_embedded.inc
  3. query_vertical SELECT PLUGIN_STATUS, PLUGIN_TYPE, PLUGIN_DESCRIPTION
  4. FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME='test_plugin_server';
  5. CREATE USER plug IDENTIFIED WITH 'test_plugin_server' AS 'plug_dest';
  6. CREATE USER plug_dest IDENTIFIED BY 'plug_dest_passwd';
  7. SELECT plugin,authentication_string FROM mysql.user WHERE User='plug';
  8. --echo ## test plugin auth
  9. --disable_query_log
  10. --error ER_ACCESS_DENIED_ERROR : this should fail : no grant
  11. connect(plug_con,localhost,plug,plug_dest);
  12. --enable_query_log
  13. GRANT PROXY ON plug_dest TO plug;
  14. --echo test proxies_priv columns
  15. --replace_column 7 xx
  16. SELECT * FROM mysql.proxies_priv;
  17. --echo test mysql.proxies_priv;
  18. SHOW CREATE TABLE mysql.proxies_priv;
  19. connect(plug_con,localhost,plug,plug_dest);
  20. connection plug_con;
  21. select USER(),CURRENT_USER();
  22. --echo ## test SET PASSWORD
  23. #--error ER_SET_PASSWORD_AUTH_PLUGIN
  24. SET PASSWORD = PASSWORD('plug_dest');
  25. connection default;
  26. disconnect plug_con;
  27. --echo ## test bad credentials
  28. --disable_query_log
  29. --error ER_ACCESS_DENIED_ERROR
  30. connect(plug_con,localhost,plug,bad_credentials);
  31. --enable_query_log
  32. --echo ## test bad default plugin : should get CR_AUTH_PLUGIN_CANNOT_LOAD
  33. --disable_result_log
  34. --disable_query_log
  35. --error 2059
  36. connect(plug_con_wrongp,localhost,plug,plug_dest,,,,,wrong_plugin_name);
  37. --enable_query_log
  38. --enable_result_log
  39. --echo ## test correct default plugin
  40. connect(plug_con_rightp,localhost,plug,plug_dest,,,,,auth_test_plugin);
  41. connection plug_con_rightp;
  42. select USER(),CURRENT_USER();
  43. connection default;
  44. disconnect plug_con_rightp;
  45. --echo ## test no_auto_create_user sql mode with plugin users
  46. SET @@sql_mode=no_auto_create_user;
  47. GRANT INSERT ON TEST.* TO grant_user IDENTIFIED WITH 'test_plugin_server';
  48. SET @@sql_mode=default;
  49. DROP USER grant_user;
  50. --echo ## test utf-8 user name
  51. CREATE USER `Ÿ` IDENTIFIED WITH 'test_plugin_server' AS 'plug_dest';
  52. GRANT PROXY ON plug_dest TO `Ÿ`;
  53. connect(non_ascii,localhost,Ÿ,plug_dest);
  54. connection non_ascii;
  55. select USER(),CURRENT_USER();
  56. connection default;
  57. disconnect non_ascii;
  58. DROP USER `Ÿ`;
  59. --echo ## test GRANT ... IDENTIFIED WITH/BY ...
  60. CREATE DATABASE test_grant_db;
  61. --echo # create new user via GRANT WITH
  62. GRANT ALL PRIVILEGES ON test_grant_db.* TO new_grant_user
  63. IDENTIFIED WITH 'test_plugin_server' AS 'plug_dest';
  64. GRANT PROXY ON plug_dest TO new_grant_user;
  65. connect(plug_con_grant,localhost,new_grant_user,plug_dest);
  66. connection plug_con_grant;
  67. select USER(),CURRENT_USER();
  68. USE test_grant_db;
  69. CREATE TABLE t1 (a INT);
  70. DROP TABLE t1;
  71. connection default;
  72. disconnect plug_con_grant;
  73. REVOKE ALL PRIVILEGES ON test_grant_db.* FROM new_grant_user;
  74. --echo # try re-create existing user via GRANT IDENTIFIED BY
  75. GRANT ALL PRIVILEGES ON test_grant_db.* TO new_grant_user
  76. IDENTIFIED BY 'unused_password';
  77. --echo # make sure password doesn't take precendence
  78. --disable_query_log
  79. --error ER_ACCESS_DENIED_ERROR
  80. connect(plug_con_grant_deny,localhost,new_grant_user,unused_password);
  81. --enable_query_log
  82. --echo #make sure plugin auth still available
  83. connect(plug_con_grant,localhost,new_grant_user,plug_dest);
  84. connection plug_con_grant;
  85. select USER(),CURRENT_USER();
  86. USE test_grant_db;
  87. CREATE TABLE t1 (a INT);
  88. DROP TABLE t1;
  89. connection default;
  90. disconnect plug_con_grant;
  91. DROP USER new_grant_user;
  92. --echo # try re-create existing user via GRANT IDENTIFIED WITH
  93. --error ER_GRANT_PLUGIN_USER_EXISTS
  94. GRANT ALL PRIVILEGES ON test_grant_db.* TO plug
  95. IDENTIFIED WITH 'test_plugin_server' AS 'plug_dest';
  96. --error ER_GRANT_PLUGIN_USER_EXISTS
  97. GRANT ALL PRIVILEGES ON test_grant_db.* TO plug_dest
  98. IDENTIFIED WITH 'test_plugin_server' AS 'plug_dest';
  99. --error ER_PARSE_ERROR
  100. REVOKE SELECT on test_grant_db.* FROM joro
  101. INDENTIFIED WITH 'test_plugin_server' AS 'plug_dest';
  102. --error ER_PARSE_ERROR
  103. REVOKE SELECT on test_grant_db.* FROM joro
  104. INDENTIFIED BY 'plug_dest_passwd';
  105. --error ER_PARSE_ERROR
  106. REVOKE SELECT on test_grant_db.* FROM joro
  107. INDENTIFIED BY PASSWORD 'plug_dest_passwd';
  108. DROP DATABASE test_grant_db;
  109. --echo ## GRANT PROXY tests
  110. CREATE USER grant_plug IDENTIFIED WITH 'test_plugin_server'
  111. AS 'grant_plug_dest';
  112. CREATE USER grant_plug_dest IDENTIFIED BY 'grant_plug_dest_passwd';
  113. CREATE USER grant_plug_dest2 IDENTIFIED BY 'grant_plug_dest_passwd2';
  114. --echo # ALL PRIVILEGES doesn't include PROXY
  115. GRANT ALL PRIVILEGES ON *.* TO grant_plug;
  116. --disable_query_log
  117. --error ER_ACCESS_DENIED_ERROR : this should fail : no grant
  118. connect(grant_plug_con,localhost,grant_plug,grant_plug_dest);
  119. --enable_query_log
  120. --error ER_PARSE_ERROR : this should fail : can't combine PROXY
  121. GRANT ALL PRIVILEGES,PROXY ON grant_plug_dest TO grant_plug;
  122. --echo this should fail : can't combine PROXY
  123. --error ER_PARSE_ERROR
  124. GRANT ALL SELECT,PROXY ON grant_plug_dest TO grant_plug;
  125. --echo # this should fail : no such grant
  126. --error ER_NONEXISTING_GRANT
  127. REVOKE PROXY ON grant_plug_dest FROM grant_plug;
  128. connect(grant_plug_dest_con,localhost,grant_plug_dest,grant_plug_dest_passwd);
  129. connection grant_plug_dest_con;
  130. --echo in grant_plug_dest_con
  131. --echo ## testing what an ordinary user can grant
  132. --echo this should fail : no rights to grant all
  133. --error ER_ACCESS_DENIED_NO_PASSWORD_ERROR
  134. GRANT PROXY ON ''@'' TO grant_plug;
  135. --echo this should fail : not the same user
  136. --error ER_ACCESS_DENIED_NO_PASSWORD_ERROR
  137. GRANT PROXY ON grant_plug TO grant_plug_dest;
  138. --echo this should fail : same user, but on a different host
  139. --error ER_ACCESS_DENIED_NO_PASSWORD_ERROR
  140. GRANT PROXY ON grant_plug_dest TO grant_plug;
  141. --echo this should work : same user
  142. GRANT PROXY ON grant_plug_dest@localhost TO grant_plug_dest2;
  143. REVOKE PROXY ON grant_plug_dest@localhost FROM grant_plug_dest2;
  144. --echo this should work : same user
  145. GRANT PROXY ON grant_plug_dest@localhost TO grant_plug WITH GRANT OPTION;
  146. REVOKE PROXY ON grant_plug_dest@localhost FROM grant_plug;
  147. --echo this should fail : can't create users
  148. --error ER_CANT_CREATE_USER_WITH_GRANT
  149. GRANT PROXY ON grant_plug_dest@localhost TO grant_plug@localhost;
  150. connection default;
  151. --echo in default connection
  152. disconnect grant_plug_dest_con;
  153. --echo # test what root can grant
  154. --echo should work : root has PROXY to all users
  155. GRANT PROXY ON ''@'' TO grant_plug;
  156. REVOKE PROXY ON ''@'' FROM grant_plug;
  157. --echo should work : root has PROXY to all users
  158. GRANT PROXY ON ''@'' TO proxy_admin IDENTIFIED BY 'test'
  159. WITH GRANT OPTION;
  160. --echo need USAGE : PROXY doesn't contain it.
  161. GRANT USAGE on *.* TO proxy_admin;
  162. connect (proxy_admin_con,localhost,proxy_admin,test);
  163. connection proxy_admin_con;
  164. --echo in proxy_admin_con;
  165. --echo should work : proxy_admin has proxy to ''@''
  166. GRANT PROXY ON future_user TO grant_plug;
  167. connection default;
  168. --echo in default connection
  169. disconnect proxy_admin_con;
  170. SHOW GRANTS FOR grant_plug;
  171. REVOKE PROXY ON future_user FROM grant_plug;
  172. SHOW GRANTS FOR grant_plug;
  173. --echo ## testing drop user
  174. CREATE USER test_drop@localhost;
  175. GRANT PROXY ON future_user TO test_drop@localhost;
  176. SHOW GRANTS FOR test_drop@localhost;
  177. DROP USER test_drop@localhost;
  178. SELECT * FROM mysql.proxies_priv WHERE Host = 'test_drop' AND User = 'localhost';
  179. DROP USER proxy_admin;
  180. DROP USER grant_plug,grant_plug_dest,grant_plug_dest2;
  181. --echo ## END GRANT PROXY tests
  182. --echo ## cleanup
  183. DROP USER plug;
  184. DROP USER plug_dest;
  185. --echo ## @@proxy_user tests
  186. CREATE USER plug IDENTIFIED WITH 'test_plugin_server' AS 'plug_dest';
  187. CREATE USER plug_dest IDENTIFIED BY 'plug_dest_passwd';
  188. GRANT PROXY ON plug_dest TO plug;
  189. SELECT USER(),CURRENT_USER(),@@LOCAL.proxy_user;
  190. --error ER_INCORRECT_GLOBAL_LOCAL_VAR
  191. SELECT @@GLOBAL.proxy_user;
  192. SELECT @@LOCAL.proxy_user;
  193. --error ER_INCORRECT_GLOBAL_LOCAL_VAR
  194. SET GLOBAL proxy_user = 'test';
  195. --error ER_INCORRECT_GLOBAL_LOCAL_VAR
  196. SET LOCAL proxy_user = 'test';
  197. SELECT @@LOCAL.proxy_user;
  198. connect(plug_con,localhost,plug,plug_dest);
  199. connection plug_con;
  200. --echo # in connection plug_con
  201. SELECT @@LOCAL.proxy_user;
  202. connection default;
  203. --echo # in connection default
  204. disconnect plug_con;
  205. --echo ## cleanup
  206. DROP USER plug;
  207. DROP USER plug_dest;
  208. --echo ## END @@proxy_user tests
  209. --echo ## @@external_user tests
  210. CREATE USER plug IDENTIFIED WITH 'test_plugin_server' AS 'plug_dest';
  211. CREATE USER plug_dest IDENTIFIED BY 'plug_dest_passwd';
  212. GRANT PROXY ON plug_dest TO plug;
  213. SELECT USER(),CURRENT_USER(),@@LOCAL.external_user;
  214. --error ER_INCORRECT_GLOBAL_LOCAL_VAR
  215. SELECT @@GLOBAL.external_user;
  216. SELECT @@LOCAL.external_user;
  217. --error ER_INCORRECT_GLOBAL_LOCAL_VAR
  218. SET GLOBAL external_user = 'test';
  219. --error ER_INCORRECT_GLOBAL_LOCAL_VAR
  220. SET LOCAL external_user = 'test';
  221. SELECT @@LOCAL.external_user;
  222. connect(plug_con,localhost,plug,plug_dest);
  223. connection plug_con;
  224. --echo # in connection plug_con
  225. SELECT @@LOCAL.external_user;
  226. connection default;
  227. --echo # in connection default
  228. disconnect plug_con;
  229. --echo ## cleanup
  230. DROP USER plug;
  231. DROP USER plug_dest;
  232. --echo ## END @@external_user tests
  233. --echo #
  234. --echo # Bug #56798 : Wrong credentials assigned when using a proxy user.
  235. --echo #
  236. GRANT ALL PRIVILEGES ON *.* TO power_user;
  237. GRANT USAGE ON anonymous_db.* TO ''@''
  238. IDENTIFIED WITH 'test_plugin_server' AS 'power_user';
  239. GRANT PROXY ON power_user TO ''@'';
  240. CREATE DATABASE confidential_db;
  241. connect(plug_con,localhost, test_login_user, power_user, confidential_db);
  242. SELECT user(),current_user(),@@proxy_user;
  243. connection default;
  244. disconnect plug_con;
  245. DROP USER power_user;
  246. DROP USER ''@'';
  247. DROP DATABASE confidential_db;
  248. --echo # Test case #2 (crash with double grant proxy)
  249. CREATE USER ''@'' IDENTIFIED WITH 'test_plugin_server' AS 'standard_user';
  250. CREATE USER standard_user;
  251. CREATE DATABASE shared;
  252. GRANT ALL PRIVILEGES ON shared.* TO standard_user;
  253. GRANT PROXY ON standard_user TO ''@'';
  254. --echo #should not crash
  255. GRANT PROXY ON standard_user TO ''@'';
  256. DROP USER ''@'';
  257. DROP USER standard_user;
  258. DROP DATABASE shared;