QA package
authorCarlos Ghan <charlie.brown.uy@gmail.com>
Wed, 25 Nov 2009 12:57:54 +0000 (09:57 -0300)
committerEduardo Silva <edsiper@gmail.com>
Wed, 25 Nov 2009 12:57:54 +0000 (09:57 -0300)
17 files changed:
qa/README.txt [new file with mode: 0644]
qa/TEMPLATE [new file with mode: 0644]
qa/__CONFIG [new file with mode: 0644]
qa/docs_httest.txt [new file with mode: 0644]
qa/error_400_test01.htt [new file with mode: 0644]
qa/error_404.htt [new file with mode: 0644]
qa/error_411.htt [new file with mode: 0644]
qa/error_501.htt [new file with mode: 0644]
qa/error_505.htt [new file with mode: 0644]
qa/head.htt [new file with mode: 0644]
qa/headers_case_insensitive.htt [new file with mode: 0644]
qa/post_test01.htt [new file with mode: 0644]
qa/post_test02.htt [new file with mode: 0644]
qa/query.htt [new file with mode: 0644]
qa/redir_301.htt [new file with mode: 0644]
qa/run_tests.sh [new file with mode: 0755]
qa/simple.htt [new file with mode: 0644]

diff --git a/qa/README.txt b/qa/README.txt
new file mode 100644 (file)
index 0000000..d82e7a2
--- /dev/null
@@ -0,0 +1,19 @@
+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
diff --git a/qa/TEMPLATE b/qa/TEMPLATE
new file mode 100644 (file)
index 0000000..e5d8b16
--- /dev/null
@@ -0,0 +1,26 @@
+################################################################################
+# 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
diff --git a/qa/__CONFIG b/qa/__CONFIG
new file mode 100644 (file)
index 0000000..af0b137
--- /dev/null
@@ -0,0 +1,5 @@
+# Global server settings
+SET PORT=2001
+SET HOST=localhost
+SET HTTPVER=HTTP/1.1
+_LOG_LEVEL 4
diff --git a/qa/docs_httest.txt b/qa/docs_httest.txt
new file mode 100644 (file)
index 0000000..07556c9
--- /dev/null
@@ -0,0 +1,181 @@
+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
diff --git a/qa/error_400_test01.htt b/qa/error_400_test01.htt
new file mode 100644 (file)
index 0000000..e6d7e7f
--- /dev/null
@@ -0,0 +1,26 @@
+################################################################################
+# 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
diff --git a/qa/error_404.htt b/qa/error_404.htt
new file mode 100644 (file)
index 0000000..2860048
--- /dev/null
@@ -0,0 +1,26 @@
+################################################################################
+# 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
diff --git a/qa/error_411.htt b/qa/error_411.htt
new file mode 100644 (file)
index 0000000..95c8d22
--- /dev/null
@@ -0,0 +1,26 @@
+################################################################################
+# 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
diff --git a/qa/error_501.htt b/qa/error_501.htt
new file mode 100644 (file)
index 0000000..275bca4
--- /dev/null
@@ -0,0 +1,26 @@
+################################################################################
+# 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
diff --git a/qa/error_505.htt b/qa/error_505.htt
new file mode 100644 (file)
index 0000000..f50fafe
--- /dev/null
@@ -0,0 +1,27 @@
+################################################################################
+# 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
diff --git a/qa/head.htt b/qa/head.htt
new file mode 100644 (file)
index 0000000..6956c47
--- /dev/null
@@ -0,0 +1,23 @@
+################################################################################
+# 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
diff --git a/qa/headers_case_insensitive.htt b/qa/headers_case_insensitive.htt
new file mode 100644 (file)
index 0000000..a8064d3
--- /dev/null
@@ -0,0 +1,32 @@
+################################################################################
+# 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
diff --git a/qa/post_test01.htt b/qa/post_test01.htt
new file mode 100644 (file)
index 0000000..856afdc
--- /dev/null
@@ -0,0 +1,26 @@
+################################################################################
+# 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
diff --git a/qa/post_test02.htt b/qa/post_test02.htt
new file mode 100644 (file)
index 0000000..79880e8
--- /dev/null
@@ -0,0 +1,28 @@
+################################################################################
+# 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
diff --git a/qa/query.htt b/qa/query.htt
new file mode 100644 (file)
index 0000000..eec3bd2
--- /dev/null
@@ -0,0 +1,25 @@
+################################################################################
+# 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
diff --git a/qa/redir_301.htt b/qa/redir_301.htt
new file mode 100644 (file)
index 0000000..396810a
--- /dev/null
@@ -0,0 +1,29 @@
+################################################################################
+# 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
diff --git a/qa/run_tests.sh b/qa/run_tests.sh
new file mode 100755 (executable)
index 0000000..2cebcc4
--- /dev/null
@@ -0,0 +1,59 @@
+#!/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
diff --git a/qa/simple.htt b/qa/simple.htt
new file mode 100644 (file)
index 0000000..a1538db
--- /dev/null
@@ -0,0 +1,26 @@
+################################################################################
+# 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