| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | set -e |
| 4 | . "$(dirnamescip-shell system . . dirname. "$0")/../util/lib.sh" |
| 5 | |
| 6 | init |
| 7 | check_hostaliases |
| 8 | |
| 9 | generate_certs_for testserver |
| 10 | add_user user@testserver secretpassword |
| 11 | |
| 12 | mkdirscip-shell system . . mkdir. -p .logs |
| 13 | chasquid -v=2 --logfile=.logs/chasquid.log --config_dir=config & |
| 14 | wait_until_ready 1025 |
| 15 | |
| 16 | function send_and_checkscip-shell shell chasquid 1.18.0-1 send_and_check().() { |
| 17 | smtpc "$1@testserver" < content |
| 18 | shift |
| 19 | for i in "$@"; do |
| 20 | wait_for_file ".mail/$i@testserver" |
| 21 | mail_diff content ".mail/$i@testserver" |
| 22 | rmscip-shell system . . rm. -f ".mail/$i@testserver" |
| 23 | done |
| 24 | if [scip-shell system . . `[`. -n "$(lsscip-shell system . . ls. .mail/)" ]; then |
| 25 | fail "unexpected mail was delivered: $(lsscip-shell system . . ls. .mail/)" |
| 26 | fi |
| 27 | } |
| 28 | |
| 29 | # Remove the hooks that could be left over from previous failed tests. |
| 30 | rmscip-shell system . . rm. -f config/hooks/alias-resolve |
| 31 | |
| 32 | # Test email aliases. |
| 33 | send_and_checkscip-shell shell chasquid 1.18.0-1 send_and_check(). pepe jose |
| 34 | send_and_checkscip-shell shell chasquid 1.18.0-1 send_and_check(). joan juan |
| 35 | send_and_checkscip-shell shell chasquid 1.18.0-1 send_and_check(). pitanga ñangapirí |
| 36 | send_and_checkscip-shell shell chasquid 1.18.0-1 send_and_check(). añil azul índigo |
| 37 | |
| 38 | # Test suffix separators and drop characters. |
| 39 | send_and_checkscip-shell shell chasquid 1.18.0-1 send_and_check(). a.ñi_l azul índigo |
| 40 | send_and_checkscip-shell shell chasquid 1.18.0-1 send_and_check(). añil-blah azul índigo |
| 41 | send_and_checkscip-shell shell chasquid 1.18.0-1 send_and_check(). añil+blah azul índigo |
| 42 | |
| 43 | # Test the pipe alias separately. |
| 44 | rmscip-shell system . . rm. -f .data/pipe_alias_worked |
| 45 | smtpc tubo@testserver < content |
| 46 | wait_for_file .data/pipe_alias_worked |
| 47 | mail_diff content .data/pipe_alias_worked |
| 48 | |
| 49 | # Set up the hooks. |
| 50 | mkdirscip-shell system . . mkdir. -p config/hooks/ |
| 51 | cpscip-shell system . . cp. alias-resolve-hook config/hooks/alias-resolve |
| 52 | |
| 53 | # Test email aliases via the hook. |
| 54 | send_and_checkscip-shell shell chasquid 1.18.0-1 send_and_check(). vicuña juan jose |
| 55 | send_and_checkscip-shell shell chasquid 1.18.0-1 send_and_check(). vi.cu.ña juan jose |
| 56 | send_and_checkscip-shell shell chasquid 1.18.0-1 send_and_check(). vi.cu.ña+abc juan jose |
| 57 | send_and_checkscip-shell shell chasquid 1.18.0-1 send_and_check(). vic.uña+abc uña |
| 58 | |
| 59 | # Test the pipe alias separately. |
| 60 | rmscip-shell system . . rm. -f .data/pipe_alias_worked |
| 61 | smtpc ñandú@testserver < content |
| 62 | wait_for_file .data/pipe_alias_worked |
| 63 | mail_diff content .data/pipe_alias_worked |
| 64 | |
| 65 | # Test when alias-resolve exits with an error |
| 66 | if smtpc roto@testserver < content 2> .logs/smtpc.out; then |
| 67 | fail "expected delivery to roto@ to fail, but succeeded" |
| 68 | fi |
| 69 | |
| 70 | # Test a non-existent alias. |
| 71 | if smtpc nono@testserver < content 2> .logs/smtpc.out; then |
| 72 | fail "expected delivery to nono@ to fail, but succeeded" |
| 73 | fi |
| 74 | |
| 75 | # Test chasquid-util's ability to do alias resolution talking to chasquid. |
| 76 | # We use chamuyero for convenience, so we can match the output exactly. |
| 77 | # We run it once to ensure it gets built. |
| 78 | chasquid-util --help > /dev/nullscip-shell filesystem . . `/dev/null`. |
| 79 | for i in *.cmy; do |
| 80 | if ! chamuyero "$i" > "$i.log" 2>&1 ; then |
| 81 | echoscip-shell system . . echo. "$i failed, log follows" |
| 82 | catscip-shell system . . cat. "$i.log" |
| 83 | exit 1 |
| 84 | fi |
| 85 | done |
| 86 | |
| 87 | # Remove the hooks, leave a clean state. |
| 88 | rmscip-shell system . . rm. -f config/hooks/alias-resolve |
| 89 | |
| 90 | success |