13.10. Command Line Testing

A CGI.pm program is easily tested from the command line; as soon as the program calls a CGI method or creates a CGI object it will prompt

(offline mode: enter name=value pairs on standard input)

and you can then type a series of lines like:

address="742 Evergreen Terrace"
phone=555-8707

End them with whatever character signals end-of-input to your current shell. The inputs you cannot provide this way are

  • File uploads.

  • Cookies: You can pass them by setting the environment variable HTTP_COOKIE to the name of the cookie followed by an = sign and the value of the cookie.

  • User authentication: Set the REMOTE_USER environment variable to the name of the authenticated user. A Web server will not pass the password the user typed to your program anyway.

If your program does something different when you run it from the command line than when you run it through a browser, here are the things to check:

  • Path: These are probably different. Set $ENV{PATH} explicitly in your program to satisfy taint mode.

  • Current directory: The Web server may set this to something other than the directory the program is located in. Use absolute paths for filenames for input and output, or chdir to absolute paths first.

  • Cookies: Try disabling these in your browser to see if it makes a difference, or use something like our proxylog tool to see what cookie transactions take place over the Web.

  • Permissions and ownerships: Does your program read any files that are inaccessible to the UID the Web server process runs under? Does your program modify any files outside of scratch directories? If so, bear in mind that the Web server process UID has very little authority (hopefully). You'll need to give write permission to that UID for anything like this.

  • Environment: There may be some environment variable set only in your command line shell (like LD_LIBRARY_PATH) that modifies the behavior of programs executed by your program. Compare all your environment variables with the ones reported by cgi-test.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset