1#!/bin/sh
2
3pass=0
4count=0
5fail=""
6
7RUN_ME_ONCE=1
8export RUN_ME_ONCE
9
10name=$(basename $0)
11
12usage="$name --asan"
13
14asan=""
15
16while test $# -gt 0;
17do
18  case $1 in
19  --fuzzer)
20	  HEIMDAL_FUZZER=1
21	  export HEIMDAL_FUZZER
22	  shift
23	  ;;
24  --asan)
25	  asan="_asan";
26	  DYLD_IMAGE_SUFFIX="_asan"
27	  ASAN_OPTIONS="abort_on_error=1"
28	  export asan ASAN_OPTIONS DYLD_IMAGE_SUFFIX
29	  shift
30	  ;;
31  -h) echo $usage; exit 0;;
32  --help) echo $usage; exit 0;;
33  *) echo "unknown argument $0"; exit 1;;
34  esac
35done
36
37frame_echo() {
38    r=$(echo "$@")
39    echo $r | sed 's/./=/g'
40    echo $r
41    echo $r | sed 's/./=/g'
42}
43
44run_test() {
45    name=$1
46    shift
47    frame_echo "[BEGIN] $name"
48    arg="$1"
49    if [ -x "${arg}${asan}" ]; then
50	arg="${arg}${asan}"
51	shift
52	set -- "$arg" "$@"
53    fi
54    "$@"
55    res=$?
56    if [ "$res" = 0 ]; then
57	frame_echo "[PASS] $name"
58	pass=$(expr $pass + 1)
59    else
60	frame_echo "[FAIL] $name"
61	fail="$fail $name"
62    fi
63    count=$(expr $count + 1)
64}
65
66check_crash() {
67    name=$1
68    old=$2
69    new=$3
70
71    run_test "${name}-crashes" diff -uw $old $new
72}
73
74
75# kill daemon/agent/services to make sure we run the new version
76if sudo -n true ; then
77    sudo killall -9 kcm digest-service kdc com.apple.GSSCred
78    sudo defaults write org.h5l.hx509 AllowHX509Validation -bool true
79fi
80defaults write org.h5l.hx509 AllowHX509Validation -bool true
81
82killall -9 kcm digest-service kdc com.apple.GSSCred
83
84crashuserold=$(mktemp /tmp/heimdal-crash-user-old-XXXXXX)
85crashsystemold=$(mktemp /tmp/heimdal-crash-user-old-XXXXXX)
86crashusernew=$(mktemp /tmp/heimdal-crash-user-new-XXXXXX)
87crashsystemnew=$(mktemp /tmp/heimdal-crash-user-new-XXXXXX)
88crashlogs=/Library/Logs/DiagnosticReports
89
90(cd $HOME/$crashlogs && ls -1 ) > $crashuserold
91(cd $crashlogs && ls -1 ) > $crashsystemold
92
93if [ X"$HEIMDAL_FUZZER" != "X" ] ; then
94    krb5fuzzer=test_srv
95fi
96
97
98# hcrypto
99#for a in test_cipher ; do
100#    run_test $a /usr/local/libexec/heimdal/bin/$a
101#done
102
103# commoncrypto
104for a in test_scram test_ntlm ; do
105    run_test $a /usr/local/libexec/heimdal/bin/$a
106done
107
108# asn1
109for a in check-der check-gen ; do
110    run_test $a /usr/local/libexec/heimdal/bin/$a
111done
112
113# base
114for a in test_base ; do
115    run_test $a /usr/local/libexec/heimdal/bin/$a
116done
117
118# libkrb5
119for a in test-principal heimdal-test-cc test_fx $krb5fuzzer ; do
120    run_test $a /usr/local/libexec/heimdal/bin/$a
121done
122
123# gss
124for a in test_gsscf ; do
125    run_test $a /usr/local/libexec/heimdal/bin/$a
126done
127
128# GSS Apps
129if [ "X${SSH_CONNECTION}" = X ] ; then
130    /AppleInternal/CoreOS/Heimdal/Applications/GSSTestApp.app/Contents/MacOS/GSSTestApp
131fi
132
133# check/kdc
134for a in check-kdc check-fast check-kpasswdd ; do
135    run_test $a /usr/local/libexec/heimdal/tests/kdc/$a
136done
137
138# check/gss
139for a in check-basic check-context ; do
140    run_test $a /usr/local/libexec/heimdal/tests/gss/$a
141done
142
143# check/apple
144if sudo -n true ; then
145    sudo launchctl unload /System/Library/LaunchDaemons/com.apple.Kerberos.kdc.plist
146
147    trap "sudo launchctl load /System/Library/LaunchDaemons/com.apple.Kerberos.kdc.plist" SIGINT EXIT
148
149    for a in check-apple-lkdc check-apple-hodadmin check-server-hodadmin check-apple-od check-apple-no-home-directory ; do
150	run_test $a sudo /usr/local/libexec/heimdal/tests/apple/$a
151    done
152
153    trap - SIGINT EXIT
154
155    sudo launchctl load /System/Library/LaunchDaemons/com.apple.Kerberos.kdc.plist
156
157    # server tests
158    if serverinfo --software / > /dev/null 2>/dev/null ; then
159	for a in check-apple-server ; do
160	    run_test $a sudo /usr/local/libexec/heimdal/tests/apple/$a
161	done
162    fi
163
164else
165    echo "no running tests requiring sudo"
166    fail="$fail no-sudo"
167    count=$(expr $count + 1)
168fi
169
170# check apple non root
171# check-apple-netlogon -- <rdar://problem/16389320> re-enabled netlogon tests
172for a in check-apple-ad check-apple-dump check-apple-mitdump  ; do
173    run_test $a /usr/local/libexec/heimdal/tests/apple/$a
174done
175for a in test_export ; do
176    path="/usr/local/libexec/heimdal/bin/$a"
177    for arch in i386 x86_64 ; do
178        if file $path | grep $arch  > /dev/null ; then
179	    run_test "$a-$arch" arch "-$arch" "$path"
180	fi
181    done
182done
183
184
185if sudo -n true ; then
186    sudo defaults delete /Library/Preferences/org.h5l.hx509 AllowHX509Validation
187fi
188defaults delete /Library/Preferences/org.h5l.hx509 AllowHX509Validation
189
190#
191# Check for new crash logs
192#
193
194(cd $HOME/$crashlogs && ls -1 ) > $crashusernew
195(cd $crashlogs && ls -1 ) > $crashsystemnew
196
197# but only if we are not running under raft, since raft handles that
198if [ X"${VERSIONER_RAFT_VERSION}" == "X" ]; then
199    check_crash system $crashsystemold $crashsystemnew
200    check_crash user $crashuserold $crashusernew
201fi
202
203rm -f $crashusernew $crashuserold $crashsystemnew $crashsystemold
204
205# make sure MallocStackLoggingNoCompact is off
206if sudo -n true ; then
207        sudo launchctl unsetenv MallocStackLoggingNoCompact
208        sudo launchctl unsetenv MallocErrorAbort
209fi
210launchctl unsetenv MallocStackLoggingNoCompact
211launchctl unsetenv MallocErrorAbort
212
213if expr "$count" = "$pass" > /dev/null; then
214    frame_echo "All tests passed"
215    exit 0
216else
217    frame_echo "tests failed:$fail"
218    exit 1
219fi
220