CoderZone.org
Pages: 1 « previous     next »
  Print  
Author Topic: bash / curl Automated web interface testing with authentication  (Read 12377 times) Bookmark and Share
wheels
Jr. Member
*****
Posts: 62



View Profile
« on: Dec 07, 2010, 07:28:39 am »

This is a simple bash script that uses curl to authenticate into a web interface and then request pages.  It could serve as a very basic sanity test to ensure authentication works and all the pages load without error, or it could be used as the foundation for a more sophisticated test tool.

Code:  
Highlight Mode: (Bash)
  1. # Display constants
  2. esc=`echo e | tr e '\033'`
  3. REVERSE="${esc}[7m"
  4. UNDERLINE="${esc}[4m"
  5. BOLD="${esc}[1m"
  6. BOLD_UNDERLINE="${esc}[1;4m"
  7. RESET="${esc}[0m"
  8. TAB='-e \t'
  9.  
  10. # Default target URL
  11. TARGET=https://domain.com/
  12.  
  13. # Common curl options
  14. CURL_OPTS='-A AutoTest -L -k -s'
  15. COOKIE_OUT='-c cookie'
  16. COOKIE_IN='-b cookie'
  17.  
  18. # Application specific options
  19. JSON='-F sRequestType=json'
  20.  
  21. # Data settings
  22. ID=1
  23.  
  24. # Error detection
  25. ERROR_CHECK='grep -i error'
  26. LOGGED_IN="grep -o bLoggedIn=false"
  27.  
  28. for admin in admin editor
  29. do
  30.      echo $BOLD$admin$RESET Tests
  31.  
  32.      echo Logging in
  33.      LOGIN_RESULT=`curl $CURL_OPTS $COOKIE_OUT -F sUsername=$admin -F sPassword=$admin $TARGET/home.php | $LOGGED_IN`
  34.      if [ -z $LOGIN_RESULT ]
  35.      then
  36.        PAGES='users report system account'
  37.  
  38.        echo "$BOLD_UNDERLINE"Page Load Test$RESET
  39.        for page in $PAGES
  40.        do
  41.                echo $TAB$page
  42.                curl $CURL_OPTS $COOKIE_IN $TARGET/$page.php > /dev/nul
  43.                # Test page content here
  44.        done
  45.        echo Logging out
  46.        curl $CURL_OPTS $COOKIE_IN $TARGET/logout.php > /dev/nul
  47.      else
  48.        echo "$BOLD"Login FAILED$RESET
  49.      fi
  50.      echo $BOLD$admin$RESET End test
  51.      echo
  52. done
 
Logged
Tags:
Pages: 1
  Print  
 
Jump to: