Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
ruby-build
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ruby-build
Commits
8ea265d2
Commit
8ea265d2
authored
Jan 20, 2016
by
Mislav Marohnić
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #887 from jasonkarns/checksum-refactor
Checksum refactor
parents
6bdc16c0
af49837c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
35 deletions
+42
-35
bin/ruby-build
+28
-26
test/cache.bats
+0
-6
test/checksum.bats
+13
-2
test/fixtures/definitions/with-invalid-checksum
+1
-1
No files found.
bin/ruby-build
View file @
8ea265d2
...
@@ -246,24 +246,39 @@ compute_md5() {
...
@@ -246,24 +246,39 @@ compute_md5() {
fi
fi
}
}
has_checksum_support
()
{
local
checksum_command
=
"
$1
"
local
has_checksum_var
=
"HAS_CHECKSUM_SUPPORT_
${
checksum_command
}
"
if
[
-z
"
${
!has_checksum_var+defined
}
"
]
;
then
printf
-v
"
$has_checksum_var
"
"
$(
echo test
|
"
$checksum_command
"
>
/dev/null
;
echo
$?
)
"
fi
return
"
${
!has_checksum_var
}
"
}
verify_checksum
()
{
verify_checksum
()
{
# If there's no SHA2 support, return success
local
checksum_command
[
-n
"
$HAS_SHA2_SUPPORT
"
]
||
return
0
local
filename
=
"
$1
"
local
checksum_command
=
"compute_sha2
"
local
expected_checksum
=
"
$(
echo
"
$2
"
| tr
[
A-Z]
[
a-z]
)
"
# If the specified filename doesn't exist, return success
# If the specified filename doesn't exist, return success
local
filename
=
"
$1
"
[
-e
"
$filename
"
]
||
return
0
[
-e
"
$filename
"
]
||
return
0
# If there's no expected checksum, return success
case
"
${#
expected_checksum
}
"
in
local
expected_checksum
=
`
echo
"
$2
"
| tr
[
A-Z]
[
a-z]
`
0
)
return
0
;;
# empty checksum; return success
[
-n
"
$expected_checksum
"
]
||
return
0
32
)
checksum_command
=
"compute_md5"
;;
64
)
checksum_command
=
"compute_sha2"
;;
*
)
{
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 the checksum length is 32 chars, assume MD5, otherwise SHA2
# If chosen provided checksum algorithm isn't supported, return success
if
[
"
${#
expected_checksum
}
"
-eq
32
]
;
then
has_checksum_support
"
$checksum_command
"
||
return
0
[
-n
"
$HAS_MD5_SUPPORT
"
]
||
return
0
checksum_command
=
"compute_md5"
fi
# If the computed checksum is empty, return failure
# If the computed checksum is empty, return failure
local
computed_checksum
=
`
echo
"
$(
$checksum_command
<
"
$filename
"
)
"
| tr
[
A-Z]
[
a-z]
`
local
computed_checksum
=
`
echo
"
$(
$checksum_command
<
"
$filename
"
)
"
| tr
[
A-Z]
[
a-z]
`
...
@@ -1219,23 +1234,10 @@ else
...
@@ -1219,23 +1234,10 @@ else
RUBY_BUILD_DEFAULT_MIRROR
=
RUBY_BUILD_DEFAULT_MIRROR
=
fi
fi
if
[
-n
"
$RUBY_BUILD_SKIP_MIRROR
"
]
;
then
if
[
-n
"
$RUBY_BUILD_SKIP_MIRROR
"
]
||
!
has_checksum_support compute_sha2
;
then
unset
RUBY_BUILD_MIRROR_URL
unset
RUBY_BUILD_MIRROR_URL
fi
fi
if
echo test
| compute_sha2
>
/dev/null
;
then
HAS_SHA2_SUPPORT
=
1
else
unset
HAS_SHA2_SUPPORT
unset
RUBY_BUILD_MIRROR_URL
fi
if
echo test
| compute_md5
>
/dev/null
;
then
HAS_MD5_SUPPORT
=
1
else
unset
HAS_MD5_SUPPORT
fi
SEED
=
"
$(
date
"+%Y%m%d%H%M%S"
)
.
$$
"
SEED
=
"
$(
date
"+%Y%m%d%H%M%S"
)
.
$$
"
LOG_PATH
=
"
${
TMP
}
/ruby-build.
${
SEED
}
.log"
LOG_PATH
=
"
${
TMP
}
/ruby-build.
${
SEED
}
.log"
RUBY_BIN
=
"
${
PREFIX_PATH
}
/bin/ruby"
RUBY_BIN
=
"
${
PREFIX_PATH
}
/bin/ruby"
...
...
test/cache.bats
View file @
8ea265d2
...
@@ -10,7 +10,6 @@ setup() {
...
@@ -10,7 +10,6 @@ setup() {
@test "packages are saved to download cache" {
@test "packages are saved to download cache" {
stub shasum true
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/without-checksum
install_fixture definitions/without-checksum
...
@@ -19,12 +18,10 @@ setup() {
...
@@ -19,12 +18,10 @@ setup() {
[ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
[ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
unstub curl
unstub curl
unstub shasum
}
}
@test "cached package without checksum" {
@test "cached package without checksum" {
stub shasum true
stub curl
stub curl
cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH"
cp "${FIXTURE_ROOT}/package-1.0.0.tar.gz" "$RUBY_BUILD_CACHE_PATH"
...
@@ -35,7 +32,6 @@ setup() {
...
@@ -35,7 +32,6 @@ setup() {
[ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
[ -e "${RUBY_BUILD_CACHE_PATH}/package-1.0.0.tar.gz" ]
unstub curl
unstub curl
unstub shasum
}
}
...
@@ -79,7 +75,6 @@ setup() {
...
@@ -79,7 +75,6 @@ setup() {
@test "nonexistent cache directory is ignored" {
@test "nonexistent cache directory is ignored" {
stub shasum true
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
export RUBY_BUILD_CACHE_PATH="${TMP}/nonexistent"
export RUBY_BUILD_CACHE_PATH="${TMP}/nonexistent"
...
@@ -91,5 +86,4 @@ setup() {
...
@@ -91,5 +86,4 @@ setup() {
[ ! -d "$RUBY_BUILD_CACHE_PATH" ]
[ ! -d "$RUBY_BUILD_CACHE_PATH" ]
unstub curl
unstub curl
unstub shasum
}
}
test/checksum.bats
View file @
8ea265d2
...
@@ -6,7 +6,6 @@ export RUBY_BUILD_CACHE_PATH=
...
@@ -6,7 +6,6 @@ export RUBY_BUILD_CACHE_PATH=
@test "package URL without checksum" {
@test "package URL without checksum" {
stub shasum true
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
stub curl "-q -o * -*S* http://example.com/* : cp $FIXTURE_ROOT/\${5##*/} \$3"
install_fixture definitions/without-checksum
install_fixture definitions/without-checksum
...
@@ -14,7 +13,6 @@ export RUBY_BUILD_CACHE_PATH=
...
@@ -14,7 +13,6 @@ export RUBY_BUILD_CACHE_PATH=
[ -x "${INSTALL_ROOT}/bin/package" ]
[ -x "${INSTALL_ROOT}/bin/package" ]
unstub curl
unstub curl
unstub shasum
}
}
...
@@ -143,3 +141,16 @@ DEF
...
@@ -143,3 +141,16 @@ DEF
unstub shasum
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)"
}
test/fixtures/definitions/with-invalid-checksum
View file @
8ea265d2
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#invalid" copy
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz#invalid
_64_character_checksum_0000000000000000000000000000000000
" copy
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment