--- /dev/null
+Monkey QA Test scripts
+======================
+This QA test script package has been written by
+Carlos Ghan (charly.brown.uy@gmail.com).
+
+In order to run this test you will need the
+HTTP Test Tool installed in your system, you can
+get the latest version from http://htt.sf.net/
+
+Running the tests
+=================
+To run all tests:
+ ./run-tests.sh
+
+[Variables in run-tests.sh]
+CONFIG_FILE Server parameters file
+LOGFILE Log errors to this file
+STOP_AT_ERRORS Stop at first error
+WITH_COLOR Enable/Disable color in output
--- /dev/null
+################################################################################
+# DESCRIPTION
+# Test description
+#
+# AUTHOR
+# Author Name <author@email.here>
+#
+# DATE
+# Month_text Day_number Year_number
+#
+# COMMENTS
+# Anything pertinent.
+###############################################################################
+
+
+INCLUDE __CONFIG
+
+CLIENT
+_REQ $HOST $PORT
+__GET / $HTTPVER
+__Host: $HOST
+__Connection: close
+__
+_EXPECT . "HTTP/1.1 200 OK"
+_WAIT
+END
--- /dev/null
+# Global server settings
+SET PORT=2001
+SET HOST=localhost
+SET HTTPVER=HTTP/1.1
+_LOG_LEVEL 4
--- /dev/null
+Global Commands
+---------------
+BLOCK <name>
+Store a block of commands to call it from a CLIENT/SERVER/BLOCK
+
+CLIENT [<number of concurrent clients>]
+Client body start, close it with END and a newline
+
+DAEMON
+Daemon body start, close it with END and a newline.
+A daemon will not join CLIENT/SERVER and could therefore be used
+for supervisor jobs
+
+END
+Close CLIENT|SERVER body
+
+EXEC <shell command>
+Execute a shell command, attention executes will not join CLIENT/SERVER
+
+GO
+Starts all client in sync mode
+
+INCLUDE <include file>
+Load and execute defined include file,
+current path is taken the callers current path
+
+SERVER [<SSL>:]<port> [<number of concurrent servers>]
+Server body start, close it with END and a newline,
+Do load server.cert.pem and server.key.pem if found in local directory,
+number of concurrent servers, -1 for unlimited,
+<SSL>: SSL, SSL2, SSL3, TLS
+
+SET <variable>=<value>
+Store a value in a global variable
+
+TIMEOUT <timeout in ms>
+Defines global socket timeout
+
+
+Local Commands
+-------------
+-__ <string>
+Send <string> to the socket with a CRLF at the end of line
+
+_- <string>
+Same like __ but no CRLF at the end of line
+
+_ADD_HEADER <header> <value>
+Add additional header to received headers to force forexample chunked encoding
+
+_BPS <n>
+Send not more than defined Bytes per second
+close body with _END BPS
+
+_CALL <name of block>
+Call a defined block
+
+_CERT <cert-file> <key-file> [<ca-cert-file>]
+Sets cert for the current ssl connection, mainly used for server cert
+
+_CHUNK
+Mark the end of a chunk block, all data after last _FLUSH are counted,
+does automatic add chunk info
+
+_CLOSE
+Close the current connection and set the connection state to CLOSED
+
+_DEBUG <string>
+Prints to stderr for debugging reasons
+
+_DOWN
+Shutdown listener
+
+_EXEC <shell command>
+Execute a shell command, _EXEC| will pipe the incoming stream on the
+socket in to the called shell command
+
+_EXIT [OK|FAILED]
+Exits with OK or FAILED default is FAILED
+
+_EXPECT . "[!]<regex>"
+Define what data we do or do not expect on a WAIT command.
+Negation with a leading '!' in the <regex>
+
+_FLUSH
+Flush the cached lines,
+the AUTO Content-Length calculation will take place here
+
+_HEADER ALLOW|FILTER <header name>
+Defines allowed headers or headers to filter,
+default all headers are allowed and no headers are filtered.
+Filter only for receive mechanisme
+
+_IF "<expression>" MATCH "[!]<regex>"
+Test if variable do or do not match the regex, close body with _END IF,
+negation with a leading '!' in the <regex>,
+<expression> must not be empty
+
+_IGNORE_ERR <regex>
+This command is Depreciated, do not use it
+Ignores errors specified in <regex>,
+i.e. ".*" would ignore all errors, only .* is implemented
+
+_LOG_LEVEL <level>
+Level is a number 0-4
+
+_LOOP <n>
+Do loop the body <n> times,
+close body with _END LOOP
+
+_MATCH (headers|body|error) "<regex>" <variable>
+Define a regex with a match which should be stored in <variable>
+
+_MATCH EXEC "<regex>" <variable>
+_EXEC algun_comando
+(No documentado; aparece en los ejemplos de la página web)
+Hace lo mismo que _MATCH pero con la salida del comando ejecutado en _EXEC
+
+_ONLY_PRINTABLE on|off
+Replace all chars below 32 and above 127 with a space
+
+_OP <left> ADD|SUB|DIV|MUL <right> <variable>
+Store evaluated expression
+
+_PIPE [chunked [<chunk_size>]]
+Start a pipe for stream the output of EXEC to the socket stream,
+wiht optional chunk support
+
+_RAND <start> <end>
+Generates a number between <start> and <end>
+
+_RECV <bytes>|POLL
+Receive an amount of bytes, either specified by a number
+or as much until socket timeout will in POLL mode
+
+_REQ <host> [<SSL>:]<port>[:<tag>] [<cert-file> <key-file> [<ca-cert-file>]]
+Start a request to defined host:port, with SSL support.
+Does only open a new connection if we are in connection state CLOSED
+<SSL>: SSL, SSL2, SSL3, TLS<tag>:Additional tag info do support multiple connection to one target
+<cert-file>, <key-file> and <ca-cert-file> are optional for client/server authentication
+
+_RES
+Wait for a connection accept
+
+_SENDFILE <file>
+Send file over http
+
+_SET <variable>=<value>
+Store a value in a local variable
+
+_SH shell script line or END
+Embedded shell script within a tmp file, execute if END is found
+
+_SLEEP <milisecond>
+Sleep for defined amount of time
+
+_SOCKSTATE <variable>
+Stores connection state CLOSED or CONNECTED in the <variable>
+
+_SYNC
+Synchronise to the next full second
+
+_TIME <variable>
+Store time in variable [ms]
+
+_TIMEOUT <miliseconds>
+Set socket timeout of current socket
+
+_UP
+Setup listener
+
+_VERIFY_PEER
+Gets peer cert and validate it
+
+_WAIT [<amount of bytes>]
+Wait for data and receive them.
+EXPECT and MATCH definitions will be checked here on the incoming data.
+Optional you could receive a specific amount of bytes
+
+_WHICH <variable>
+Stores the concurrency number of current thread
--- /dev/null
+################################################################################
+# DESCRIPTION
+# Exercise error 400
+#
+# AUTHOR
+# Carlos Ghan <charlie.brown.uy@gmail.com>
+#
+# DATE
+# June 29 2009
+#
+# COMMENTS
+# Sending a bad request. In this case, one with missing "Host" header.
+# ("Host" header is required in HTTP v1.1)
+################################################################################
+
+
+INCLUDE __CONFIG
+
+CLIENT
+_REQ $HOST $PORT
+__GET / $HTTPVER
+__Connection: close
+__
+_EXPECT . "HTTP/1.1 400 Bad Request"
+_WAIT
+END
--- /dev/null
+################################################################################
+# DESCRIPTION
+# Exercise error 404
+#
+# AUTHOR
+# Carlos Ghan <charlie.brown.uy@gmail.com>
+#
+# DATE
+# June 29 2009
+#
+# COMMENTS
+# Requesting an inexistent object should return "Not Found"
+################################################################################
+
+
+INCLUDE __CONFIG
+
+CLIENT
+_REQ $HOST $PORT
+__GET /a_file_that_doesnt_exists.html $HTTPVER
+__Host: $HOST
+__Connection: close
+__
+_EXPECT . "HTTP/1.1 404 Not Found"
+_WAIT
+END
--- /dev/null
+################################################################################
+# DESCRIPTION
+# Exercise error 411
+#
+# AUTHOR
+# Carlos Ghan <charlie.brown.uy@gmail.com>
+#
+# DATE
+# June 29 2009
+#
+# COMMENTS
+# A POST request without "Content-Length" should return "Length Required"
+################################################################################
+
+
+INCLUDE __CONFIG
+
+CLIENT
+_REQ $HOST $PORT
+__POST / $HTTPVER
+__Host: $HOST
+__Connection: close
+__
+_EXPECT . "HTTP/1.1 411 Length Required"
+_WAIT
+END
--- /dev/null
+################################################################################
+# DESCRIPTION
+# Exercise error 501
+#
+# AUTHOR
+# Carlos Ghan <charlie.brown.uy@gmail.com>
+#
+# DATE
+# June 29 2009
+#
+# COMMENTS
+# Requesting an unsupported method should return "Not Implemented"
+################################################################################
+
+
+INCLUDE __CONFIG
+
+CLIENT
+_REQ $HOST $PORT
+__1234 / $HTTPVER
+__Host: $HOST
+__Connection: close
+__
+_EXPECT . "HTTP/1.1 501 Not Implemented"
+_WAIT
+END
--- /dev/null
+################################################################################
+# DESCRIPTION
+# Exercise error 505
+#
+# AUTHOR
+# Carlos Ghan <charlie.brown.uy@gmail.com>
+#
+# DATE
+# June 29 2009
+#
+# COMMENTS
+# Requesting an unsupported HTTP version should return "HTTP Version Not
+# Supported"
+################################################################################
+
+
+INCLUDE __CONFIG
+
+CLIENT
+_REQ $HOST $PORT
+__GET / HTTP/1.9
+__Host: $HOST
+__Connection: close
+__
+_EXPECT . "HTTP/1.1 505 HTTP Version Not Supported"
+_WAIT
+END
--- /dev/null
+################################################################################
+# DESCRIPTION
+# HEAD method.
+#
+# AUTHOR
+# Carlos Ghan <charlie.brown.uy@gmail.com>
+#
+# DATE
+# June 29 2009
+################################################################################
+
+
+INCLUDE __CONFIG
+
+CLIENT
+_REQ $HOST $PORT
+__HEAD / $HTTPVER
+__Host: $HOST
+__Connection: close
+__
+_EXPECT . "HTTP/1.1 200 OK"
+_WAIT 0
+END
--- /dev/null
+################################################################################
+# DESCRIPTION
+# Test that headers are treated as case insensitive. (RFC2616 Section 4.2)
+#
+# AUTHOR
+# Carlos Ghan <charlie.brown.uy@gmail.com>
+#
+# DATE
+# June 29 2009
+################################################################################
+
+
+INCLUDE __CONFIG
+CLIENT
+_REQ $HOST $PORT
+__GET / $HTTPVER
+__HOST: $HOST
+__CONNECTION: close
+__
+_EXPECT . "HTTP/1.1 200 OK"
+_WAIT
+_CLOSE
+
+_REQ $HOST $PORT
+__POST / $HTTPVER
+__HOST: $HOST
+__CONNECTION: close
+__CONTENT_TYPE: text/plain
+__CONTENT_LENGTH: AUTO
+__
+_-This is a test entity body.
+END
--- /dev/null
+################################################################################
+# DESCRIPTION
+# POST method.
+#
+# AUTHOR
+# Carlos Ghan <charlie.brown.uy@gmail.com>
+#
+# DATE
+# June 29 2009
+###############################################################################
+
+
+INCLUDE __CONFIG
+
+CLIENT
+_REQ $HOST $PORT
+__POST / $HTTPVER
+__Host: $HOST
+__Content-Type: text/plain
+__Content-Length: AUTO
+__Connection: close
+__
+_-someVariable=1234&daemon=monkeyd&SESSION=e1d83283d597ca88f599e34c8ef2e8c3
+_EXPECT . "HTTP/1.1 200 OK"
+_WAIT
+END
--- /dev/null
+################################################################################
+# DESCRIPTION
+# An incomplete POST request.
+#
+# AUTHOR
+# Carlos Ghan <charlie.brown.uy@gmail.com>
+#
+# DATE
+# June 29 2009
+#
+# COMMENTS
+# A POST request with missing Content-Length.(Should return "Length Required")
+################################################################################
+
+
+INCLUDE __CONFIG
+
+CLIENT
+_REQ $HOST $PORT
+__POST / $HTTPVER
+__Host: $HOST
+__Content-Type: text/plain
+__Connection: close
+__
+_-someVariable=1234&daemon=monkeyd&SESSION=e1d83283d597ca88f599e34c8ef2e8c3
+_EXPECT . "HTTP/1.1 411 Length Required"
+_WAIT
+END
--- /dev/null
+################################################################################
+# DESCRIPTION
+# A simple GET query.
+#
+# AUTHOR
+# Carlos Ghan <charlie.brown.uy@gmail.com>
+#
+# DATE
+# June 29 2009
+################################################################################
+
+
+INCLUDE __CONFIG
+
+SET QUERY=server=monkeyd&version=0.10git&someVariable=someValue&num=1234
+
+CLIENT
+_REQ $HOST $PORT
+__GET /?$QUERY $HTTPVER
+__Host: $HOST
+__Connection: close
+__
+_EXPECT . "HTTP/1.1 200 OK"
+_WAIT
+END
--- /dev/null
+################################################################################
+# DESCRIPTION
+# Test status = 301.
+#
+# AUTHOR
+# Carlos Ghan <charlie.brown.uy@gmail.com>
+#
+# DATE
+# June 29 2009
+#
+# COMMENTS
+# Request a directory without trailing '/' so that we get "Moved Permanently".
+################################################################################
+
+
+INCLUDE __CONFIG
+
+SET REDIR=imgs
+
+CLIENT
+_REQ $HOST $PORT
+__GET /$REDIR $HTTPVER
+__Host: $HOST
+__Connection: close
+__
+_EXPECT . "HTTP/1.1 301 Moved Permanently"
+_EXPECT . "Location: http://$HOST:$PORT/$REDIR/"
+_WAIT
+END
--- /dev/null
+#!/bin/sh
+TEST_FILES=`ls *.htt`
+TOTAL_TESTS=`echo $TEST_FILES | wc -w`
+
+# Server parameters file
+CONFIG_FILE='__CONFIG'
+
+LOGFILE='errors.log'
+
+# Clear log file
+:>$LOGFILE
+
+# Should we stop at the first error? (yes | no)
+STOP_AT_ERRORS=no
+
+# httest error code for 'Connection refused'
+CONN_REFUSED=111
+
+# Enable colors in output :) (yes | no)
+WITH_COLOR=yes
+
+# httest command
+HTTEST_CMD='httest'
+
+NTEST=1
+for test_file in $TEST_FILES; do
+# echo -ne "[TEST $NTEST/$TOTAL_TESTS]\t""case: $test_file\t\t"
+ printf "[%3d/%d] %-32s " $NTEST $TOTAL_TESTS "$test_file"
+
+ OUTPUT=`$HTTEST_CMD "$test_file" 2>&1`
+ ERRCODE=$?
+
+ case $ERRCODE in
+ 0)
+ [ $WITH_COLOR = yes ] && echo -n "\e[1;32m"
+ echo "=> [OK]"
+ [ $WITH_COLOR = yes ] && echo -n "\e[m"
+ ;;
+
+ $CONN_REFUSED)
+ echo
+ echo "Connection refused... (Is monkey running?)" >&2
+ exit $CONN_REFUSED
+ ;;
+
+ *)
+ [ $WITH_COLOR = yes ] && echo -n "\e[1;31m"
+ echo "=> [FAILED]"
+ [ $WITH_COLOR = yes ] && echo -n "\e[m"
+
+ perl -e 'print "-" x 78, "\n"' >>"$LOGFILE"
+ echo "$OUTPUT" >>"$LOGFILE"
+ perl -e 'print "-" x 78, "\n"' >>"$LOGFILE"
+
+ [ $STOP_AT_ERRORS = yes ] && exit 1
+ esac
+
+ NTEST=$((NTEST+1))
+done
--- /dev/null
+################################################################################
+# DESCRIPTION
+# The most basic request: GET /
+#
+# AUTHOR
+# Carlos Ghan <charlie.brown.uy@gmail.com>
+#
+# DATE
+# June 29 2009
+#
+# COMMENTS
+# This test shouldn't fail ;)
+################################################################################
+
+
+INCLUDE __CONFIG
+
+CLIENT
+_REQ $HOST $PORT
+__GET / $HTTPVER
+__Host: $HOST
+__Connection: close
+__
+_EXPECT . "HTTP/1.1 200 OK"
+_WAIT
+END