File: tests.sh

package info (click to toggle)
cvm 0.97-0.1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,036 kB
  • sloc: ansic: 4,065; sh: 2,758; makefile: 235; sql: 15
file content (1683 lines) | stat: -rw-r--r-- 44,258 bytes parent folder | download
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
#!/bin/sh
src=`pwd`
tmp=$src/tests-tmp
rm -rf $tmp
mkdir -p $tmp
PATH="$src:/bin:/usr/bin:/usr/local/bin"
tests_failed=0
tests_count=0
_UID=`id -u`
_GID=`id -g`

usage() {
  echo "usage: sh $0 [-v]"
}

vecho() { :; }
while getopts v flag
do
  case $flag in
    v)      vecho() { echo "$*"; } ;;
	*)      usage; exit 1 ;;
  esac
done
printf='env printf'

home=$tmp/home
mkdir $home

CVM_PWFILE_PATH=$tmp/pwfile
export CVM_PWFILE_PATH
make_pwfile()
{
  (
    echo 'pwfuser:testpass:123:456:Gecos,xyz:/home/ftp:/bin/false'
    echo 'cryptuser:tpzv1IkcX9.fE:234:567:Crypt:/home/crypt:/bin/true'
  ) >$CVM_PWFILE_PATH
}

CVM_SQLITE_DB=$tmp/db.sqlite
CVM_SQLITE_QUERY='SELECT password, username, userid, groupid, directory, realname, shell, groupname, domain, sys_username, sys_directory, mailbox_path FROM accounts WHERE username=$account AND domain=$domain'
CVM_SQLITE_PWCMP=plain
export CVM_SQLITE_DB CVM_SQLITE_QUERY CVM_SQLITE_PWCMP
make_sqlite()
{
  sqlite3 $CVM_SQLITE_DB <<EOF
CREATE TABLE accounts (
  username      TEXT NOT NULL,
  domain        TEXT NOT NULL,
  password      TEXT NOT NULL,
  userid        TEXT NOT NULL,
  groupid       TEXT NOT NULL,
  realname      TEXT,
  directory     TEXT NOT NULL,
  shell         TEXT,
  groupname     TEXT,
  sys_username  TEXT,
  sys_directory TEXT,
  mailbox_path  TEXT,
  UNIQUE (username, domain)
);
INSERT INTO accounts VALUES ('sluser','','testpass',123,456,'realname','/home/sluser','/bin/false',NULL,NULL,NULL,NULL);
INSERT INTO accounts VALUES ('sluser','domain','pass2',234,567,'sluser2','/home/sluser2','/bin/true',NULL,NULL,NULL,NULL);
EOF
}

for base in pwfile qmail vmailmgr; do

cat <<EOF >$tmp/cvm-$base-lookup
#!/bin/sh
CVM_LOOKUP_SECRET=secret export CVM_LOOKUP_SECRET
exec $src/cvm-$base
EOF

cat <<EOF >$tmp/cvm-$base-nosecret
#!/bin/bash
unset CVM_LOOKUP_SECRET
exec $src/cvm-$base
EOF

done

chmod +x $tmp/cvm-*

QMAIL_ROOT=$tmp
export QMAIL_ROOT

mkdir $tmp/users
(
  uid=`id -u`
  gid=`id -g`
  hlen=`echo $home $uid $gid | wc -c`
  tlen=`echo $tmp $uid $gid | wc -c`
  $printf "+6,%d:!user\0->user\000$uid\000$gid\000$home\0\0\n" $(($hlen+6))
  $printf "+6,%d:!user-->user\000$uid\000$gid\000$home\0-\0\n" $(($hlen+7))
  $printf "+7,%d:!alias\0->alias\000$uid\000$gid\000$tmp/alias\0\0\n" $(($tlen+13))
  $printf "+7,%d:!alias-->alias\000$uid\000$gid\000$tmp/alias\0-\0\n" $(($tlen+14))
  $printf "+1,%d:!->alias\000$uid\000$gid\000$tmp/alias\0-\0\n" $(($tlen+14))
  echo
) | cdbmake $tmp/users/cdb $tmp/users/tmp

mkdir $tmp/control
echo local.dom >$tmp/control/locals
echo test.tld:user >$tmp/control/virtualdomains
echo noathost:user >>$tmp/control/virtualdomains
echo noathost >$tmp/control/envnoathost
mkdir $tmp/alias
echo \# >$home/.qmail-wild-default
echo \# >$home/.qmail-addr
echo \# >$home/.qmail-dot:addr
echo \# >$tmp/alias/.qmail-alias
echo \# >$tmp/alias/.qmail-awild-default
echo \# >$tmp/alias/.qmail-adot:addr

(
  $printf '+4,69:virt->\x2\x8\x1\0$1$aSoIrl/J$TmAwoxKzrPJ0IaW5UvX4A0\0./virt\0\0\0-\0-\0-\0-\0001016731358\0-\0\n'
  echo
) | cdbmake $home/passwd.cdb $home/passwd.tmp

