1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
#!/usr/bin/env bats
load test_helper
export RUBY_BUILD_SKIP_MIRROR=1
export RUBY_BUILD_CACHE_PATH=
@test "package URL without checksum" {
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/without-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
}
@test "package URL with valid checksum" {
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub shasum
}
@test "package URL with invalid checksum" {
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-invalid-checksum
assert_failure
refute [ -f "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub shasum
}
@test "package URL with checksum but no shasum support" {
stub shasum false
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub shasum
}
@test "package URL with valid md5 checksum" {
stub md5 true "echo 83e6d7725e20166024a1eb74cde80677"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-md5-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub md5
}
@test "package URL with md5 checksum but no md5 support" {
stub md5 false
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-md5-checksum
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub md5
}
@test "package with invalid checksum" {
stub shasum true "echo invalid"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/with-checksum
assert_failure
refute [ -f "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub shasum
}
@test "existing tarball in build location is reused" {
stub shasum true "echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub curl false
stub wget false
export -n RUBY_BUILD_CACHE_PATH
export RUBY_BUILD_BUILD_PATH="${TMP}/build"
mkdir -p "$RUBY_BUILD_BUILD_PATH"
ln -s "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_BUILD_PATH"
run_inline_definition <<DEF
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" copy
DEF
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
unstub shasum
}
@test "existing tarball in build location is discarded if not matching checksum" {
stub shasum true \
"echo invalid" \
"echo ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
export -n RUBY_BUILD_CACHE_PATH
export RUBY_BUILD_BUILD_PATH="${TMP}/build"
mkdir -p "$RUBY_BUILD_BUILD_PATH"
touch "${RUBY_BUILD_BUILD_PATH}/package-1.0.0.tar.gz"
run_inline_definition <<DEF
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#ba988b1bb4250dee0b9dd3d4d722f9c64b2bacfc805d1b6eba7426bda72dd3c5" copy
DEF
assert_success
assert [ -x "${INSTALL_ROOT}/bin/package" ]
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
refute [ -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)"
}
|