mirror of
https://github.com/SergioBenitez/Rocket.git
synced 2026-02-06 10:48:05 +00:00
Prior to this commit, it was not possible to test Rocket crates in production mode without setting a global secret key or bypassing secret key checking - the testing script did the latter. The consequence is that it became impossible to test secret key related failures because the tests passed regardless. This commit undoes this. As a consequence, all tests are now aware of the difference between debug and release configurations, the latter of which validates 'secret_key' by default. New 'Client::debug()' and 'Client::debug_with()' simplify creating an instance of 'Client' with configuration in debug mode to avoid undesired test failures. The summary of changes in this commit are: * Config 'secret_key' success and failure are now tested. * 'secret_key' validation was moved to pre-launch from 'Config:from()'. * 'Config::from()' only extracts the config. * Added 'Config::try_from()' for non-panicking extraction. * 'Config' now knows the profile it was extracted from. * The 'Config' provider sets a profile of 'Config.profile'. * 'Rocket', 'Client', 'Fairings', implement 'Debug'. * 'fairing::Info' implements 'Copy', 'Clone'. * 'Fairings' keeps track of, logs attach fairings. * 'Rocket::reconfigure()' was added to allow modifying a config. Internally, the testing script was refactored to properly test the codebase with the new changes. In particular, it no longer sets a rustc 'cfg' to avoid secret-key checking. Resolves #1543. Fixes #1564.
189 lines
4.4 KiB
Bash
Executable File
189 lines
4.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
# Brings in _ROOT, _DIR, _DIRS globals.
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
source "${SCRIPT_DIR}/config.sh"
|
|
|
|
# Add Cargo to PATH.
|
|
export PATH=${HOME}/.cargo/bin:${PATH}
|
|
export CARGO_INCREMENTAL=0
|
|
CARGO="cargo"
|
|
|
|
# Checks that the versions for Cargo projects $@ all match
|
|
function check_versions_match() {
|
|
local last_version=""
|
|
for dir in "${@}"; do
|
|
local cargo_toml="${dir}/Cargo.toml"
|
|
if ! [ -f "${cargo_toml}" ]; then
|
|
echo "Cargo configuration file '${cargo_toml}' does not exist."
|
|
exit 1
|
|
fi
|
|
|
|
local version=$(grep version "${cargo_toml}" | head -n 1 | cut -d' ' -f3)
|
|
if [ -z "${last_version}" ]; then
|
|
last_version="${version}"
|
|
elif ! [ "${version}" = "${last_version}" ]; then
|
|
echo "Versions differ in '${cargo_toml}'. ${version} != ${last_version}"
|
|
exit 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
# Ensures there are no tabs in any file.
|
|
function ensure_tab_free() {
|
|
local tab=$(printf '\t')
|
|
local matches=$(git grep -E -I "${tab}" "${PROJECT_ROOT}" | grep -v 'LICENSE')
|
|
if ! [ -z "${matches}" ]; then
|
|
echo "Tab characters were found in the following:"
|
|
echo "${matches}"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Ensures there are no files with trailing whitespace.
|
|
function ensure_trailing_whitespace_free() {
|
|
local matches=$(git grep -E -I "\s+$" "${PROJECT_ROOT}" | grep -v -F '.stderr:')
|
|
if ! [ -z "${matches}" ]; then
|
|
echo "Trailing whitespace was found in the following:"
|
|
echo "${matches}"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
function test_contrib() {
|
|
FEATURES=(
|
|
json
|
|
msgpack
|
|
tera_templates
|
|
handlebars_templates
|
|
serve
|
|
helmet
|
|
diesel_postgres_pool
|
|
diesel_sqlite_pool
|
|
diesel_mysql_pool
|
|
postgres_pool
|
|
mysql_pool
|
|
sqlite_pool
|
|
memcache_pool
|
|
brotli_compression
|
|
gzip_compression
|
|
)
|
|
|
|
echo ":: Building and testing contrib [default]..."
|
|
|
|
pushd "${CONTRIB_LIB_ROOT}" > /dev/null 2>&1
|
|
|
|
$CARGO test $@
|
|
|
|
for feature in "${FEATURES[@]}"; do
|
|
echo ":: Building and testing contrib [${feature}]..."
|
|
$CARGO test --no-default-features --features "${feature}" $@
|
|
done
|
|
|
|
popd > /dev/null 2>&1
|
|
}
|
|
|
|
function test_core() {
|
|
FEATURES=(
|
|
secrets
|
|
tls
|
|
)
|
|
|
|
pushd "${CORE_LIB_ROOT}" > /dev/null 2>&1
|
|
|
|
echo ":: Building and testing core [no features]..."
|
|
$CARGO test --no-default-features $@
|
|
|
|
for feature in "${FEATURES[@]}"; do
|
|
echo ":: Building and testing core [${feature}]..."
|
|
$CARGO test --no-default-features --features "${feature}" $@
|
|
done
|
|
|
|
popd > /dev/null 2>&1
|
|
}
|
|
|
|
function test_examples() {
|
|
for dir in $(find "${EXAMPLES_DIR}" -maxdepth 1 -mindepth 1 -type d); do
|
|
echo ":: Building and testing example [${dir#"${EXAMPLES_DIR}/"}]..."
|
|
|
|
pushd "${dir}" > /dev/null 2>&1
|
|
$CARGO test $@
|
|
popd > /dev/null 2>&1
|
|
done
|
|
}
|
|
|
|
function test_guide() {
|
|
echo ":: Building and testing guide..."
|
|
|
|
pushd "${GUIDE_TESTS_ROOT}" > /dev/null 2>&1
|
|
$CARGO test $@
|
|
popd > /dev/null 2>&1
|
|
}
|
|
|
|
function test_default() {
|
|
for project in "${ALL_PROJECT_DIRS[@]}"; do
|
|
echo ":: Building and testing ${project#"${PROJECT_ROOT}/"}..."
|
|
|
|
pushd "${project}" > /dev/null 2>&1
|
|
$CARGO test --all-features $@
|
|
popd > /dev/null 2>&1
|
|
done
|
|
}
|
|
|
|
if [[ $1 == +* ]]; then
|
|
CARGO="$CARGO $1"
|
|
shift
|
|
fi
|
|
|
|
# The kind of test we'll be running.
|
|
TEST_KIND="default"
|
|
KINDS=("contrib" "core" "examples" "guide" "all")
|
|
|
|
if [[ " ${KINDS[@]} " =~ " ${1#"--"} " ]]; then
|
|
TEST_KIND=${1#"--"}
|
|
shift
|
|
fi
|
|
|
|
echo ":: Preparing. Environment is..."
|
|
print_environment
|
|
echo " CARGO: $CARGO"
|
|
echo " EXTRA FLAGS: $@"
|
|
|
|
echo ":: Ensuring all crate versions match..."
|
|
check_versions_match "${ALL_PROJECT_DIRS[@]}"
|
|
|
|
echo ":: Checking for tabs..."
|
|
ensure_tab_free
|
|
|
|
echo ":: Checking for trailing whitespace..."
|
|
ensure_trailing_whitespace_free
|
|
|
|
echo ":: Updating dependencies..."
|
|
if ! $CARGO update ; then
|
|
echo " WARNING: Update failed! Proceeding with possibly outdated deps..."
|
|
fi
|
|
|
|
case $TEST_KIND in
|
|
contrib) test_contrib $@ ;;
|
|
core) test_core $@ ;;
|
|
examples) test_examples $@ ;;
|
|
guide) test_guide $@ ;;
|
|
default)
|
|
test_examples $@ & examples=$!
|
|
test_default $@ & default=$!
|
|
test_guide $@ & guide=$!
|
|
|
|
wait $examples && wait $default && wait $guide
|
|
;;
|
|
all)
|
|
test_core $@ & core=$!
|
|
test_contrib $@ & contrib=$!
|
|
test_examples $@ & examples=$!
|
|
test_default $@ & default=$!
|
|
test_guide $@ & guide=$!
|
|
|
|
wait $core && wait $contrib && wait $examples && wait $default && wait $guide
|
|
;;
|
|
esac
|