sasltest() {
  make_pwfile
  env \
  CVM_SASL_PLAIN=$src/cvm-pwfile \
  PROTO=TCP \
  TCPLOCALHOST=localhost \
  $src/sasl-auth-test "$@"
  rm -f $CVM_PWFILE_PATH
}


run_compare_test() {
  local name=$1
  shift
  sed -e "s:@SOURCE@:$src:g"   	-e "s:@TMPDIR@:$tmp:g"   	-e "s:@UID@:$_UID:" 	-e "s:@GID@:$_GID:" 	>$tmp/expected
  ( runtest "$@" 2>&1 ) 2>&1 >$tmp/actual-raw
  cat -v $tmp/actual-raw >$tmp/actual
  if ! cmp $tmp/expected $tmp/actual >/dev/null 2>&1
  then
    echo "Test $name $* failed:"
	( cd $tmp; diff -U 9999 expected actual | tail -n +3; echo; )
	tests_failed=$(($tests_failed+1))
  fi
  rm -f $tmp/expected $tmp/actual
  tests_count=$(($tests_count+1))
}

##### Test tests/sqlite #####

runtest() {
make_sqlite

# Can it look up the right user
$src/cvm-testclient $src/cvm-sqlite sluser '' testpass

echo
# Does it check the password
$src/cvm-testclient $src/cvm-sqlite sluser '' testpasx

echo
# Does it look up the domain
$src/cvm-testclient $src/cvm-sqlite sluser domain pass2

rm $CVM_SQLITE_DB
}
vecho "Running test tests/sqlite "
run_compare_test tests/sqlite  <<END_OF_TEST_RESULTS
user name:        sluser
user ID:          123
group ID:         456
real name:        realname
directory:        /home/sluser
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           
mailbox path:     (null)

cvm-testclient: Authentication failed, error #100 (Credentials rejected)

user name:        sluser
user ID:          234
group ID:         567
real name:        sluser2
directory:        /home/sluser2
shell:            /bin/true
group name:       (null)
system user name: (null)
system directory: (null)
domain:           domain
mailbox path:     (null)
END_OF_TEST_RESULTS


##### Test tests/qmail-lookup-assume #####

runtest() {
env CVM_LOOKUP_SECRET=secret \
$src/cvm-testclient $tmp/cvm-qmail-lookup user nothingness

echo

env CVM_LOOKUP_SECRET=secret CVM_QMAIL_ASSUME_LOCAL=1 \
$src/cvm-testclient $tmp/cvm-qmail-lookup user nothingness
}
vecho "Running test tests/qmail-lookup-assume "
run_compare_test tests/qmail-lookup-assume  <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     1

user name:        user
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           nothingness
mailbox path:     @TMPDIR@/home
END_OF_TEST_RESULTS


##### Test tests/vmlookup-normal #####

runtest() {
CVM_LOOKUP_SECRET=secret \
$src/cvm-testclient $tmp/cvm-vmailmgr-lookup virt test.tld
}
vecho "Running test tests/vmlookup-normal "
run_compare_test tests/vmlookup-normal  <<END_OF_TEST_RESULTS
user name:        virt
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home/virt
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home/virt
END_OF_TEST_RESULTS


##### Test tests/sql-substitution #####

runtest() {
sqt() { env - var1=1 var_2=2 $src/sql-query-test "$@"; }
sqt 'one two' act dom
sqt '$account $domain one two' act dom
sqt 'one $account two' act dom
sqt 'one two $account' act dom
sqt '$var1 one two' act dom
sqt 'one $var1 two' act dom
sqt 'one two $var1' act dom
sqt '$var_2 one two' act dom
sqt 'one $var_2 two' act dom
sqt 'one two $var_2' act dom
sqt '$var1one two' act dom
sqt 'one $var1two' act dom
sqt '${var1} one two' act dom
sqt 'one ${var1} two' act dom
sqt 'one two ${var1}' act dom
}
vecho "Running test tests/sql-substitution "
run_compare_test tests/sql-substitution  <<END_OF_TEST_RESULTS
one two
'act' 'dom' one two
one 'act' two
one two 'act'
'1' one two
one '1' two
one two '1'
'2' one two
one '2' two
one two '2'
 two
one 
'1' one two
one '1' two
one two '1'
END_OF_TEST_RESULTS


##### Test tests/vmlookup-notable #####

runtest() {
mv $home/passwd.cdb $home/passwd.cdb.donotuse

$src/cvm-testclient $src/cvm-vmailmgr virt test.tld 'xpass'

mv $home/passwd.cdb.donotuse $home/passwd.cdb
chmod 000 $home/passwd.cdb

$src/cvm-testclient $src/cvm-vmailmgr virt test.tld 'xpass'

chmod 444 $home/passwd.cdb
}
vecho "Running test tests/vmlookup-notable "
run_compare_test tests/vmlookup-notable  <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     1
cvm-testclient: Authentication failed, error #4 (Input/Output error)
END_OF_TEST_RESULTS


##### Test tests/pwfile-crypt #####

