Commit af49837c authored by Jason Karns's avatar Jason Karns
Browse files

Helpful error msg for unexpected checksum length

parent 8738d193
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -265,14 +265,16 @@ verify_checksum() {
  [ -e "$filename" ] || return 0

  case "${#expected_checksum}" in
  # If expected checksum is empty, return success
  0) return 0 ;;
  # MD5
  0) return 0 ;; # empty checksum; return success
  32) checksum_command="compute_md5" ;;
  # SHA2 256
  64) checksum_command="compute_sha2" ;;
  # unknown checksum algorithm, return failure
  *) return 1 ;;
  *)
    { echo
      echo "unexpected checksum length: ${#expected_checksum} (${expected_checksum})"
      echo "expected 0 (no checksum), 32 (MD5), or 64 (SHA2-256)"
      echo
    } >&4
    return 1 ;;
  esac

  # If chosen provided checksum algorithm isn't supported, return success
+13 −0
Original line number Diff line number Diff line
@@ -141,3 +141,16 @@ DEF

  unstub shasum
}

@test "package URL with checksum of unexpected length" {
  stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"

  run_inline_definition <<DEF
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#checksum_of_unexpected_length" copy
DEF

  assert_failure
  [ ! -f "${INSTALL_ROOT}/bin/package" ]
  assert_output_contains "unexpected checksum length: 29 (checksum_of_unexpected_length)"
  assert_output_contains "expected 0 (no checksum), 32 (MD5), or 64 (SHA2-256)"
}