This commit is contained in:
root
2017-02-26 00:07:07 +01:00
parent 0df597b47d
commit 74c3c310e6
21 changed files with 2494 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
#! /bin/bash
cat <<---
This test checks that the built Nginx either has the dynamic fancyindex
module available, or that it's not there (for static builds).
--
readonly nginx_path="${PREFIX}/sbin/nginx"
readonly so_path="${PREFIX}/modules/ngx_http_fancyindex_module.so"
if [[ ! -x ${nginx_path} ]] ; then
fail "executable binary not found at '%s'\n" "${nginx_path}"
fi
if ${DYNAMIC} ; then
if [[ ! -r ${so_path} ]] ; then
fail "module not found at '%s'\n" "${so_path}"
fi
else
if [[ -r ${so_path} ]] ; then
fail "module should not exist at '%s'\n" "${so_path}"
fi
fi

View File

@@ -0,0 +1,7 @@
#! /bin/bash
cat <<---
This test fetches the root directory served by Nginx, which has no index file,
and checks that the output contains something that resembles a directory index.
--
nginx_start
grep 'Index of' <( fetch )

View File

@@ -0,0 +1,11 @@
#! /bin/bash
cat <<---
This test fetches the root directory served by Nginx, which has no index file,
and checks that the output contains something that resembles the output from
the fancyindex module.
--
nginx_start
content=$(fetch --with-headers)
grep 'Index of /' <<< "${content}" # It is an index
grep '\<table\>' <<< "${content}" # It contains a table
grep '^ Content-Type:[[:space:]]*text/html' <<< "${content}"

25
ngx-fancyindex/t/build-and-run Executable file
View File

@@ -0,0 +1,25 @@
#! /bin/bash
set -e
if [[ $# -lt 1 || $# -gt 2 ]] ; then
echo "Usage: $0 <nginx-version> [1]" 1>&2
exit 1
fi
readonly NGINX=$1
if [[ $2 -eq 1 ]] ; then
readonly DYNAMIC=$2
fi
cd "$(dirname "$0")/.."
wget -O - http://nginx.org/download/nginx-${NGINX}.tar.gz | tar -xzf -
rm -rf prefix/
cd nginx-${NGINX}
./configure \
--add-${DYNAMIC:+dynamic-}module=.. \
--with-http_addition_module \
--prefix="$(pwd)/../prefix"
make install
cd ..
exec ./t/run prefix ${DYNAMIC}

View File

@@ -0,0 +1,7 @@
#! /bin/bash
cat <<---
This test ensures that the "index.html" is returned instead of a directory
listing when fetching a directory which contains an index file.
--
nginx_start
diff -u "${TESTDIR}/has-index/index.html" <( fetch /has-index/ ) 1>&2

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Index file test</title>
</head>
<body>
This is <code>index.html</code>.
</body>
</html>

View File

@@ -0,0 +1,25 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

84
ngx-fancyindex/t/preamble Normal file
View File

@@ -0,0 +1,84 @@
#! /bin/bash
#
# preamble
# Copyright (C) 2016 Adrian Perez <aperez@igalia.com>
#
# Distributed under terms of the MIT license.
#
function nginx_conf_generate () {
if ${DYNAMIC} ; then
echo 'load_module modules/ngx_http_fancyindex_module.so;'
fi
cat <<-EOF
worker_processes 1;
events { worker_connections 1024; }
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
server_name localhost;
listen 127.0.0.1:8888;
root ${TESTDIR};
error_page 500 502 503 504 /50x.html;
location = /50x.html { root html; }
location / {
index index.html;
fancyindex on;
$*
}
}
}
EOF
}
readonly NGINX_CONF="${PREFIX}/conf/nginx.conf"
readonly NGINX_PID="${PREFIX}/logs/nginx.pid"
rm -f "${NGINX_CONF}" "${NGINX_PID}"
mkdir -p "${PREFIX}/logs"
function nginx () {
env - PATH="${PATH}" "${PREFIX}/sbin/nginx" "$@"
}
function nginx_conf () {
nginx_conf_generate "$@" > "${NGINX_CONF}"
}
function nginx_is_running () {
[[ -r ${NGINX_PID} ]] && kill -0 $(< "${NGINX_PID}")
}
function nginx_stop () {
if nginx_is_running ; then nginx -s stop ; fi
rm -f "${NGINX_PID}"
}
trap nginx_stop EXIT
function nginx_start () {
if [[ $# -gt 0 || ! -r ${NGINX_CONF} ]] ; then nginx_conf "$@" ; fi
nginx_stop # Ensure that it is not running.
nginx
}
function fetch () {
local -a opts=( -q )
if [[ $1 = --with-headers ]] ; then
opts+=( -S )
shift
fi
wget "${opts[@]}" -O- "http://localhost:8888${1:-/}" 2>&1
}
function fail () {
printf "(FF) "
printf "$@"
exit 1
} 1>&2
function warn () {
printf "(WW)"
printf "$@"
} 1>&2

67
ngx-fancyindex/t/run Executable file
View File

@@ -0,0 +1,67 @@
#! /bin/bash
set -e
if [[ $# -lt 1 || $# -gt 2 ]] ; then
echo "Usage: $0 <prefix-path> [1]" 1>&2
exit 1
fi
# Obtain the absolute path to the tests directory
pushd "$(dirname "$0")" &> /dev/null
readonly T=$(pwd)
popd &> /dev/null
export T
# Same for the nginx prefix directory
pushd "$1" &> /dev/null
readonly prefix=$(pwd)
popd &> /dev/null
dynamic=false
if [[ $# -gt 1 && $2 -eq 1 ]] ; then
dynamic=true
fi
readonly dynamic
declare -a t_pass=( )
declare -a t_fail=( )
for t in "$T"/*.test ; do
name="t/${t##*/}"
name=${name%.test}
printf "${name} ... "
errfile="${name}.err"
outfile="${name}.out"
shfile="${name}.sh"
cat > "${shfile}" <<-EOF
readonly DYNAMIC=${dynamic}
readonly TESTDIR='$T'
readonly PREFIX='${prefix}'
$(< "$T/preamble")
$(< "$t")
EOF
if bash -e "${shfile}" > "${outfile}" 2> "${errfile}" ; then
t_pass+=( "${name}" )
printf 'passed\n'
else
t_fail+=( "${name}" )
printf 'failed\n'
fi
done
for name in "${t_fail[@]}" ; do
echo
printf '=== %s.out\n' "${name}"
cat "${name}.out"
echo
printf '=== %s.err\n' "${name}"
cat "${name}.err"
echo
done
printf '=== passed/failed/total: %d/%d/%d\n' \
${#t_pass[@]} ${#t_fail[@]} $(( ${#t_pass[@]} + ${#t_fail[@]} ))
if [[ ${#t_fail[@]} -gt 0 ]] ; then
exit 1
fi