runtest() {
make_pwfile
CVM_PWFILE_PWCMP=crypt export CVM_PWFILE_PWCMP
$src/cvm-testclient $src/cvm-pwfile cryptuser '' testpass
}
vecho "Running test tests/pwfile-crypt "
run_compare_test tests/pwfile-crypt  <<END_OF_TEST_RESULTS
user name:        cryptuser
user ID:          234
group ID:         567
real name:        Crypt
directory:        /home/crypt
shell:            /bin/true
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
END_OF_TEST_RESULTS


##### Test tests/vmlookup-upper-virt #####

runtest() {
CVM_LOOKUP_SECRET=secret \
$src/cvm-testclient $tmp/cvm-vmailmgr-lookup Virt test.tld
}
vecho "Running test tests/vmlookup-upper-virt "
run_compare_test tests/vmlookup-upper-virt  <<END_OF_TEST_RESULTS
user name:        virt
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home/virt
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home/virt
END_OF_TEST_RESULTS


##### Test tests/qmail-lookup-novirtualdomains #####

runtest() {
mv $QMAIL_ROOT/control/virtualdomains $QMAIL_ROOT/control/vds

env CVM_LOOKUP_SECRET=secret \
$src/cvm-testclient $tmp/cvm-qmail-lookup user test.tld

mv $QMAIL_ROOT/control/vds $QMAIL_ROOT/control/virtualdomains
}
vecho "Running test tests/qmail-lookup-novirtualdomains "
run_compare_test tests/qmail-lookup-novirtualdomains  <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     1
END_OF_TEST_RESULTS


##### Test tests/qmail-lookup #####

runtest() {
local addr="$1"
local domain="$2"

env CVM_LOOKUP_SECRET=secret \
$src/cvm-testclient $tmp/cvm-qmail-lookup $addr $domain
}
vecho "Running test tests/qmail-lookup 'user' 'local.dom'"
run_compare_test tests/qmail-lookup 'user' 'local.dom' <<END_OF_TEST_RESULTS
user name:        user
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           local.dom
mailbox path:     @TMPDIR@/home
END_OF_TEST_RESULTS

vecho "Running test tests/qmail-lookup 'user-addr' 'local.dom'"
run_compare_test tests/qmail-lookup 'user-addr' 'local.dom' <<END_OF_TEST_RESULTS
user name:        user
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           local.dom
mailbox path:     @TMPDIR@/home
END_OF_TEST_RESULTS

vecho "Running test tests/qmail-lookup 'user-addr-x' 'local.dom'"
run_compare_test tests/qmail-lookup 'user-addr-x' 'local.dom' <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     0
END_OF_TEST_RESULTS

vecho "Running test tests/qmail-lookup 'user-wild' 'local.dom'"
run_compare_test tests/qmail-lookup 'user-wild' 'local.dom' <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     0
END_OF_TEST_RESULTS

vecho "Running test tests/qmail-lookup 'user-wild-x' 'local.dom'"
run_compare_test tests/qmail-lookup 'user-wild-x' 'local.dom' <<END_OF_TEST_RESULTS
user name:        user
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           local.dom
mailbox path:     @TMPDIR@/home
END_OF_TEST_RESULTS

vecho "Running test tests/qmail-lookup 'user-wild-x-y-z' 'local.dom'"
run_compare_test tests/qmail-lookup 'user-wild-x-y-z' 'local.dom' <<END_OF_TEST_RESULTS
user name:        user
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           local.dom
mailbox path:     @TMPDIR@/home
END_OF_TEST_RESULTS

vecho "Running test tests/qmail-lookup 'alias' 'local.dom'"
run_compare_test tests/qmail-lookup 'alias' 'local.dom' <<END_OF_TEST_RESULTS
user name:        alias
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/alias
shell:            (null)
group name:       (null)
system user name: alias
system directory: @TMPDIR@/alias
domain:           local.dom
mailbox path:     @TMPDIR@/alias
END_OF_TEST_RESULTS

vecho "Running test tests/qmail-lookup 'alias-x' 'local.dom'"
run_compare_test tests/qmail-lookup 'alias-x' 'local.dom' <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     0
END_OF_TEST_RESULTS

vecho "Running test tests/qmail-lookup 'awild' 'local.dom'"
run_compare_test tests/qmail-lookup 'awild' 'local.dom' <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     0
END_OF_TEST_RESULTS

vecho "Running test tests/qmail-lookup 'awild-x' 'local.dom'"
run_compare_test tests/qmail-lookup 'awild-x' 'local.dom' <<END_OF_TEST_RESULTS
user name:        alias
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/alias
shell:            (null)
group name:       (null)
system user name: alias
system directory: @TMPDIR@/alias
domain:           local.dom
mailbox path:     @TMPDIR@/alias
END_OF_TEST_RESULTS

vecho "Running test tests/qmail-lookup 'USER' 'local.dom'"
run_compare_test tests/qmail-lookup 'USER' 'local.dom' <<END_OF_TEST_RESULTS
user name:        user
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           local.dom
mailbox path:     @TMPDIR@/home
END_OF_TEST_RESULTS

vecho "Running test tests/qmail-lookup 'user-ADDR' 'local.dom'"
run_compare_test tests/qmail-lookup 'user-ADDR' 'local.dom' <<END_OF_TEST_RESULTS
user name:        user
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           local.dom
mailbox path:     @TMPDIR@/home
END_OF_TEST_RESULTS

