2 # The mysql-devel (or equivalent) package will be need for Exim to build, and
3 # the mysql-server (or mariadb-server or equivalent) package for this test to run.
5 # first, populate a DB to test against
7 echo Installing DB server dir
9 system 'mysql_install_db --no-defaults --datadir=DIR/mysql --user=CALLER';
11 sudo rm test-stdout test-stderr
14 echo Starting DB server
16 DIR/bin.sys/mysqld --datadir=DIR/mysql --log-error=DIR/mysql/log --bind-address=* --port=PORT_N --socket=DIR/mysql/sock --pid-file=DIR/mysql/pidfile
19 ### wait for db startup, set password on the root user
20 echo Waiting for DB server startup
22 system 'mysql --protocol=socket --socket=`pwd`/mysql/sock --connect_timeout=10 -u root -e "set password = password(\"pass\")"';
25 ### create testdb and extra users
26 echo Create testdb and extra users
28 system 'mysqladmin --protocol=TCP -P PORT_N -u root -ppass create test';
30 open($fh, '-|', 'mysql --protocol=TCP -P PORT_N -u root -ppass -D test -e "select 1 from mysql.user where User = \'root\' and Host = \'HOSTIPV4\'"');
32 if (length($line) == 0) {
33 system 'mysql --protocol=TCP -P PORT_N -u root -ppass -D test -e "create user \'root\'@\'HOSTIPV4\'"';
35 open($fh, '-|', 'mysql --protocol=TCP -P PORT_N -u root -ppass -D test -e "select 1 from mysql.user where User = \'CALLER\' and Host = \'HOSTIPV4\'"');
37 if (length($line) == 0) {
38 system 'mysql --protocol=TCP -P PORT_N -u root -ppass -D test -e "create user \'CALLER\'@\'HOSTIPV4\'"';
43 # wait for db startup, insert some data
46 system 'mysql --protocol=TCP -P PORT_N -u root -ppass -D test \
47 -e "CREATE TABLE them ( name text, id text ); \
48 INSERT INTO them VALUES ( \'Philip Hazel\', \'ph10\' ); \
49 INSERT INTO them VALUES ( \'Aristotle\', \'aaaa\' ); \
50 INSERT INTO them VALUES ( \'\', \'nothing\' ); \
51 INSERT INTO them VALUES ( \'\"stquot\', \'quote2\' ); \
52 INSERT INTO them VALUES ( CONCAT(\'before\', CHAR(13), CHAR(10), \'after\'), \'newline\' ); \
53 INSERT INTO them VALUES ( CONCAT(\'x\', CHAR(9), \'x\'), \'tab\' ); \
54 INSERT INTO them VALUES ( CONCAT(CHAR(39), \'stquot\'), \'quote1\' ); \
55 GRANT ALL ON *.* TO \'root\'@\'HOSTIPV4\'; \
56 GRANT ALL ON *.* TO \'CALLER\'@\'HOSTIPV4\'; \
60 sudo rm test-stderr-server
63 exim -d-all+lookup -be
64 ${lookup mysql {select name from them where id='ph10';}}
65 ${lookup mysql {select name from them where id='ph10';}}
66 ${lookup mysql {select name from them where id='xxxx';}}
67 ${lookup mysql {select name from them where id='nothing';}}
68 ${lookup mysql {select id,name from them where id='nothing';}}
69 ${lookup mysql {delete from them where id='nonexist';}}
70 ${lookup mysql {select * from them where id='quote';}}
71 ${lookup mysql {select * from them where id='filter';}}
72 ${lookup mysql {select * from them where id='quote2';}}
73 ${lookup mysql {select * from them where id='nlonly';}}
74 ${lookup mysql {servers=x:127.0.0.1::PORT_N; select name from them where id='ph10';}}
75 ${lookup mysql {servers=127.0.0.1::PORT_N:x; select name from them where id='ph10';}}
76 ${lookup mysql {servers=127.0.0.1::PORT_N/test/root/:x; select name from them where id='ph10';}}
77 ${lookup mysql {servers=HOSTIPV4::PORT_N/test/root/:127.0.0.1::PORT_N; select name from them where id='ph10';}}
78 ${lookup mysql {servers=localhost(DIR/mysql/sock)/test/root/pass; select name from them where id='ph10';}}
80 ${lookup mysql {SELECT name FROM them WHERE id IN ('ph10', 'aaaa');}}
81 ${lookup mysql {SELECT * FROM them WHERE id IN ('ph10', 'aaaa');}}
82 ${lookup mysql {delete from them where id='aaaa'}}
96 system 'mysqladmin --protocol=TCP -P PORT_N -u root -ppass shutdown';