Refactor: define extract_http_header() in testdefs.sh

Also http_unquote_string()
This commit is contained in:
Andrew Bettison 2015-06-02 01:43:21 +09:30
parent 45c6b9ecfa
commit 858a7fc577
2 changed files with 20 additions and 18 deletions

View File

@ -533,6 +533,26 @@ assert_rhizome_received() {
done done
} }
# Extract a value from an HTTP header
extract_http_header() {
local __var="$1"
local __headerfile="$2"
local __header="$3"
local __rexp="$4"
local __value=$($SED -n -e "/^$__header:[ $HT]*$__rexp$CR\$/s/^$__header:[ $HT]*\(.*\)$CR\$/\1/p" "$__headerfile")
assert --message="$__headerfile contains valid '$__header' header" \
--dump-on-fail="$__headerfile" \
[ -n "$__value" ]
[ -n "$__var" ] && eval $__var=\"\$__value\"
}
# Parse an HTTP quoted-string
http_unquote_string() {
local __var="$1"
local __unq="$(eval echo '"${'$__var'}"' | sed -e 's/^"//' -e 's/"$//' -e 's/\\\(.\)/\1/g')"
eval $__var=\"\$__unq\"
}
rhizome_add_bundles() { rhizome_add_bundles() {
local encrypted=false local encrypted=false
case "$1" in case "$1" in

View File

@ -532,24 +532,6 @@ test_RhizomePayloadDecryptedNonexistPayload() {
assertJqGrep --ignore-case http.content '.rhizome_payload_status_message' "payload new to store" assertJqGrep --ignore-case http.content '.rhizome_payload_status_message' "payload new to store"
} }
extract_http_header() {
local __var="$1"
local __headerfile="$2"
local __header="$3"
local __rexp="$4"
local __value=$($SED -n -e "/^$__header:[ $HT]*$__rexp$CR\$/s/^$__header:[ $HT]*\(.*\)$CR\$/\1/p" "$__headerfile")
assert --message="$__headerfile contains valid '$__header' header" \
--dump-on-fail="$__headerfile" \
[ -n "$__value" ]
[ -n "$__var" ] && eval $__var=\"\$__value\"
}
http_unquote_string() {
local __var="$1"
local __unq="$(eval echo '"${'$__var'}"' | sed -e 's/^"//' -e 's/"$//' -e 's/\\\(.\)/\1/g')"
eval $__var=\"\$__unq\"
}
doc_RhizomeInsert="HTTP RESTful insert new Rhizome bundles" doc_RhizomeInsert="HTTP RESTful insert new Rhizome bundles"
setup_RhizomeInsert() { setup_RhizomeInsert() {
IDENTITY_COUNT=3 IDENTITY_COUNT=3