diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/function.res | 6 | ||||
-rw-r--r-- | tests/function.tst | 2 | ||||
-rw-r--r-- | tests/grant.pl | 75 | ||||
-rw-r--r-- | tests/grant.res | 72 | ||||
-rwxr-xr-x | tests/truncate.pl | 125 |
5 files changed, 264 insertions, 16 deletions
diff --git a/tests/function.res b/tests/function.res index a2322020d74..acd34f41a3e 100644 --- a/tests/function.res +++ b/tests/function.res @@ -11,11 +11,11 @@ select floor(5.5),floor(-5.5),ceiling(5.5),ceiling(-5.5),round(5.5),round(-5.5) floor(5.5) floor(-5.5) ceiling(5.5) ceiling(-5.5) round(5.5) round(-5.5) 5 -6 6 -5 6 -6 -------------- -select abs(-10),log(exp(10)),exp(log(sqrt(10))*2),pow(10,log10(10)),rand(999999),rand() +select abs(-10),log(exp(10)),ln(exp(10)),log2(65535),log(2,65535),exp(log(sqrt(10))*2),pow(10,log10(10)),rand(999999),rand() -------------- -abs(-10) log(exp(10)) exp(log(sqrt(10))*2) pow(10,log10(10)) rand(999999) rand() -10 10.000000 10.000000 10.000000 0.1844 0.7637 +abs(-10) log(exp(10)) ln(exp(10)) log2(65535) log(2,65535) exp(log(sqrt(10))*2) pow(10,log10(10)) rand(999999) rand() +10 10.000000 10.000000 2.000000 2.000000 10.000000 10.000000 0.1844 0.7637 -------------- select least(6,1.0,2.0),greatest(3,4,5,0) -------------- diff --git a/tests/function.tst b/tests/function.tst index 5b8746e8d3c..17e1cb6c8ac 100644 --- a/tests/function.tst +++ b/tests/function.tst @@ -7,7 +7,7 @@ # select 1+1,1-1,1+1*2,8/5,8%5,mod(8,5),mod(8,5)|0,-(1+1)*-2,sign(-5) ; select floor(5.5),floor(-5.5),ceiling(5.5),ceiling(-5.5),round(5.5),round(-5.5); -select abs(-10),log(exp(10)),exp(log(sqrt(10))*2),pow(10,log10(10)),rand(999999),rand(); +select abs(-10),log(exp(10)),ln(exp(10)),log2(65535),log(2,65535),exp(log(sqrt(10))*2),pow(10,log10(10)),rand(999999),rand(); select least(6,1.0,2.0),greatest(3,4,5,0) ; select 1 | (1+1),5 & 3,bit_count(7) ; # diff --git a/tests/grant.pl b/tests/grant.pl index 0219fdb71ee..6da4326d465 100644 --- a/tests/grant.pl +++ b/tests/grant.pl @@ -8,9 +8,10 @@ use DBI; use Getopt::Long; use strict; -use vars qw($dbh $user_dbh $opt_help $opt_Information $opt_force $opt_debug - $opt_verbose $opt_server $opt_root_user $opt_password $opt_user - $opt_database $opt_host $version $user $tables_cols $columns_cols); +use vars qw($dbh $user_dbh $opt_help $opt_Information $opt_force $opt_debug + $opt_verbose $opt_server $opt_root_user $opt_password $opt_user + $opt_database $opt_host $version $user $tables_cols $columns_cols + $tmp_table); $version="1.0"; $opt_help=$opt_Information=$opt_force=$opt_debug=$opt_verbose=0; @@ -35,6 +36,8 @@ $|=1; $tables_cols="Host, Db, User, Table_name, Grantor, Table_priv, Column_priv"; $columns_cols="Host, Db, User, Table_name, Column_name, Column_priv"; +$tmp_table="/tmp/mysql-grant.test"; # Can't use $$ as we are logging result +unlink($tmp_table); # # clear grant tables @@ -72,6 +75,7 @@ user_connect(0); user_query("select * from mysql.user where user = '$opt_user'"); user_query("select * from mysql.db where user = '$opt_user'"); safe_query("grant select on *.* to $user,$user"); +safe_query("show grants for $user"); # The following should fail user_query("insert into mysql.user (host,user) values ('error','$opt_user')",1); @@ -294,6 +298,7 @@ safe_query("select $tables_cols from mysql.tables_priv"); safe_query("revoke ALL PRIVILEGES on $opt_database.test from $user"); safe_query("select $tables_cols from mysql.tables_priv"); safe_query("revoke GRANT OPTION on $opt_database.test from $user",1); + # # Test grants on database level # @@ -378,20 +383,80 @@ safe_query("select $tables_cols from mysql.tables_priv where user = '$opt_user'" safe_query("select $columns_cols from mysql.columns_priv where user = '$opt_user'"); # -# Test IDENTIFIED BY -# +# Clear up privileges to make future tests easier safe_query("delete from user where user='$opt_user'"); +safe_query("delete from db where user='$opt_user'"); safe_query("flush privileges"); +safe_query("show grants for $user",1); + +# +# Test IDENTIFIED BY +# + safe_query("grant ALL PRIVILEGES on $opt_database.test to $user identified by 'dummy', ${opt_user}\@127.0.0.1 identified by 'dummy2'"); user_connect(0,"dummy"); safe_query("grant SELECT on $opt_database.* to $user identified by ''"); user_connect(0); +safe_query("revoke ALL PRIVILEGES on $opt_database.test from $user identified by ''"); +safe_query("revoke ALL PRIVILEGES on $opt_database.* from $user identified by ''"); +safe_query("show grants for $user"); + +# +# Test bug reported in SELECT INTO OUTFILE +# + +safe_query("create table $opt_database.test3 (a int)"); +safe_query("grant SELECT on $opt_database.test3 to $user"); +safe_query("grant FILE on *.* to $user"); +safe_query("insert into $opt_database.test3 values (1)"); +user_connect(0); +user_query("select * into outfile '$tmp_table' from $opt_database.test3"); +safe_query("revoke SELECT on $opt_database.test3 from $user"); +safe_query("revoke FILE on *.* from $user"); +safe_query("drop table $opt_database.test3"); + +# +# Test privileges needed for LOCK TABLES +# + +safe_query("create table $opt_database.test3 (a int)"); +user_connect(1); +safe_query("grant INSERT on $opt_database.test3 to $user"); +user_connect(0); +user_query("select * into outfile '$tmp_table' from $opt_database.test3",1); +safe_query("grant SELECT on $opt_database.test3 to $user"); +user_connect(0); +user_query("LOCK TABLES $opt_database.test3 READ",1); +safe_query("grant LOCK TABLES on *.* to $user"); +safe_query("show grants for $user"); +safe_query("select * from mysql.user where user='$opt_user'"); +user_connect(0); +user_query("LOCK TABLES $opt_database.test3 READ"); +user_query("UNLOCK TABLES"); +safe_query("revoke SELECT,INSERT,UPDATE,DELETE on $opt_database.test3 from $user"); +user_connect(1); +safe_query("revoke LOCK TABLES on *.* from $user"); +safe_query("drop table $opt_database.test3"); + +# +# test new privileges in 4.0.2 +# + +safe_query("show grants for $user"); +safe_query("grant all on *.* to $user WITH MAX_QUERIES_PER_HOUR 1 MAX_UPDATES_PER_HOUR 2 MAX_CONNECTIONS_PER_HOUR 3"); +safe_query("show grants for $user"); +safe_query("revoke LOCK TABLES on *.* from $user"); +safe_query("flush privileges"); +safe_query("show grants for $user"); +safe_query("revoke ALL PRIVILEGES on *.* from $user"); +safe_query("show grants for $user"); # # Clean up things # +unlink($tmp_table); safe_query("drop database $opt_database"); safe_query("delete from user where user='$opt_user'"); safe_query("delete from db where user='$opt_user'"); diff --git a/tests/grant.res b/tests/grant.res index 37266facc61..b54fec94514 100644 --- a/tests/grant.res +++ b/tests/grant.res @@ -19,10 +19,13 @@ Access denied for user: 'grant_user@localhost' (Using password: NO) set password FOR grant_user='' Connecting grant_user select * from mysql.user where user = 'grant_user' -localhost grant_user Y N N N N N N N N N N N N N +localhost grant_user Y N N N N N N N N N N N N N N N N N N N N 0 0 0 select * from mysql.db where user = 'grant_user' grant select on *.* to grant_user@localhost,grant_user@localhost +show grants for grant_user@localhost +GRANT SELECT ON *.* TO 'grant_user'@'localhost' + insert into mysql.user (host,user) values ('error','grant_user') Error in execute: Access denied for user: 'grant_user@localhost' to database 'mysql' update mysql.user set host='error' WHERE user='grant_user' @@ -48,7 +51,7 @@ Error in execute: The host or user argument to GRANT is too long grant select on grant_test.test to grant_user with grant option Error in execute: grant command denied to user: 'grant_user@localhost' for table 'test' set password FOR ''@''='' -Error in execute: You are using MySQL as an anonymous users and anonymous users are not allowed to change passwords +Error in execute: Can't find any matching row in the user table set password FOR root@localhost = password('test') Error in execute: Access denied for user: 'grant_user@localhost' to database 'mysql' revoke select on *.* from grant_user@localhost @@ -93,7 +96,7 @@ delete from user where user='grant_user' flush privileges grant select on grant_test.* to grant_user@localhost select * from mysql.user where user = 'grant_user' -localhost grant_user N N N N N N N N N N N N N N +localhost grant_user N N N N N N N N N N N N N N N N N N N N N 0 0 0 select * from mysql.db where user = 'grant_user' localhost grant_test grant_user Y N N N N N N N N N @@ -152,7 +155,7 @@ insert into mysql.user (host,user) values ('error','grant_user',0) Error in execute: Access denied for user: 'grant_user@localhost' to database 'mysql' revoke ALL PRIVILEGES on grant_test.* from grant_user@localhost select * from mysql.user where user = 'grant_user' -localhost grant_user N N N N N N N N N N N N N N +localhost grant_user N N N N N N N N N N N N N N N N N N N N N 0 0 0 select * from mysql.db where user = 'grant_user' Connecting grant_user @@ -168,7 +171,7 @@ Error in execute: select command denied to user: 'grant_user@localhost' for tabl show keys from test Error in execute: select command denied to user: 'grant_user@localhost' for table 'test' show columns from test2 -a int(11) 0 +a int(11) 0 show keys from test2 select * from test @@ -311,8 +314,8 @@ revoke GRANT OPTION on grant_test.test from grant_user@localhost Error in execute: There is no such grant defined for user 'grant_user' on host 'localhost' on table 'test' grant select(a) on grant_test.test to grant_user@localhost show columns from test -a int(11) YES NULL select -b int(11) YES NULL +a int(11) YES NULL +b int(11) YES NULL grant insert (b), update (b) on grant_test.test to grant_user@localhost select count(a) from test @@ -432,11 +435,66 @@ localhost grant_test grant_user N Y N N N N N N N N select Host, Db, User, Table_name, Grantor, Table_priv, Column_priv from mysql.tables_priv where user = 'grant_user' select Host, Db, User, Table_name, Column_name, Column_priv from mysql.columns_priv where user = 'grant_user' delete from user where user='grant_user' +delete from db where user='grant_user' flush privileges +show grants for grant_user@localhost +Error in execute: There is no such grant defined for user 'grant_user' on host 'localhost' grant ALL PRIVILEGES on grant_test.test to grant_user@localhost identified by 'dummy', grant_user@127.0.0.1 identified by 'dummy2' Connecting grant_user grant SELECT on grant_test.* to grant_user@localhost identified by '' Connecting grant_user +revoke ALL PRIVILEGES on grant_test.test from grant_user@localhost identified by '' +revoke ALL PRIVILEGES on grant_test.* from grant_user@localhost identified by '' +show grants for grant_user@localhost +create table grant_test.test3 (a int) +grant SELECT on grant_test.test3 to grant_user@localhost +grant FILE on *.* to grant_user@localhost +insert into grant_test.test3 values (1) +Connecting grant_user +select * into outfile '/tmp/mysql-grant.test' from grant_test.test3 +revoke SELECT on grant_test.test3 from grant_user@localhost +revoke FILE on *.* from grant_user@localhost +drop table grant_test.test3 +create table grant_test.test3 (a int) +Connecting grant_user +Access denied for user: 'grant_user@localhost' to database 'grant_test' +grant INSERT on grant_test.test3 to grant_user@localhost +Connecting grant_user +select * into outfile '/tmp/mysql-grant.test' from grant_test.test3 +Error in execute: Access denied for user: 'grant_user@localhost' (Using password: NO) +grant SELECT on grant_test.test3 to grant_user@localhost +Connecting grant_user +LOCK TABLES grant_test.test3 READ +Error in execute: Access denied for user: 'grant_user@localhost' (Using password: NO) +grant LOCK TABLES on *.* to grant_user@localhost +show grants for grant_user@localhost +GRANT LOCK TABLES ON *.* TO 'grant_user'@'localhost' +GRANT SELECT, INSERT ON grant_test.test3 TO 'grant_user'@'localhost' + +select * from mysql.user where user='grant_user' +127.0.0.1 grant_user 7f70e8b858ee6782 N N N N N N N N N N N N N N N N N N N N N 0 0 0 +localhost grant_user N N N N N N N N N N N N N N N N N Y N N N 0 0 0 + +Connecting grant_user +LOCK TABLES grant_test.test3 READ +UNLOCK TABLES +revoke SELECT,INSERT,UPDATE,DELETE on grant_test.test3 from grant_user@localhost +Connecting grant_user +Access denied for user: 'grant_user@localhost' to database 'grant_test' +revoke LOCK TABLES on *.* from grant_user@localhost +drop table grant_test.test3 +show grants for grant_user@localhost +grant all on *.* to grant_user@localhost WITH MAX_QUERIES_PER_HOUR 1 MAX_UPDATES_PER_HOUR 2 MAX_CONNECTIONS_PER_HOUR 3 +show grants for grant_user@localhost +GRANT ALL PRIVILEGES ON *.* TO 'grant_user'@'localhost' WITH MAX_QUERIES_PER_HOUR 1 MAX_UPDATES_PER_HOUR 2 MAX_CONNECTIONS_PER_HOUR 3 + +revoke LOCK TABLES on *.* from grant_user@localhost +flush privileges +show grants for grant_user@localhost +GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'grant_user'@'localhost' WITH MAX_QUERIES_PER_HOUR 1 MAX_UPDATES_PER_HOUR 2 MAX_CONNECTIONS_PER_HOUR 3 + +revoke ALL PRIVILEGES on *.* from grant_user@localhost +show grants for grant_user@localhost drop database grant_test delete from user where user='grant_user' delete from db where user='grant_user' diff --git a/tests/truncate.pl b/tests/truncate.pl new file mode 100755 index 00000000000..57b50cf96b6 --- /dev/null +++ b/tests/truncate.pl @@ -0,0 +1,125 @@ +#!/usr/bin/perl -w +# +# This is a test with uses many processes to test a MySQL server. +# + +$opt_loop_count=10000; # Change this to make test harder/easier + +##################### Standard benchmark inits ############################## + +use DBI; +use Getopt::Long; +use Benchmark; + +package main; + +$opt_skip_create=$opt_skip_in=$opt_verbose=$opt_fast_insert= +$opt_lock_tables=$opt_debug=$opt_skip_delete=$opt_fast=$opt_force=0; +$opt_threads=2; +$opt_host=$opt_user=$opt_password=""; $opt_db="test"; + +GetOptions("host=s","db=s","user=s","password=s","loop-count=i","skip-create","skip-in","skip-delete","verbose","fast-insert","lock-tables","debug","fast","force","threads=i") || die "Aborted"; +$opt_verbose=$opt_debug=$opt_lock_tables=$opt_fast_insert=$opt_fast=$opt_skip_in=$opt_force=undef; # Ignore warnings from these + +print "Testing truncate from $opt_threads multiple connections $opt_loop_count times\n"; + +@testtables = ( ["bench_f31", "type=heap"]); + +#### +#### Start timeing and start test +#### + +$start_time=new Benchmark; +$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host", + $opt_user, $opt_password, + { PrintError => 0}) || die $DBI::errstr; +if (!$opt_skip_create) +{ + my $table_def; + foreach $table_def (@testtables) + { + my ($table,$extra)= ($table_def->[0], $table_def->[1]); + print "Creating table $table in database $opt_db\n"; + $dbh->do("drop table if exists $table"); + $dbh->do("create table $table". + " (id int(6) not null,". + " info varchar(32)," . + " marker timestamp," . + " flag int not null," . + " primary key(id)) $extra") + + or die $DBI::errstr; + } +} + +$dbh->disconnect; $dbh=0; # Close handler +$|= 1; # Autoflush + +#### +#### Start the tests +#### + +for ($i=0 ; $i < $opt_threads ; $i ++) +{ + test_truncate() if (($pid=fork()) == 0); $work{$pid}="truncate"; +} + +print "Started $opt_threads threads\n"; + +$errors=0; +$running_insert_threads=$opt_threads; +while (($pid=wait()) != -1) +{ + $ret=$?/256; + print "thread '" . $work{$pid} . "' finished with exit code $ret\n"; + --$running_insert_threads; + $errors++ if ($ret != 0); +} + +# +# Cleanup +# + +if (!$opt_skip_delete && !$errors) +{ + my $table_def; + $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host", + $opt_user, $opt_password, + { PrintError => 0}) || die $DBI::errstr; + + foreach $table_def (@testtables) + { + $dbh->do("drop table " . $table_def->[0]); + } + $dbh->disconnect; $dbh=0; # Close handler +} + +print ($errors ? "Test failed\n" :"Test ok\n"); +$end_time=new Benchmark; +print "Total time: " . + timestr(timediff($end_time, $start_time),"noc") . "\n"; + +exit(0); + + +# +# Insert records in the table +# + +sub test_truncate +{ + my ($dbh,$i,$j,$count,$table_def,$table); + + $dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host", + $opt_user, $opt_password, + { PrintError => 0}) || die $DBI::errstr; + + for ($count=0; $count < $opt_loop_count ; $count++) + { + my ($table)= ($testtables[0]->[0]); + $dbh->do("truncate table $table") || die "Got error on truncate: $DBI::errstr\n"; + } + $dbh->disconnect; $dbh=0; + print "Test_truncate: Run $count times\n"; + exit(0); +} |