Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Removed Print in favour of proper logging
Browse files Browse the repository at this point in the history
  • Loading branch information
AutomatedTester committed May 20, 2011
1 parent 51d58eb commit fc33436
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions garmr.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
import httplib import httplib
import urllib2 import urllib2
from optparse import OptionParser from optparse import OptionParser
import logging


logging.basicConfig(format='%(asctime)s %(levelname)-8s %(message)s')
logger = logging.getLogger("Garmr")
logger.setLevel(logging.DEBUG)


class Reporter(object): class Reporter(object):
pass pass
Expand All @@ -18,23 +24,21 @@ def xframe_checks(self):
response = urllib2.urlopen(self.urls) response = urllib2.urlopen(self.urls)
response_headers = response.headers.headers response_headers = response.headers.headers
headers = self._clean_header(response_headers) headers = self._clean_header(response_headers)
print "Checking x-frame-options" logger.info("Checking x-frame-options")
try: try:
assert headers["x-frame-options"] == "DENY" or \ assert headers["x-frame-options"] == "DENY" or \
headers["x-frame-options"] == "SAMEORIGIN", \ headers["x-frame-options"] == "SAMEORIGIN", \
"x-frame-options were: %s" % headers["x-frame-options"] "x-frame-options were: %s" % headers["x-frame-options"]


print "x-frame-options were correct" logger.info("x-frame-options were correct")
except KeyError: except KeyError:
print "x-frame-options were not found in headers" logger.error("x-frame-options were not found in headers")
except AssertionError, e: except AssertionError, e:
print str(e) logger.error(str(e))
finally:
print "\n"


def trace_checks(self): def trace_checks(self):
try: try:
print "Checking TRACE is not valid" logger.info("Checking TRACE is not valid")
http_urls = self._clean_url(self.urls) http_urls = self._clean_url(self.urls)
request = httplib.HTTPConnection(http_urls[0]) request = httplib.HTTPConnection(http_urls[0])
if len(http_urls) > 1: if len(http_urls) > 1:
Expand All @@ -45,23 +49,19 @@ def trace_checks(self):
request.getresponse() request.getresponse()
raise Exception("TRACE is a valid HTTP call") raise Exception("TRACE is a valid HTTP call")
except httplib.BadStatusLine, e: except httplib.BadStatusLine, e:
print "TRACE is not valid" logger.error("TRACE is not valid")
except Exception, e: except Exception, e:
print str(e) logger.error(str(e))
finally:
print "\n"




def redirect_checks(self): def redirect_checks(self):
response = urllib2.urlopen(self.urls) response = urllib2.urlopen(self.urls)
try: try:
print "Checking for HTTPS" logger.info("Checking for HTTPS")
assert "https://" in response.geturl(), "Have not been redirected to HTTPS" assert "https://" in response.geturl(), "Have not been redirected to HTTPS"
print "Redirected to HTTPS version of site" logger.info("Redirected to HTTPS version of site")
except AssertionError, e: except AssertionError, e:
print str(e) logger.error(str(e))
finally:
print "\n"




def _clean_header(self, response_headers): def _clean_header(self, response_headers):
Expand Down Expand Up @@ -89,7 +89,7 @@ def main():
help="File name with URLS to test, Currently not available") help="File name with URLS to test, Currently not available")


(options, args) = parser.parse_args() (options, args) = parser.parse_args()
if len(args) == 0: if not options:
parser.error("Please supply an argument") parser.error("Please supply an argument")


garmr = Garmr(options.aut) garmr = Garmr(options.aut)
Expand Down

0 comments on commit fc33436

Please sign in to comment.