Ford & Mason Ltd
HOME
ABOUT
CONTACT
RESOURCES
ADVERTISING



donations support the development of
cronolog.org
and
refcards.com

next up previous contents index
Next: Security aspects Up: Testing dynamic documents Previous: Testing in isolation


Testing with the server

CGI scripts are generally invoked as the result of a request made by a browser when a user submits a form or follows a link in an HTML document. The request is accompanied by input data for the CGI script.

When testing a script that takes input from a form, or from a URL containing a query string, one of the first steps must be to determine the content of this input data. It is often helpful to substitute a debug script for the actual script, which returns a document that displays the input data. The following example shows a debug script written in Perl that does precisely that:

    #!/usr/local/bin/perl

# Script to output CGI Information

# Output the MIME headers and HTML document head

print("Content-Type: text/html\n\n"); print("<HEAD><TITLE>CGI Information Received</TITLE>\n"); print("</HEAD><BODY><H1>CGI Information Received</H1>\n");

# Output the values of environment variables

print("<H2>Environment Variables</H2>\n<DL COMPACT>\n"); foreach $var ("GATEWAY_INTERFACE", "REQUEST_METHOD", "CONTENT_TYPE", "CONTENT_LENGTH", "SCRIPT_NAME", "PATH_INFO", "PATH_TRANSLATED", "QUERY_STRING", "REMOTE_HOST", "REMOTE_ADDR", "REMOTE_USER", "REMOTE_IDENT", "SERVER_NAME", "SERVER_PORT", "SERVER_SOFTWARE", "SERVER_PROTOCOL", "AUTH_TYPE", "PATH") { print("<DT><B>$var</B><DD>$ENV{$var}\n") if $ENV{$var}; }

foreach $var (sort keys ENV) { print("<DT><B>$var</B><DD>$ENV{$var}\n") if $var = /^HTTP_/; } print("</DL>\n");

# Output any command line arguments

if ($#ARGV > 0) { print("<H2>Command Line Arguments</H2>\n"); foreach $i (1 .. $#ARGV) { printf("ARGv[$i]: s<BR>\n", $ARGV[$i]); } }

# Output any data on the standard input stream

if ($ENV{CONTENT_LENGTH} ne "") { read(STDIN, $content, $ENV{CONTENT_LENGTH}); print("<H2>Data on Standard Input</H2>\n"); print("<PRE>$content</PRE>\n"); } print("</BODY>");

Testing with the server can be partially automated by using command line clients: programs that will retrieve a document specified by a URL given on the command line.


next up previous contents index
Next: Security aspects Up: Testing dynamic documents Previous: Testing in isolation

[ITCP]Spinning the Web by Andrew Ford
© 1995 International Thomson Publishing
© 2002 Andrew Ford and Ford & Mason Ltd
Note: this HTML document was generated in December 1994 directly from the LaTeX source files using LaTeX2HTML. It was formatted into our standard page layout using the Template Toolkit. The document is mainly of historical interest as obviously many of the sites mentioned have long since disappeared.

 
Copyright © 1996-2002 Ford & Mason Ltd