vecho "Running test tests/qmail-lookup 'USER-ADDR' 'local.dom'"
run_compare_test tests/qmail-lookup 'USER-ADDR' 'local.dom' <<END_OF_TEST_RESULTS
user name:        user
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           local.dom
mailbox path:     @TMPDIR@/home
END_OF_TEST_RESULTS

vecho "Running test tests/qmail-lookup 'user-dot.addr' 'local.dom'"
run_compare_test tests/qmail-lookup 'user-dot.addr' 'local.dom' <<END_OF_TEST_RESULTS
user name:        user
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           local.dom
mailbox path:     @TMPDIR@/home
END_OF_TEST_RESULTS

vecho "Running test tests/qmail-lookup 'adot.addr' 'local.dom'"
run_compare_test tests/qmail-lookup 'adot.addr' 'local.dom' <<END_OF_TEST_RESULTS
user name:        alias
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/alias
shell:            (null)
group name:       (null)
system user name: alias
system directory: @TMPDIR@/alias
domain:           local.dom
mailbox path:     @TMPDIR@/alias
END_OF_TEST_RESULTS


##### Test tests/chain-client #####

runtest() {
$src/cvm-testclient $src/cvm-pwfile,$src/cvm-vmailmgr pwfuser test.tld testpass
echo
$src/cvm-testclient $src/cvm-pwfile,$src/cvm-vmailmgr virt test.tld pass
echo
$src/cvm-testclient $src/cvm-pwfile,$src/cvm-vmailmgr notexist test.tld pass
echo
$src/cvm-testclient $src/cvm-pwfile,$src/cvm-vmailmgr notexist other.dom pass
}
vecho "Running test tests/chain-client "
run_compare_test tests/chain-client  <<END_OF_TEST_RESULTS
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)

user name:        virt
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home/virt
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home/virt

cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     0

cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     1
END_OF_TEST_RESULTS


##### Test tests/command-bad-username #####

runtest() {
make_pwfile
$src/cvm-testclient $src/cvm-pwfile pxfuser '' testpass
}
vecho "Running test tests/command-bad-username "
run_compare_test tests/command-bad-username  <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
END_OF_TEST_RESULTS


##### Test tests/sasl-eof #####

runtest() {
sasltest LOGIN </dev/null
}
vecho "Running test tests/sasl-eof "
run_compare_test tests/sasl-eof  <<END_OF_TEST_RESULTS
sasl-auth-test: AUTH LOGIN PLAIN
+ VXNlcm5hbWU6^M
sasl-auth-test: SASL AUTH LOGIN failed
sasl-auth-test: Fatal: sasl_auth1 failed: 8
  535 End of file reached.
END_OF_TEST_RESULTS


##### Test tests/vmailmgr-xconvert #####

runtest() {
env VMAILMGR_AUTOCONVERT=1 \
$src/cvm-testclient $src/cvm-vmailmgr virt test.tld pass
echo
$src/cvm-testclient $src/cvm-vmailmgr virt test.tld pass
echo
cdbget virt <$home/passwd.cdb | xxd
}
vecho "Running test tests/vmailmgr-xconvert "
run_compare_test tests/vmailmgr-xconvert  <<END_OF_TEST_RESULTS
user name:        virt
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home/virt
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home/virt

user name:        virt
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home/virt
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home/virt

00000000: 020a 0108 0100 2430 2470 6173 7300 2e2f  ......\$0\$pass../
00000010: 7669 7274 0000 002d 002d 002d 002d 0031  virt...-.-.-.-.1
00000020: 3031 3637 3331 3335 3800 2d00            016731358.-.
END_OF_TEST_RESULTS


##### Test tests/pwfile #####

runtest() {
make_pwfile
$src/cvm-testclient $src/cvm-pwfile pwfuser '' testpass
}
vecho "Running test tests/pwfile "
run_compare_test tests/pwfile  <<END_OF_TEST_RESULTS
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
END_OF_TEST_RESULTS


##### Test tests/vmlookup-baddomain #####

runtest() {
CVM_LOOKUP_SECRET=secret \
$src/cvm-testclient $tmp/cvm-vmailmgr-lookup virt other.tld
}
vecho "Running test tests/vmlookup-baddomain "
run_compare_test tests/vmlookup-baddomain  <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     1
END_OF_TEST_RESULTS


##### Test tests/sasl-login2 #####

runtest() {
sasltest LOGIN\ cHdmdXNlcg== <<EOF
dGVzdHBhc3M=
EOF
}
vecho "Running test tests/sasl-login2 "
run_compare_test tests/sasl-login2  <<END_OF_TEST_RESULTS
sasl-auth-test: AUTH LOGIN PLAIN
+ UGFzc3dvcmQ6^M
sasl-auth-test: SASL AUTH LOGIN username=pwfuser
END_OF_TEST_RESULTS


##### Test tests/command-case #####

runtest() {
make_pwfile
$src/cvm-testclient $src/cvm-pwfile PWFUser '' testpass
}
vecho "Running test tests/command-case "
run_compare_test tests/command-case  <<END_OF_TEST_RESULTS
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
END_OF_TEST_RESULTS


##### Test tests/vmlookup-pass #####

runtest() {
CVM_LOOKUP_SECRET=secret \
$src/cvm-testclient $tmp/cvm-vmailmgr-lookup virt test.tld
}
vecho "Running test tests/vmlookup-pass "
run_compare_test tests/vmlookup-pass  <<END_OF_TEST_RESULTS
user name:        virt
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home/virt
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home/virt
END_OF_TEST_RESULTS


##### Test tests/vmailmgr-upper-pass #####

runtest() {
$src/cvm-testclient $src/cvm-vmailmgr virt test.tld Pass
}
vecho "Running test tests/vmailmgr-upper-pass "
run_compare_test tests/vmailmgr-upper-pass  <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     0
END_OF_TEST_RESULTS


##### Test tests/vmlookup-upper-domain #####

runtest() {
CVM_LOOKUP_SECRET=secret \
$src/cvm-testclient $tmp/cvm-vmailmgr-lookup virt Test.TLD
}
vecho "Running test tests/vmlookup-upper-domain "
run_compare_test tests/vmlookup-upper-domain  <<END_OF_TEST_RESULTS
user name:        virt
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home/virt
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home/virt
END_OF_TEST_RESULTS


##### Test tests/sasl-login1 #####

runtest() {
sasltest LOGIN <<EOF
cHdmdXNlcg==
dGVzdHBhc3M=
EOF
}
vecho "Running test tests/sasl-login1 "
run_compare_test tests/sasl-login1  <<END_OF_TEST_RESULTS
sasl-auth-test: AUTH LOGIN PLAIN
+ VXNlcm5hbWU6^M
+ UGFzc3dvcmQ6^M
sasl-auth-test: SASL AUTH LOGIN username=pwfuser
END_OF_TEST_RESULTS


##### Test tests/sasl-plain1 #####

runtest() {
sasltest PLAIN <<EOF
cHdmdXNlcgBwd2Z1c2VyAHRlc3RwYXNz
EOF
}
vecho "Running test tests/sasl-plain1 "
run_compare_test tests/sasl-plain1  <<END_OF_TEST_RESULTS
sasl-auth-test: AUTH LOGIN PLAIN
+ ^M
sasl-auth-test: SASL AUTH PLAIN username=pwfuser
END_OF_TEST_RESULTS


##### Test tests/sasl-plain-fail #####

runtest() {
sasltest PLAIN\ cHdmdXNlcgBwd2Z1c2VyAHRlc3RwYXNZ </dev/null
}
vecho "Running test tests/sasl-plain-fail "
run_compare_test tests/sasl-plain-fail  <<END_OF_TEST_RESULTS
sasl-auth-test: AUTH LOGIN PLAIN
sasl-auth-test: SASL AUTH PLAIN failed
sasl-auth-test: Fatal: sasl_auth1 failed: 1
  501 Authentication failed.
END_OF_TEST_RESULTS


##### Test tests/qmail-lookup-baddomain #####

runtest() {
env CVM_LOOKUP_SECRET=secret \
$src/cvm-testclient $tmp/cvm-qmail-lookup user other.dom
}
vecho "Running test tests/qmail-lookup-baddomain "
run_compare_test tests/qmail-lookup-baddomain  <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     1
END_OF_TEST_RESULTS


##### Test tests/sasl-plain2 #####

runtest() {
sasltest PLAIN\ cHdmdXNlcgBwd2Z1c2VyAHRlc3RwYXNz </dev/null
}
vecho "Running test tests/sasl-plain2 "
run_compare_test tests/sasl-plain2  <<END_OF_TEST_RESULTS
sasl-auth-test: AUTH LOGIN PLAIN
sasl-auth-test: SASL AUTH PLAIN username=pwfuser
END_OF_TEST_RESULTS


##### Test tests/vmlookup-baduser #####

runtest() {
CVM_LOOKUP_SECRET=secret \
$src/cvm-testclient $tmp/cvm-vmailmgr-lookup missing test.tld
}
vecho "Running test tests/vmlookup-baduser "
run_compare_test tests/vmlookup-baduser  <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     0
END_OF_TEST_RESULTS


##### Test tests/vmlookup-badpass #####

runtest() {
$src/cvm-testclient $src/cvm-vmailmgr virt test.tld 'xpass'
}
vecho "Running test tests/vmlookup-badpass "
run_compare_test tests/vmlookup-badpass  <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     0
END_OF_TEST_RESULTS


##### Test tests/vmailmgr-upper-virt #####

runtest() {
$src/cvm-testclient $src/cvm-vmailmgr Virt test.tld pass
}
vecho "Running test tests/vmailmgr-upper-virt "
run_compare_test tests/vmailmgr-upper-virt  <<END_OF_TEST_RESULTS
user name:        virt
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home/virt
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home/virt
END_OF_TEST_RESULTS


##### Test tests/command-no-prefix #####

runtest() {
make_pwfile
$src/cvm-testclient $src/cvm-pwfile pwfuser '' testpass
}
vecho "Running test tests/command-no-prefix "
run_compare_test tests/command-no-prefix  <<END_OF_TEST_RESULTS
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
END_OF_TEST_RESULTS


##### Test tests/vmailmgr-upper-domain #####

runtest() {
$src/cvm-testclient $src/cvm-vmailmgr virt Test.TLD pass
}
vecho "Running test tests/vmailmgr-upper-domain "
run_compare_test tests/vmailmgr-upper-domain  <<END_OF_TEST_RESULTS
user name:        virt
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home/virt
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home/virt
END_OF_TEST_RESULTS


##### Test tests/pwfile-bad-password #####

runtest() {
make_pwfile
$src/cvm-testclient $src/cvm-pwfile pwfuser '' testpaxx
}
vecho "Running test tests/pwfile-bad-password "
run_compare_test tests/pwfile-bad-password  <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
END_OF_TEST_RESULTS


##### Test tests/vmailmgr-normal #####

runtest() {
$src/cvm-testclient $src/cvm-vmailmgr virt test.tld pass
echo
$src/cvm-testclient $src/cvm-vmailmgr missing test.tld pass
}
vecho "Running test tests/vmailmgr-normal "
run_compare_test tests/vmailmgr-normal  <<END_OF_TEST_RESULTS
user name:        virt
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home/virt
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home/virt

cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     0
END_OF_TEST_RESULTS


##### Test tests/qmail-lookup-nodomain #####

runtest() {
CVM_LOOKUP_SECRET=secret \
$src/cvm-testclient $tmp/cvm-qmail-lookup addr ''
}
vecho "Running test tests/qmail-lookup-nodomain "
run_compare_test tests/qmail-lookup-nodomain  <<END_OF_TEST_RESULTS
user name:        user
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           noathost
mailbox path:     @TMPDIR@/home
END_OF_TEST_RESULTS


##### Test tests/qmail-lookup-perms #####

runtest() {
doit() {
    echo "$1" >$tmp/.qmail-lookaside-default
    $src/cvm-testclient $tmp/cvm-qmail-lookup lookaside-someone test.tld
}

export CVM_LOOKUP_SECRET=secret
export CVM_QMAIL_CHECK_PERMS=0

$src/cvm-testclient $tmp/cvm-qmail-lookup addr test.tld

chmod 000 $home
echo
$src/cvm-testclient $tmp/cvm-qmail-lookup addr test.tld

export CVM_QMAIL_CHECK_PERMS=-
echo
$src/cvm-testclient $tmp/cvm-qmail-lookup addr test.tld

chmod 755 $home

unset CVM_LOOKUP_SECRET
unset CVM_QMAIL_CHECK_PERMS
}
vecho "Running test tests/qmail-lookup-perms "
run_compare_test tests/qmail-lookup-perms  <<END_OF_TEST_RESULTS
user name:        user
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home

cvm-testclient: Authentication failed, error #4 (Input/Output error)

cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     0
END_OF_TEST_RESULTS


##### Test tests/v1lookup #####

runtest() {
local secret="$1"

make_pwfile
cat <<EOF >$tmp/cvmlookup
#!/bin/sh
CVM_LOOKUP_SECRET=$secret
export CVM_LOOKUP_SECRET
exec $src/cvm-pwfile
EOF
chmod +x $tmp/cvmlookup

$src/cvm-v1testclient $tmp/cvmlookup pwfuser ''
$src/cvm-v1testclient $tmp/cvmlookup pwfuser '' ''
$src/cvm-v1testclient $tmp/cvmlookup pwfuser '' secret

rm -f $tmp/cvmlookup
}
vecho "Running test tests/v1lookup ''"
run_compare_test tests/v1lookup '' <<END_OF_TEST_RESULTS
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
END_OF_TEST_RESULTS

vecho "Running test tests/v1lookup 'secret'"
run_compare_test tests/v1lookup 'secret' <<END_OF_TEST_RESULTS
cvm-v1testclient: Fatal: Authentication failed, error #7 (Credential missing in data from module)
cvm-v1testclient: Fatal: Authentication failed, error #7 (Credential missing in data from module)
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
END_OF_TEST_RESULTS


##### Test tests/qmail-lookup-lookaside #####

runtest() {
doit() {
    echo "$1" >$home/.qmail-lookaside-default
    $src/cvm-testclient $tmp/cvm-qmail-lookup lookaside-someone test.tld
}

export CVM_LOOKUP_SECRET=secret
export CVM_QMAIL_LOOKASIDE='/bin/program1 /bin/program2 /bin/program3'

doit '| /bin/program foo'
echo
doit '| /bin/program1 foo'
echo
doit '| /bin/program2 foo'
echo
doit '| /bin/program3 foo'
echo
doit ' |/bin/program1'
echo
doit $'#before\n|/bin/program2\n#after'

unset CVM_LOOKUP_SECRET
unset CVM_QMAIL_LOOKASIDE
}
vecho "Running test tests/qmail-lookup-lookaside "
run_compare_test tests/qmail-lookup-lookaside  <<END_OF_TEST_RESULTS
user name:        user
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home

cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     1

cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     1

cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     1

cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     1

cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     1
END_OF_TEST_RESULTS


##### Test tests/lookup #####

runtest() {
local secret="$1"

make_pwfile
cat <<EOF >$tmp/cvmlookup
#!/bin/sh
CVM_LOOKUP_SECRET=$secret
export CVM_LOOKUP_SECRET
exec $src/cvm-pwfile
EOF
chmod +x $tmp/cvmlookup

$src/cvm-testclient $tmp/cvmlookup pwfuser ''
env CVM_LOOKUP_SECRET='' \
$src/cvm-testclient $tmp/cvmlookup pwfuser ''
env CVM_LOOKUP_SECRET=$secret \
$src/cvm-testclient $tmp/cvmlookup pwfuser ''

rm -f $tmp/cvmlookup
}
vecho "Running test tests/lookup ''"
run_compare_test tests/lookup '' <<END_OF_TEST_RESULTS
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
END_OF_TEST_RESULTS

vecho "Running test tests/lookup 'secret'"
run_compare_test tests/lookup 'secret' <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #7 (Credential missing in data from module)
cvm-testclient: Authentication failed, error #7 (Credential missing in data from module)
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
END_OF_TEST_RESULTS


##### Test tests/chain-module #####

runtest() {
CVM_CHAIN0=$src/cvm-pwfile
CVM_CHAIN1=$src/cvm-vmailmgr
export CVM_CHAIN0 CVM_CHAIN1

$src/cvm-testclient $src/cvm-chain pwfuser test.tld testpass
echo
$src/cvm-testclient $src/cvm-chain virt test.tld pass
echo
$src/cvm-testclient $src/cvm-chain notexist test.tld pass
echo
$src/cvm-testclient $src/cvm-chain notexist other.dom pass

unset CVM_CHAIN0 CVM_CHAIN1
}
vecho "Running test tests/chain-module "
run_compare_test tests/chain-module  <<END_OF_TEST_RESULTS
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)

user name:        virt
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home/virt
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home/virt

cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     0

cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     1
END_OF_TEST_RESULTS


##### Test tests/sasl-nomech #####

runtest() {
sasltest BOGUS </dev/null
}
vecho "Running test tests/sasl-nomech "
run_compare_test tests/sasl-nomech  <<END_OF_TEST_RESULTS
sasl-auth-test: AUTH LOGIN PLAIN
sasl-auth-test: SASL AUTH BOGUS failed
sasl-auth-test: Fatal: sasl_auth1 failed: 2
  504 Unrecognized authentication mechanism.
END_OF_TEST_RESULTS


##### Test tests/command-bad-password #####

runtest() {
make_pwfile
$src/cvm-testclient $src/cvm-pwfile pwfuser '' testpassx
}
vecho "Running test tests/command-bad-password "
run_compare_test tests/command-bad-password  <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
END_OF_TEST_RESULTS


##### Test tests/split #####

runtest() {
local dom1="$1"
local dom2="$2"
$src/cvm-testclient $src/cvm-vmailmgr virt$dom1 "$dom2" pass
}
vecho "Running test tests/split '' ''"
run_compare_test tests/split '' '' <<END_OF_TEST_RESULTS
user name:        virt
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home/virt
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           noathost
mailbox path:     @TMPDIR@/home/virt
END_OF_TEST_RESULTS

vecho "Running test tests/split '' 'test.tld'"
run_compare_test tests/split '' 'test.tld' <<END_OF_TEST_RESULTS
user name:        virt
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home/virt
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home/virt
END_OF_TEST_RESULTS

vecho "Running test tests/split '' 'other.tld'"
run_compare_test tests/split '' 'other.tld' <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     1
END_OF_TEST_RESULTS

vecho "Running test tests/split '@test.tld' ''"
run_compare_test tests/split '@test.tld' '' <<END_OF_TEST_RESULTS
user name:        virt
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home/virt
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home/virt
END_OF_TEST_RESULTS

vecho "Running test tests/split '@test.tld' 'test.tld'"
run_compare_test tests/split '@test.tld' 'test.tld' <<END_OF_TEST_RESULTS
user name:        virt
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home/virt
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home/virt
END_OF_TEST_RESULTS

vecho "Running test tests/split '@test.tld' 'other.tld'"
run_compare_test tests/split '@test.tld' 'other.tld' <<END_OF_TEST_RESULTS
user name:        virt
user ID:          @UID@
group ID:         @GID@
real name:        (null)
directory:        @TMPDIR@/home/virt
shell:            (null)
group name:       (null)
system user name: user
system directory: @TMPDIR@/home
domain:           test.tld
mailbox path:     @TMPDIR@/home/virt
END_OF_TEST_RESULTS

vecho "Running test tests/split '@other.tld' ''"
run_compare_test tests/split '@other.tld' '' <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     1
END_OF_TEST_RESULTS

vecho "Running test tests/split '@other.tld' 'test.tld'"
run_compare_test tests/split '@other.tld' 'test.tld' <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     1
END_OF_TEST_RESULTS

vecho "Running test tests/split '@other.tld' 'other.tld'"
run_compare_test tests/split '@other.tld' 'other.tld' <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
out of scope:     1
END_OF_TEST_RESULTS


