Skip to content

Commit

Permalink
fix for uploading compressed files and misc application types
Browse files Browse the repository at this point in the history
  • Loading branch information
Colas Nahaboo committed Dec 13, 2017
1 parent b4ca0c5 commit 6ffee34
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
7 changes: 5 additions & 2 deletions cgibashopts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ if [ "$REQUEST_METHOD" = POST ]; then
type=
read -r line
while [ -n "$line" ]; do
[[ $line =~ ^Content-Type:\ *application/octet-stream ]] && type=bin
[[ $line =~ ^Content-Type:\ *text/plain ]] && type=txt
if [[ $line =~ ^Content-Type:\ *text/plain ]]; then
type=txt
elif [[ $line =~ ^Content-Type: ]]; then # any other type
type=bin
fi
read -r line
done
if [ "$type" = bin ]; then # binary file upload
Expand Down
5 changes: 4 additions & 1 deletion test-suite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ Just run `RUN-ALL-TESTS.sh` to run all the tests silently. No output means every
- `form.test` replays saved data for test in POST mode
- `form-files.test` replays saved data for testing file uploads

`clearenv.sh` is a script to source before (or after) each test to clean all the results of an invocation of cgibashopts, to enable performing multiple tests in the same file.
`clearenv.sh` is a script to source before (or after) each test to clean all the results of an invocation of cgibashopts, to enable performing multiple tests in the same file.

## Manual tests
- **form-local/** tests manually the uploads of files through a real browser and web server on your local machine
8 changes: 8 additions & 0 deletions test-suite/form-local/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Local file upload interactive test
To use this test:
- copy cgibashopts-local.cgi and cgibashopts into a place in your local web server where .cgi files are executed as cgi
- place the various files to test the upload of in `/tmp`
- open cgibashopts-local.cgi in your browser, e.g: http://localhost/cgi-bin/cgibashopts-local.cgi
- upload them via the web page: On each upload of a file, the script will compare the uploaded copy to its source in /tmp and display the result

This is a (semi-)manual test, but exercising a real web server and browser.
50 changes: 50 additions & 0 deletions test-suite/form-local/cgibashopts-local.cgi
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
set -u
set -e
. cgibashopts

title="CGI BASH opts upload test on a local host"
header="Content-Type: text/html$nl$nl<html><head><title>$title</title>
</head><body><h1>$title</h1>"
footer=""

################################# Options
export data=/tmp/cgibashopts-formfiletest.data
err() { echo "***ERROR: $*" >&2; exit -1; }

################################# Code
main() {
echo "$header"
if [ -n "${FORM_file:-}" ]; then
src="/tmp/${FORM_file##*/}"
[ "$FORMFILES" = file ] || echo "<p>***Error, FORMFILES=$FORMFILES</p>"
if [ -e "$CGIBASHOPTS_DIR/file" ]; then
if [ -s "$CGIBASHOPTS_DIR/file" ]; then
if [ -s "$src" ]; then
if cmp -s "$src" "$CGIBASHOPTS_DIR/file"; then
echo "<p>Upload of $src successful</p>"
else
echo "<p>***Error, file uploaded differ</p>"
fi
else
echo "<p>***Error, src file empty</p>"
fi
else
echo "<p>***Error, file uploaded empty</p>"
fi
else
echo "<p>***Error no uploaded file!</p>"
fi
fi
form_page
}

form_page() {
echo "<form method=POST enctype='multipart/form-data'>
<br>File: <input type=file name=file size=32>
<br><input type=submit value=Upload>
</form>"
echo "$footer"
}

main

0 comments on commit 6ffee34

Please sign in to comment.