2003-06-19 00:44:16 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
## $Id$
|
|
|
|
|
2003-07-18 21:43:12 +00:00
|
|
|
from testbase import *
|
2003-06-19 00:44:16 +00:00
|
|
|
import urllib, random
|
|
|
|
|
|
|
|
# test makes sure that testing framework is sane
|
|
|
|
|
2003-06-26 23:53:37 +00:00
|
|
|
def read_url(url, quiet=False):
|
2003-06-19 00:44:16 +00:00
|
|
|
'''return 1 line from url'''
|
2003-06-26 23:53:37 +00:00
|
|
|
verbose_echo(2, " reading url: "+url)
|
2003-08-14 00:15:30 +00:00
|
|
|
err = ''
|
2003-06-19 00:44:16 +00:00
|
|
|
try:
|
|
|
|
return urllib.URLopener().open(url).readline().strip()
|
|
|
|
except IOError, e:
|
2003-08-14 00:15:30 +00:00
|
|
|
err = e
|
|
|
|
except AttributeError:
|
|
|
|
# Python urllib is buggy if connection is closed (by our proxy
|
|
|
|
# intentionally) right after opened
|
|
|
|
pass
|
|
|
|
if not quiet:
|
|
|
|
error("couldn't access url: %s %s" % (url, err))
|
|
|
|
else:
|
|
|
|
verbose_echo(2, "couldn't access url: %s %s" % (url, err))
|
|
|
|
return ''
|
2003-06-19 00:44:16 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_msg("framework sanity");
|
|
|
|
|
|
|
|
verbose_echo(1, "Checking executables")
|
|
|
|
check_core_client_executable()
|
|
|
|
check_app_executable("upper_case")
|
|
|
|
check_app_executable("concat")
|
|
|
|
check_app_executable("1sec")
|
|
|
|
|
|
|
|
verbose_echo(1, "Checking directories")
|
2003-07-18 21:43:12 +00:00
|
|
|
for d in ['projects_dir',
|
|
|
|
'cgi_dir', 'html_dir', 'hosts_dir']:
|
|
|
|
dir = options.__dict__[d]
|
2003-06-19 00:44:16 +00:00
|
|
|
if not os.path.isdir(dir):
|
|
|
|
error("%s doesn't exist: %s" % (d, dir))
|
|
|
|
|
|
|
|
magic = "Foo %x Bar" % random.randint(0,2**16)
|
|
|
|
|
2003-07-18 21:43:12 +00:00
|
|
|
html_path = os.path.join(options.html_dir, 'test_sanity.txt')
|
|
|
|
html_url = os.path.join(options.html_url, 'test_sanity.txt')
|
2003-06-26 23:53:37 +00:00
|
|
|
html_proxy_url = proxerize(html_url)
|
2003-07-18 21:43:12 +00:00
|
|
|
cgi_path = os.path.join(options.cgi_dir, 'test_sanity_cgi')
|
|
|
|
cgi_url = os.path.join(options.cgi_url, 'test_sanity_cgi')
|
2003-06-19 00:44:16 +00:00
|
|
|
|
|
|
|
verbose_echo(1, "Checking webserver setup: non-cgi")
|
|
|
|
print >>open(html_path,'w'), magic
|
|
|
|
if read_url(html_url) != magic:
|
|
|
|
error("couldn't access a file I just wrote: "+html_path+"\n using url: "+html_url)
|
|
|
|
|
2003-06-26 23:53:37 +00:00
|
|
|
verbose_echo(1, "Checking proxy setup")
|
|
|
|
if read_url(html_proxy_url, quiet=True):
|
|
|
|
error("Another proxy already running")
|
|
|
|
else:
|
|
|
|
proxy = Proxy('')
|
|
|
|
if read_url(html_proxy_url) != magic:
|
|
|
|
error("couldn't access file using proxy url: "+html_proxy_url)
|
|
|
|
else:
|
|
|
|
proxy.stop()
|
|
|
|
|
2003-07-03 01:14:47 +00:00
|
|
|
proxy = Proxy('close_connection if $nconnections < 2')
|
2003-06-26 23:53:37 +00:00
|
|
|
if read_url(html_proxy_url, quiet=True):
|
|
|
|
error("Proxy should have closed connection #1")
|
|
|
|
if read_url(html_proxy_url) != magic:
|
|
|
|
error("Proxy should have allowed connection #2")
|
|
|
|
proxy.stop()
|
|
|
|
|
2003-06-19 00:44:16 +00:00
|
|
|
os.unlink(html_path)
|
|
|
|
|
|
|
|
verbose_echo(1, "Checking webserver setup: cgi")
|
|
|
|
print >>open(cgi_path,'w'), '''#!/bin/sh
|
|
|
|
echo "Content-Type: text/plain"
|
|
|
|
echo ""
|
|
|
|
echo "%s"
|
|
|
|
''' % magic
|
|
|
|
os.chmod(cgi_path, 0755)
|
|
|
|
|
|
|
|
if read_url(cgi_url) != magic:
|
|
|
|
error("couldn't access a cgi file I just wrote: "+cgi_path+"\n using url: "+cgi_url)
|
|
|
|
|
|
|
|
os.unlink(cgi_path)
|