##### Test tests/command-prefix #####

runtest() {
make_pwfile
$src/cvm-testclient cvm-command:$src/cvm-pwfile pwfuser '' testpass
}
vecho "Running test tests/command-prefix "
run_compare_test tests/command-prefix  <<END_OF_TEST_RESULTS
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
END_OF_TEST_RESULTS


##### Test tests/start-pwfile-local #####

runtest() {
$src/cvm-pwfile cvm-local:$tmp/socket >$tmp/log &
echo $! >$tmp/pid
sleep 1
cat $tmp/log
}
vecho "Running test tests/start-pwfile-local "
run_compare_test tests/start-pwfile-local  <<END_OF_TEST_RESULTS
Starting.
END_OF_TEST_RESULTS


##### Test tests/v1local #####

runtest() {
make_pwfile
$src/cvm-v1testclient cvm-local:$tmp/socket pwfuser '' testpass
tail -n 1 $tmp/log
}
vecho "Running test tests/v1local "
run_compare_test tests/v1local  <<END_OF_TEST_RESULTS
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
+ pwfuser
END_OF_TEST_RESULTS


##### Test tests/pwfile-local #####

runtest() {
make_pwfile
$src/cvm-testclient cvm-local:$tmp/socket pwfuser '' testpass
tail -n 1 $tmp/log
}
vecho "Running test tests/pwfile-local "
run_compare_test tests/pwfile-local  <<END_OF_TEST_RESULTS
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
+ pwfuser
END_OF_TEST_RESULTS


##### Test tests/pwfile-local-bad-password #####

runtest() {
make_pwfile
$src/cvm-testclient cvm-local:$tmp/socket pwfuser '' testpaxx
tail -n 1 $tmp/log
}
vecho "Running test tests/pwfile-local-bad-password "
run_compare_test tests/pwfile-local-bad-password  <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
- pwfuser
END_OF_TEST_RESULTS


##### Test tests/stop-pwfile-local #####

runtest() {
kill `cat $tmp/pid`
rm -f $tmp/pid
sleep 1
tail -n 1 $tmp/log
echo `cat $tmp/log | wc`
rm -f $tmp/log
test -e $tmp/socket || echo Socket was removed.
}
vecho "Running test tests/stop-pwfile-local "
run_compare_test tests/stop-pwfile-local  <<END_OF_TEST_RESULTS
Stopping.
5 8 50
Socket was removed.
END_OF_TEST_RESULTS


##### Test tests/start-pwfile-udp #####

runtest() {
$src/cvm-pwfile cvm-udp:127.1.2.3:12345 >$tmp/log &
echo $! >$tmp/pid
sleep 1
cat $tmp/log
}
vecho "Running test tests/start-pwfile-udp "
run_compare_test tests/start-pwfile-udp  <<END_OF_TEST_RESULTS
Starting.
END_OF_TEST_RESULTS


##### Test tests/v1udp #####

runtest() {
make_pwfile
$src/cvm-v1testclient cvm-udp:127.1.2.3:12345 pwfuser '' testpass
tail -n 1 $tmp/log
}
vecho "Running test tests/v1udp "
run_compare_test tests/v1udp  <<END_OF_TEST_RESULTS
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
+ pwfuser
END_OF_TEST_RESULTS


##### Test tests/pwfile-udp #####

runtest() {
make_pwfile
$src/cvm-testclient cvm-udp:127.1.2.3:12345 pwfuser '' testpass
tail -n 1 $tmp/log
}
vecho "Running test tests/pwfile-udp "
run_compare_test tests/pwfile-udp  <<END_OF_TEST_RESULTS
user name:        pwfuser
user ID:          123
group ID:         456
real name:        Gecos
directory:        /home/ftp
shell:            /bin/false
group name:       (null)
system user name: (null)
system directory: (null)
domain:           (null)
mailbox path:     (null)
+ pwfuser
END_OF_TEST_RESULTS


##### Test tests/pwfile-udp-bad-password #####

runtest() {
make_pwfile
$src/cvm-testclient cvm-udp:127.1.2.3:12345 pwfuser '' testpaxx
tail -n 1 $tmp/log
}
vecho "Running test tests/pwfile-udp-bad-password "
run_compare_test tests/pwfile-udp-bad-password  <<END_OF_TEST_RESULTS
cvm-testclient: Authentication failed, error #100 (Credentials rejected)
- pwfuser
END_OF_TEST_RESULTS


##### Test tests/stop-pwfile-udp #####

runtest() {
kill `cat $tmp/pid`
rm -f $tmp/pid
sleep 1
tail -n 1 $tmp/log
echo `cat $tmp/log | wc`
rm -f $tmp/log
}
vecho "Running test tests/stop-pwfile-udp "
run_compare_test tests/stop-pwfile-udp  <<END_OF_TEST_RESULTS
Stopping.
5 8 50
END_OF_TEST_RESULTS


rm -rf $tmp
echo $tests_count tests executed, $tests_failed failures
if [ $tests_failed != 0 ]; then exit 1; fi