mirror of https://github.com/sysown/proxysql
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.
532 lines
12 KiB
532 lines
12 KiB
/*
|
|
TAP Tests for database privileges
|
|
*/
|
|
|
|
BEGIN;
|
|
CREATE DATABASE IF NOT EXISTS taptest;
|
|
|
|
-- setup for tests
|
|
DELIMITER //
|
|
DROP PROCEDURE IF EXISTS taptest.dropusers //
|
|
CREATE PROCEDURE taptest.dropusers()
|
|
DETERMINISTIC
|
|
BEGIN
|
|
-- This procedure is only here in the event that the tests
|
|
-- fail due to a syntax error in which case IF EXISTS (> 5.6) will not work to tidy up
|
|
-- extant user records
|
|
IF (SELECT COUNT(*) FROM mysql.user WHERE user = '__tapuser__' AND host = 'localhost') > 0 THEN
|
|
DROP USER '__tapuser__'@'localhost';
|
|
END IF;
|
|
IF (SELECT COUNT(*) FROM mysql.user WHERE user = '__usage__' AND host = 'localhost') > 0 THEN
|
|
DROP USER '__usage__'@'localhost';
|
|
END IF;
|
|
IF (SELECT COUNT(*) FROM mysql.user WHERE user = '' AND host = 'localhost') > 0 THEN
|
|
DROP USER ''@'localhost';
|
|
END IF;
|
|
IF (SELECT COUNT(*) FROM mysql.user WHERE user = '__taprole__' AND host = 'localhost') > 0 THEN
|
|
DROP USER '__taprole__'@'localhost';
|
|
END IF;
|
|
END //
|
|
|
|
DELIMITER ;
|
|
|
|
CALL taptest.dropusers();
|
|
DROP PROCEDURE IF EXISTS taptest.dropusers;
|
|
|
|
DELIMITER //
|
|
DROP PROCEDURE IF EXISTS taptest.createusers //
|
|
CREATE PROCEDURE taptest.createusers()
|
|
DETERMINISTIC
|
|
BEGIN
|
|
-- This procedure allows create user syntax to accomodate changes in
|
|
-- CREATE USER in 8.0.11
|
|
DECLARE myver INT;
|
|
|
|
SET myver = (SELECT tap.mysql_version());
|
|
SET @sql1 = "CREATE USER '__tapuser__'@'localhost' IDENTIFIED BY '__dgfjhasdkfa__'";
|
|
SET @sql2 = "CREATE USER '__usage__'@'localhost'";
|
|
|
|
PREPARE stmt1 FROM @sql1;
|
|
EXECUTE stmt1;
|
|
DEALLOCATE PREPARE stmt1;
|
|
|
|
PREPARE stmt2 FROM @sql2;
|
|
EXECUTE stmt2;
|
|
DEALLOCATE PREPARE stmt2;
|
|
|
|
IF myver > 800011 THEN
|
|
SET @sql3 = CONCAT(@sql1, '; CREATE ROLE __taprole__');
|
|
SET @sql4 = CONCAT(@sql2, '; GRANT __taprole__ TO __tapuser__');
|
|
|
|
PREPARE stmt3 FROM @sql3;
|
|
EXECUTE stmt3;
|
|
DEALLOCATE PREPARE stmt3;
|
|
|
|
PREPARE stmt4 FROM @sql4;
|
|
EXECUTE stmt4;
|
|
DEALLOCATE PREPARE stmt4;
|
|
END IF;
|
|
|
|
END //
|
|
|
|
DELIMITER ;
|
|
|
|
CALL taptest.createusers();
|
|
DROP PROCEDURE IF EXISTS taptest.createusers;
|
|
|
|
|
|
SELECT tap.plan(58);
|
|
|
|
/****************************************************************************/
|
|
-- has_user(hname CHAR(60), uname CHAR(32), description TEXT)
|
|
|
|
SELECT tap.check_test(
|
|
tap.has_user('localhost', '__tapuser__', ''),
|
|
true,
|
|
'has_user() extant user',
|
|
null,
|
|
null,
|
|
0
|
|
);
|
|
|
|
SELECT tap.check_test(
|
|
tap.has_user('127.0.0.1', 'nonexistent', ''),
|
|
false,
|
|
'has_user() nonexistent user',
|
|
null,
|
|
null,
|
|
0
|
|
);
|
|
|
|
SELECT tap.check_test(
|
|
tap.has_user('localhost', '__tapuser__', ''),
|
|
true,
|
|
'has_user() default description',
|
|
'User \'__tapuser__\'@\'localhost\' should exist',
|
|
null,
|
|
0
|
|
);
|
|
|
|
SELECT tap.check_test(
|
|
tap.has_user('localhost', '__tapuser__', 'desc'),
|
|
true,
|
|
'has_user() description supplied',
|
|
'desc',
|
|
null,
|
|
0
|
|
);
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
-- hasnt_user(hname CHAR(60), uname CHAR(32), description TEXT)
|
|
|
|
SELECT tap.check_test(
|
|
tap.hasnt_user('localhost', '__nouser__', ''),
|
|
true,
|
|
'hasnt_user() nonexistent user',
|
|
null,
|
|
null,
|
|
0
|
|
);
|
|
|
|
SELECT tap.check_test(
|
|
tap.hasnt_user('localhost', '__tapuser__', ''),
|
|
false,
|
|
'hasnt_user() extant user',
|
|
null,
|
|
null,
|
|
0
|
|
);
|
|
|
|
SELECT tap.check_test(
|
|
tap.hasnt_user('localhost', '__nouser__', ''),
|
|
true,
|
|
'hasnt_user() default description',
|
|
'User \'__nouser__\'@\'localhost\' should not exist',
|
|
null,
|
|
0
|
|
);
|
|
|
|
SELECT tap.check_test(
|
|
tap.hasnt_user('localhost', '__tapuser__', 'desc'),
|
|
false,
|
|
'hasnt_user() description supplied',
|
|
'desc',
|
|
null,
|
|
0
|
|
);
|
|
|
|
/****************************************************************************/
|
|
-- has_user_at_host(uname CHAR(97), description TEXT)
|
|
|
|
SELECT tap.check_test(
|
|
tap.has_user_at_host('__tapuser__@localhost', ''),
|
|
true,
|
|
'has_user_at_host() extant user',
|
|
null,
|
|
null,
|
|
0
|
|
);
|
|
|
|
SELECT tap.check_test(
|
|
tap.has_user_at_host('`__tapuser__`@`localhost`', ''),
|
|
true,
|
|
'has_user_at_host() extant user backtick escaped',
|
|
null,
|
|
null,
|
|
0
|
|
);
|
|
|
|
SELECT tap.check_test(
|
|
tap.has_user_at_host('''__tapuser__''@''localhost''', ''),
|
|
true,
|
|
'has_user_at_host() extant user single-quote escaped',
|
|
null,
|
|
null,
|
|
0
|
|
);
|
|
|
|
SELECT tap.check_test(
|
|
tap.has_user_at_host('nonexistent@127.0.0.1', ''),
|
|
false,
|
|
'has_user_at_host() nonexistent user',
|
|
null,
|
|
null,
|
|
0
|
|
);
|
|
|
|
SELECT tap.check_test(
|
|
tap.has_user_at_host('__tapuser__@localhost', ''),
|
|
true,
|
|
'has_user_at_host() default description',
|
|
'User __tapuser__@localhost should exist',
|
|
null,
|
|
0
|
|
);
|
|
|
|
SELECT tap.check_test(
|
|
tap.has_user_at_host('__tapuser__@localhost', 'desc'),
|
|
true,
|
|
'has_user_at_host() description supplied',
|
|
'desc',
|
|
null,
|
|
0
|
|
);
|
|
|
|
|
|
/****************************************************************************/
|
|
-- hasnt_user_at_host(uname CHAR(97), description TEXT)
|
|
|
|
SELECT tap.check_test(
|
|
tap.hasnt_user_at_host('__nouser__@localhost', ''),
|
|
true,
|
|
'hasnt_user_at_host() nonexistent user',
|
|
null,
|
|
null,
|
|
0
|
|
);
|
|
|
|
SELECT tap.check_test(
|
|
tap.hasnt_user_at_host('__tapuser__@localhost', ''),
|
|
false,
|
|
'hasnt_user_at_host() extant user',
|
|
null,
|
|
null,
|
|
0
|
|
);
|
|
|
|
SELECT tap.check_test(
|
|
tap.hasnt_user_at_host('__nouser__@localhost', ''),
|
|
true,
|
|
'hasnt_user_at_host() default description',
|
|
'User __nouser__@localhost should not exist',
|
|
null,
|
|
0
|
|
);
|
|
|
|
SELECT tap.check_test(
|
|
tap.hasnt_user_at_host('__tapuser__@localhost', 'desc'),
|
|
false,
|
|
'hasnt_user_at_host() description supplied',
|
|
'desc',
|
|
null,
|
|
0
|
|
);
|
|
|
|
|
|
/****************************************************************************/
|
|
-- user_ok(hname CHAR(60), uname CHAR(32), description TEXT)
|
|
-- account lock test
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_ok('localhost', '__tapuser__', ''),
|
|
true,
|
|
'user_ok() correct specification',
|
|
null,
|
|
null,
|
|
0
|
|
)
|
|
ELSE
|
|
tap.skip(1,'user_ok() requires MySQL version >= 5.7.6')
|
|
END ;
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_ok('localhost', '__locked__', ''),
|
|
false,
|
|
'user_ok() locked user',
|
|
null,
|
|
null,
|
|
0
|
|
)
|
|
ELSE
|
|
tap.skip(1,'user_ok() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_ok('localhost', '__tapuser__', ''),
|
|
true,
|
|
'user_ok() default description',
|
|
'User \'__tapuser__\'@\'localhost\' should not be locked or have expired password',
|
|
null,
|
|
0
|
|
)
|
|
ELSE
|
|
tap.skip(2,'user_ok() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_ok('localhost', '__tapuser__', 'desc'),
|
|
true,
|
|
'user_ok() description supplied',
|
|
'desc',
|
|
null,
|
|
0
|
|
)ELSE
|
|
tap.skip(2,'user_ok() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_ok('localhost', '__nouser__', ''),
|
|
false,
|
|
'user_ok() user not found diagnostic',
|
|
null,
|
|
'User \'__nouser__\'@\'localhost\' does not exist',
|
|
0
|
|
)
|
|
ELSE
|
|
tap.skip(2,'user_ok() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
|
|
/****************************************************************************/
|
|
-- user_not_ok(hname CHAR(60), uname CHAR(32), description TEXT)
|
|
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_not_ok('localhost', '__locked__', ''),
|
|
true,
|
|
'user_not_ok() correct specification',
|
|
null,
|
|
null,
|
|
0
|
|
)
|
|
ELSE
|
|
tap.skip(1,'user_not_ok() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_not_ok('localhost', '__tapuser__', ''),
|
|
false,
|
|
'user_not_ok() unlocked user',
|
|
null,
|
|
null,
|
|
0
|
|
)ELSE
|
|
tap.skip(1,'user_not_ok() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_not_ok('localhost', '__locked__', ''),
|
|
true,
|
|
'user_not_ok() default description',
|
|
'User \'__locked__\'@\'localhost\' should be locked out or have an expired password',
|
|
null,
|
|
0
|
|
)ELSE
|
|
tap.skip(2,'user_not_ok() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_not_ok('localhost', '__locked__', 'desc'),
|
|
true,
|
|
'user_not_ok() description supplied',
|
|
'desc',
|
|
null,
|
|
0
|
|
)ELSE
|
|
tap.skip(2,'user_not_ok() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_not_ok('localhost', '__nouser__', ''),
|
|
false,
|
|
'user_not_ok() user not found diagnostic',
|
|
null,
|
|
'User \'__nouser__\'@\'localhost\' does not exist',
|
|
0
|
|
)ELSE
|
|
tap.skip(2,'user_not_ok() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
|
|
/****************************************************************************/
|
|
-- user_has_lifetime(hname CHAR(60), uname CHAR(32), description TEXT)
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_has_lifetime('localhost', '__locked__', ''),
|
|
true,
|
|
'user_has_lifetime() correct specification',
|
|
null,
|
|
null,
|
|
0
|
|
)ELSE
|
|
tap.skip(1,'user_has_lifetime() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_has_lifetime('localhost', '__tapuser__', ''),
|
|
false,
|
|
'user_has_lifetime() with no lifetime',
|
|
null,
|
|
null,
|
|
0
|
|
)ELSE
|
|
tap.skip(1,'user_has_lifetime() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_has_lifetime('localhost', '__locked__', ''),
|
|
true,
|
|
'user_has_lifetime() default description',
|
|
'User \'__locked__\'@\'localhost\' Password should expire',
|
|
null,
|
|
0
|
|
)ELSE
|
|
tap.skip(2,'user_has_lifetime() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_has_lifetime('localhost', '__locked__', 'desc'),
|
|
true,
|
|
'user_has_lifetime() description supplied',
|
|
'desc',
|
|
null,
|
|
0
|
|
)ELSE
|
|
tap.skip(2,'user_has_lifetime() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_has_lifetime('localhost', '__nouser__', ''),
|
|
false,
|
|
'user_has_lifetime() user not found diagnostic',
|
|
null,
|
|
'User \'__nouser__\'@\'localhost\' does not exist',
|
|
0
|
|
)ELSE
|
|
tap.skip(2,'user_has_lifetime() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
|
|
/****************************************************************************/
|
|
-- user_hasnt_lifetime(hname CHAR(60), uname CHAR(32), description TEXT)
|
|
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_hasnt_lifetime('localhost', '__tapuser__', ''),
|
|
true,
|
|
'user_hasnt_lifetime() correct specification',
|
|
null,
|
|
null,
|
|
0
|
|
)ELSE
|
|
tap.skip(1,'user_hasnt_lifetime() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_hasnt_lifetime('localhost', '__locked__', ''),
|
|
false,
|
|
'user_hasnt_lifetime() locked user',
|
|
null,
|
|
null,
|
|
0
|
|
)ELSE
|
|
tap.skip(1,'user_hasnt_lifetime() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_hasnt_lifetime('localhost', '__tapuser__', ''),
|
|
true,
|
|
'user_hasnt_lifetime() default description',
|
|
'User \'__tapuser__\'@\'localhost\' Password should not expire',
|
|
null,
|
|
0
|
|
)ELSE
|
|
tap.skip(2,'user_hasnt_lifetime() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_hasnt_lifetime('localhost', '__tapuser__', 'desc'),
|
|
true,
|
|
'user_hasnt_lifetime() description supplied',
|
|
'desc',
|
|
null,
|
|
0
|
|
)ELSE
|
|
tap.skip(2,'user_hasnt_lifetime() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
SELECT CASE WHEN tap.mysql_version() >= 507006 THEN
|
|
tap.check_test(
|
|
tap.user_hasnt_lifetime('localhost', '__nouser__', ''),
|
|
false,
|
|
'user_hasnt_lifetime() user not found diagnostic',
|
|
null,
|
|
'User \'__nouser__\'@\'localhost\' does not exist',
|
|
0
|
|
)ELSE
|
|
tap.skip(2,'user_hasnt_lifetime() requires MySQL version >= 5.7.6')
|
|
END;
|
|
|
|
|
|
|
|
/****************************************************************************/
|
|
|
|
-- Finish the tests and clean up.
|
|
|
|
call tap.finish();
|
|
DROP USER '__tapuser__'@'localhost';
|
|
DROP USER '__locked__'@'localhost';
|
|
DROP DATABASE taptest;
|
|
ROLLBACK;
|