summaryrefslogtreecommitdiff
path: root/test/scripts/2610-MySQL/2610
blob: ec7b4548f5ccd41d7a8020839e97d3f28b8e1d5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# mysql lookups
# The mysql-devel (or equivalent) package will be need for Exim to build, and
# the mysql-server (or mariadb-server or equivalent) package for this test to run.
#
# first, populate a DB to test against
sudo rm -fr DIR/mysql
echo Installing DB server dir
perl
system 'mysql_install_db --no-defaults --datadir=DIR/mysql --user=CALLER';
****
sudo rm test-stdout test-stderr
#
### start a db server
echo Starting DB server
background
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
****
#
### wait for db startup, set password on the root user
echo Waiting for DB server startup
sudo perl
system 'mysql --protocol=socket --socket=`pwd`/mysql/sock --connect_timeout=10 -u root -e "set password = password(\"pass\")"';
****
#
### create testdb and extra users
echo Create testdb and extra users
perl
system 'mysqladmin --protocol=TCP -P PORT_N -u root -ppass create test';
my $fh;
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\'"');
my $line = <$fh>;
if (length($line) == 0) {
  system 'mysql --protocol=TCP -P PORT_N -u root -ppass -D test -e "create user \'root\'@\'HOSTIPV4\'"';
}
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\'"');
$line = <$fh>;
if (length($line) == 0) {
  system 'mysql --protocol=TCP -P PORT_N -u root -ppass -D test -e "create user \'CALLER\'@\'HOSTIPV4\'"';
}
****
#
#
# wait for db startup, insert some data
echo Insert some data
perl
system 'mysql --protocol=TCP -P PORT_N -u root -ppass -D test \
 -e "CREATE TABLE them ( name text, id text ); \
     INSERT INTO them VALUES ( \'Philip Hazel\', \'ph10\' ); \
     INSERT INTO them VALUES ( \'Aristotle\',    \'aaaa\' ); \
     INSERT INTO them VALUES ( \'\', \'nothing\' ); \
     INSERT INTO them VALUES ( \'\"stquot\', \'quote2\' ); \
     INSERT INTO them VALUES ( CONCAT(\'before\', CHAR(13), CHAR(10), \'after\'), \'newline\' ); \
     INSERT INTO them VALUES ( CONCAT(\'x\', CHAR(9), \'x\'), \'tab\' ); \
     INSERT INTO them VALUES ( CONCAT(CHAR(39), \'stquot\'), \'quote1\' ); \
     GRANT ALL ON *.* TO \'root\'@\'HOSTIPV4\'; \
     GRANT ALL ON *.* TO \'CALLER\'@\'HOSTIPV4\'; \
 "';
****
echo Populated DB
sudo rm test-stderr-server
#
#
exim -d-all+lookup -be
${lookup mysql {select name from them where id='ph10';}}
${lookup mysql {select name from them where id='ph10';}}
${lookup mysql {select name from them where id='xxxx';}}
${lookup mysql {select name from them where id='nothing';}}
${lookup mysql {select id,name from them where id='nothing';}}
${lookup mysql {delete from them where id='nonexist';}}
${lookup mysql {select * from them where id='quote';}}
${lookup mysql {select * from them where id='filter';}}
${lookup mysql {select * from them where id='quote2';}}
${lookup mysql {select * from them where id='nlonly';}}
${lookup mysql {servers=x:127.0.0.1::PORT_N; select name from them where id='ph10';}}
${lookup mysql {servers=127.0.0.1::PORT_N:x; select name from them where id='ph10';}}
${lookup mysql {servers=127.0.0.1::PORT_N/test/root/:x; select name from them where id='ph10';}}
${lookup mysql {servers=HOSTIPV4::PORT_N/test/root/:127.0.0.1::PORT_N; select name from them where id='ph10';}}
${lookup mysql {servers=localhost(DIR/mysql/sock)/test/root/pass; select name from them where id='ph10';}}
x
${lookup mysql {SELECT name FROM them WHERE id IN ('ph10', 'aaaa');}}
${lookup mysql {SELECT *    FROM them WHERE id IN ('ph10', 'aaaa');}}
${lookup mysql {delete from them where id='aaaa'}}
****
exim -d -bh 10.0.0.0
mail from:<a@b>
rcpt to:<c@d>
quit
****
exim -odi -d ph10
Test message
.
****
#
perl
system 'mysqladmin --protocol=TCP -P PORT_N -u root -ppass shutdown';
****
killdaemon
sudo rm -fr DIR/mysql