04-force-resources.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/sh
  2. ### Constants
  3. c_valgrind_min=1
  4. reference_file="${scriptdir}/verify-strings/test_scrypt.good"
  5. longwait_encrypted_file="${s_basename}.enc"
  6. longwait_decrypted_file="${s_basename}.txt"
  7. longwait_failed_log="${s_basename}-failed.log"
  8. scenario_cmd() {
  9. # Encrypt file which should take a long time to decrypt.
  10. setup_check "scrypt enc 10 seconds"
  11. (
  12. echo "${password}" | ${c_valgrind_cmd} "${bindir}/scrypt" \
  13. enc -P -t 10 "${reference_file}" \
  14. "${longwait_encrypted_file}"
  15. echo $? > "${c_exitfile}"
  16. )
  17. # Attempt to decrypt it with limited time. We want this
  18. # command to fail, so we negate the normal return code.
  19. setup_check "scrypt dec 1 second"
  20. (
  21. echo "${password}" | ${c_valgrind_cmd} "${bindir}/scrypt" \
  22. dec -P -t 1 "${longwait_encrypted_file}" \
  23. "${longwait_decrypted_file}" \
  24. 2> "${longwait_failed_log}"
  25. expected_exitcode 1 $? > "${c_exitfile}"
  26. )
  27. # We should have received an error message.
  28. setup_check "scrypt dec 1 second error"
  29. grep -q "scrypt: Decrypting file would take too much CPU time" \
  30. "${longwait_failed_log}"
  31. echo "$?" > "${c_exitfile}"
  32. # Attempt to decrypt it with limited time, but force success.
  33. setup_check "scrypt dec force"
  34. (
  35. echo "${password}" | ${c_valgrind_cmd} "${bindir}/scrypt" \
  36. dec -P -t 1 -f "${longwait_encrypted_file}" \
  37. "${longwait_decrypted_file}"
  38. echo $? > "${c_exitfile}"
  39. )
  40. # The decrypted reference file should match the reference.
  41. setup_check "scrypt dec force output against reference"
  42. cmp -s "${longwait_decrypted_file}" "${reference_file}"
  43. echo $? > "${c_exitfile}"
  44. }