summaryrefslogtreecommitdiff
path: root/tests/test-swaks.sh
blob: 9f521b910a63ab3addb74ac24f93a5ff06fba630 (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
#!/bin/bash

local='dummy@bitmask.net'
nobody_local='fooooooo@bitmask.net'
external='dummy@leap.se'
server='leech.bitmask.net'
exit_code=0

# override $server with possible exported shell var
[ $SWAKS_SERVER ] && server=$SWAKS_SERVER

swaks_options="--timeout 5 --server $server --hide-informational --suppress-data"
swaks_auth="--tlsc --tls-cert $HOME/leap/test/certs/cert.crt --tls-key $HOME/leap/test/certs/cert.key"

echo "swaks_options: $swaks_options"
echo "swaks_auth   : $swaks_auth"
echo

test_swaks() {
  local from=$1
  shift
  local to=$1
  shift
  local expected_repsonse_code=$1
  shift
  local options="$@"

  response=`swaks -f $from -t $to $options | tail -3 | head -1`
  response_code=`echo "$response"| cut -d' ' -f 2-|sed 's/^ //g'|cut -d' ' -f 1 `
  if [ "$response_code" == "$expected_repsonse_code" ]
  then
    echo -n 'OK:      '
  else
    echo -n 'WARNING: '
    exit_code=1
  fi
 
  [[ "$options" == *--tls* ]] && authentication='authenticated    ' || authentication='no authentication'
  [  ]
  echo "From $from, to $to, $authentication: $response"
}


test_delivery() {
  local from=$1
  local to=$2
  local unauth_repsonse_code=$3
  local auth_response_code=$4 

  test_swaks $from $to $unauth_repsonse_code $swaks_options 
  test_swaks $from $to $auth_response_code $swaks_options $swaks_auth 

  echo
}


test_delivery $local $local 250 250
test_delivery $local $nobody_local 550 550
test_delivery $local $external 554 250

echo

test_delivery $nobody_local $local 250 250
test_delivery $nobody_local $nobody_local 550 550
test_delivery $nobody_local $external 554 250

echo

test_delivery $external $local 250 250
test_delivery $external $nobody_local 550 550
test_delivery $external $external 554 250

exit $exit_code