1#	$OpenBSD: agent-timeout.sh,v 1.6 2019/11/26 23:43:10 djm Exp $
2#	Placed in the Public Domain.
3
4tid="agent timeout test"
5
6SSHAGENT_TIMEOUT=10
7
8trace "start agent"
9eval `${SSHAGENT} -s ${EXTRA_AGENT_ARGS}` > /dev/null
10r=$?
11if [ $r -ne 0 ]; then
12	fail "could not start ssh-agent: exit code $r"
13else
14	trace "add keys with timeout"
15	keys=0
16	for t in ${SSH_KEYTYPES}; do
17		${SSHADD} -kt ${SSHAGENT_TIMEOUT} $OBJ/$t > /dev/null 2>&1
18		if [ $? -ne 0 ]; then
19			fail "ssh-add did succeed exit code 0"
20		fi
21		keys=$((${keys} + 1))
22	done
23	n=`${SSHADD} -l 2> /dev/null | wc -l`
24	trace "agent has $n keys"
25	if [ $n -ne $keys ]; then
26		fail "ssh-add -l did not return $keys keys: $n"
27	fi
28	trace "sleeping 2*${SSHAGENT_TIMEOUT} seconds"
29	sleep ${SSHAGENT_TIMEOUT}
30	sleep ${SSHAGENT_TIMEOUT}
31	${SSHADD} -l 2> /dev/null | grep 'The agent has no identities.' >/dev/null
32	if [ $? -ne 0 ]; then
33		fail "ssh-add -l still returns keys after timeout"
34	fi
35
36	trace "kill agent"
37	${SSHAGENT} -k > /dev/null
38fi
39