agent-timeout.sh 986 B

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