def main():
    global pub_urls
    try:
        proxy_bin = sys.argv[1]
    except IndexError:
        usage()
        sys.exit(2)
    try:
        port = sys.argv[2]
    except IndexError:
        port = str(random.randint(1025, 49151))

    print 'Binary: %s' % proxy_bin
    print 'Running on port %s' % port

    # Start the proxy running in the background
    cid = os.spawnl(os.P_NOWAIT, proxy_bin, proxy_bin, port)
    # Give the proxy time to start up and start listening on the port
    time.sleep(2)

    passcount = 0
    for url in pub_urls:
        print '### Testing: ' + url
        passed = run_test(compare_url, (url, port), cid)
        if not live_process(cid):
            print '!!!Proxy process experienced abnormal termination during test- restarting proxy!'
            (cid, port) = restart_proxy(proxy_bin, port)
            passed = False

        if passed:
            print '%s: [PASSED]\n' % url
            passcount += 1
        else:
            print '%s: [FAILED]\n' % url

    if (use_private):
        (priv_passed, test_count,
         cid) = proxy_grade_private.runall(port, cid, proxy_bin)

    # Cleanup
    terminate(cid)

    print 'Summary: '
    print '\t%d of %d tests passed.' % (passcount, len(pub_urls))
    if (use_private):
        print '%d of %d extended tests passed' % (priv_passed, test_count)
Beispiel #2
0
def main():
     global pub_urls
     try:
          proxy_bin = sys.argv[1]
     except IndexError:
          usage()
          sys.exit(2)
     try:
          port = sys.argv[2]
     except IndexError:
          port = str(random.randint(1025, 49151))

     print 'Binary: %s' % proxy_bin
     print 'Running on port %s' % port

     # Start the proxy running in the background
     cid = os.spawnl(os.P_NOWAIT, proxy_bin, proxy_bin, port)
     # Give the proxy time to start up and start listening on the port
     time.sleep(2)

     passcount = 0
     for url in pub_urls:
          print '### Testing: ' + url
          passed = run_test(compare_url, (url, port), cid)
          if not live_process(cid):
               print '!!!Proxy process experienced abnormal termination during test- restarting proxy!'
               (cid, port) = restart_proxy(proxy_bin, port)
               passed = False

          if passed:
               print '%s: [PASSED]\n' % url
               passcount += 1
          else:
               print '%s: [FAILED]\n' % url

     if (use_private):
          (priv_passed, test_count, cid) = proxy_grade_private.runall(port, cid, proxy_bin)

     # Cleanup
     terminate(cid)

     print 'Summary: '
     print '\t%d of %d tests passed.' % (passcount, len(pub_urls))
     if (use_private):
          print '%d of %d extended tests passed' % (priv_passed, test_count)
Beispiel #3
0
def main():
    global pub_urls
    try:
        proxy_bin = sys.argv[1]
    except IndexError:
        usage()
        sys.exit(2)
    try:
        if int(sys.argv[2]) >= 0:
            port = sys.argv[2]
        else:
            port = str(random.randint(1025, 49151))
    except (IndexError, ValueError):
        port = str(random.randint(1025, 49151))

    # the following arguments are only used for grading
    try:
        test_num = int(sys.argv[3])
    except IndexError:
        test_num = 1
    try:
        passcount_file = sys.argv[4]
    except IndexError:
        passcount_file = None
    try:
        testcount_file = sys.argv[5]
    except IndexError:
        testcount_file = None

    print 'Binary: %s' % proxy_bin
    print 'Running on port %s\n' % port

    # Start the proxy running in the background
    cid = os.spawnl(os.P_NOWAIT, proxy_bin, proxy_bin, port)
    # Give the proxy time to start up and start listening on the port
    time.sleep(2)

    passcount = 0
    for url in pub_urls:
        print '### %d. Testing: ' % test_num + url
        test_num += 1
        passed = run_test(compare_url, (url, port), cid)
        if not live_process(cid):
            print '!!!Proxy process experienced abnormal termination during test- restarting proxy!'
            (cid, port) = restart_proxy(proxy_bin, port)
            passed = False

        if passed:
            print '%s: SUCCESS' % url
            passcount += 1
        else:
            print '%s: FAILURE' % url
        print(separator)

    if (use_private):
        (priv_passed, test_count, cid) = proxy_grade_private.runall(port, cid, proxy_bin)

    # Cleanup
    terminate(cid)

    if passcount_file != None:
        with open(passcount_file, 'w') as f:
            f.write(str(passcount))

    if testcount_file != None:
        with open(testcount_file, 'w') as f:
            f.write(str(len(pub_urls)))

    print 'Summary: '
    print '\t%d of %d tests passed.' % (passcount, len(pub_urls))
    if (use_private):
        print '%d of %d extended tests passed' % (priv_passed, test_count)
Beispiel #4
0
def main():
     global pub_urls
     try:
          proxy_bin = sys.argv[1]
          port = sys.argv[2]
     except IndexError:
          usage()
          sys.exit(2)

     print 'Binary: %s' % proxy_bin
     print 'Running on port %s' % port

     # Start the proxy running in the background
     cid = os.spawnl(os.P_NOWAIT, proxy_bin, proxy_bin, '-U', '-t','225','-s', 'vns-2.stanford.edu', '-v', 'vhost', '-r', 'rtable.vhost', port)
     # Give the proxy time to start up and start listening on the port
     time.sleep(2)
     proxy_map = {'http':'http://192.168.129.107:' + port}

     foblist = []
     for url in pub_urls:
          foblist.append(urllib.urlopen(url, None, proxy_map))

     passcount = 0
     for n in range(len(foblist)):
          proxy_file = foblist[n]
          lines = proxy_file.readlines()
          if (len(lines) == 0):
               print "No data received for " + pub_urls[n]
               continue

          direct_file = urllib.urlopen(pub_urls[n])
          direct_lines = direct_file.readlines()

          fail = False
          for (prox_line, dir_line) in zip(lines, direct_lines):
               if prox_line != dir_line:
                    print '>>> ' + prox_line
                    print '<<< ' + dir_line
                    direct_file.close()
                    fail = True
                    break

          direct_file.close()
          if not fail:
               passcount += 1

     for fob in foblist:
          fob.close()

     print r'Basic HTTP transactions: %d of %d tests passed' % (passcount, len(pub_urls))


     if (use_private):
          priv_passed = proxy_grade_private.runall(port, cid)


     # Cleanup
     os.kill(cid, signal.SIGINT)
     time.sleep(2)
     os.kill(cid, signal.SIGKILL)
     os.waitpid(cid, 0)

     print 'Summary: '
     print '\t%d of %d tests passed.' % (passcount, len(pub_urls))
     score = 0
     if (use_private):
          if (priv_passed):
               print '\t100% of extended tests passed.'
               score += 1
          else:
               print'\tNot all extended tests passed.'

     score += (float(passcount) / float(len(pub_urls))) * 8
     print 'Base Score: %d/10 (Remember, one point is based on style!)' % score