Exemplo n.º 1
0
def main():
	server = Server()

	commandNet = TestNetwork(server, False)
	dataNet = TestNetwork(server, True)
	host = "foo"
	client = Client(commandNet, dataNet)
	# This sets the artificial clien bug:
	#client.setDataTransferConfirmationBug(True)
	suc = client.connect(host, 21)
	print "C:Test connected:", suc
	if not suc:
		return
	
	suc = client.login("anonymous", "*****@*****.**")
	if not suc:
		return
	
	f = client.retrieveFile("xx")
	if f is None:
		pass
	else:
		print f
		
	f = client.retrieveFile("xx2")
	if f is None:
		pass
	else:
		print f
	
	
	stream = client.retrieveFileStream("xx")
	buf = ""
	if stream is not None:
		c = stream.read()
		while c != -1:
			buf += chr(c);
			c = stream.read()
	
		stream.close();
		print buf
		
	suc = client.changeWorkingDirectory("b_dir")
	if not suc:
		pass
	
	suc = client.deleteFile("a_file")
	if not suc:
		pass
	
	suc = client.logout()
	if not suc:
		pass

	print "C:TestDone."
def main(dataTransferConfirmationBug, pasvResponseReadingBug, cuttingServer):
	""" 
		Mainly for counting states of JPF and for comparison with simulation 
	"""
	assert not (dataTransferConfirmationBug and pasvResponseReadingBug)
	
	config = None
	if cuttingServer:
		config = RandServerConfig()
		config.setSERVER_LEVEL(0)
		config.setREADLINE_LEVEL(2)
		
	server = RandServer(config)

	commandNet = TestNetwork(server, False, config)
	dataNet = TestNetwork(server, True)
	host = "foo"
	client = Client(commandNet, dataNet)
	# This sets the artificial clien bug:
	client.setDataTransferConfirmationBug(dataTransferConfirmationBug)
	client.setPasvResponseReadingBug(pasvResponseReadingBug)
	suc = client.connect(host, 21)
	print "C:Test connected:", suc
	if not suc:
		return
	
	suc = client.login("anonymous", "*****@*****.**")
	if not suc:
		return
	
	f = client.retrieveFile("xx")
	if f is None:
		pass
	else:
		print f
		
	f = client.retrieveFile("xx2")
	if f is None:
		pass
	else:
		print f
	
	suc = client.logout()
	if not suc:
		pass

	print "C:TestDone."
Exemplo n.º 3
0
def main():
    """
		Tests various sequences of commands.
	"""
    server = Server()

    commandNet = TestNetwork(server, False)
    dataNet = TestNetwork(server, True)
    host = "foo"
    client = Client(commandNet, dataNet)
    suc = client.connect(host, 21)
    print "C:Test connected:", suc
    if not suc:
        return

    suc = client.login("anonymous", "*****@*****.**")
    if not suc:
        return

    for i in range(3):
        cmd = random(3)
        if cmd == 0:
            f = client.retrieveFile("xx")
            if f is None:
                pass
            else:
                print f
        elif cmd == 1:
            stream = client.retrieveFileStream("xx")
            buf = ""
            if stream is not None:
                c = stream.read()
                while c != -1:
                    buf += chr(c)
                    c = stream.read()

                stream.close()
                print buf
        elif cmd == 2:
            suc = client.changeWorkingDirectory("b_dir")
            if not suc:
                pass
        elif cmd == 3:
            files = client.listFiles()
            if files is None:
                pass

    suc = client.logout()
    if not suc:
        pass

    print "C:TestDone (random 2)."
Exemplo n.º 4
0
def wild_connnection_experiment():
	commandNet = Network()
	dataNet = Network()
	client = Client(commandNet, dataNet)
	client.connect("ftp.gnu.org", 21)
	timeoutset = commandNet.setTimeout(1000)
	if not timeoutset:
		print "Timeout not set"
		return False
	
	connected = client.isConnected()	
	if not connected:
		print "Not connected"
		return False
	
	logged = client.login("anonymous", "*****@*****.**")
	if not logged:
		print "Not logged"
		return False
	
	files = client.listFiles()
	if files is not None:
		for i in files:
			print i.toString()
	else:
		print("No listing obtained.")
		return False
	
	print client.retrieveFile("README")
	
	## Streaming..
	"""
	stream = client.retrieveFileStream("README")
	buf = ""
	print "C:reading from stream byte by byte"
	c = stream.read()
	while c != -1:
		buf += chr(c);
		c = stream.read()
	
	print "C:closing stream"	
	stream.close();
	print "C:File from stream:"
	print buf
	"""
	
	return True
Exemplo n.º 5
0
def main():
	""" This test demostrates that
		- the tracker is properly synchronized (chec_race)
		- StateException is raised until stream is not closed
	"""
	server = Server()
	commandNet = TestNetwork(server, False)
	dataNet = TestNetwork(server, True)
	host = "foo"
	client = Client(commandNet, dataNet)
	suc = client.connect(host, 21)
	print "C:Test connected:", suc
	client.login("anonymous", "*****@*****.**")

	print "C:Testing stream api (MT)..."
	stream = client.retrieveFileStream("xx")

	worker = Worker(stream)
	worker.start()
	
	f = None	
	try:
		# we either succeed fully or raise StateException
		f = client.retrieveFile("xx2")
		assert (f is not None)
	except StateException:
		print "Expected warning ^."
		# this operation may fail if the thread is not finished
		# raising an exception is correct behavior
		pass

	print "C:", (f is not None)

	print "C:joining thread"	
	worker.join() ## INJECTION: comment this line to inject a bug
	
	# these operation never fail
	# because we have joined the thread
	suc = client.changeWorkingDirectory("a_dir")
	assert (suc == True)
	suc = client.changeWorkingDirectory("b_dir")
	assert (suc == True)

	print "C:TestDone."
Exemplo n.º 6
0
def wiring():
	commandNet = INetwork()
	dataNet = INetwork()
	client = Client(commandNet, dataNet)
	client.connect("bar", 122)
	return (client.isConnected(), client.isLogged())
Exemplo n.º 7
0
def main():
	server = Server()
	commandNet = TestNetwork(server, False)
	dataNet = TestNetwork(server, True)
	host = "foo"
	client = Client(commandNet, dataNet)
	suc = client.connect(host, 21)
	print "C:Test connected:", suc
	client.login("anonymous", "*****@*****.**")
	files = client.listFiles()
	if files is not None:
		for i in files:
			print i.toString()
	else:
		print("C:No listing obtained.")
	
	f = client.retrieveFile("xx")
	if f is not None:
		print "C:File is:\r\n", f
	else:
		print "C:File transfer failed."

	print "C:Testing stream api..."
	stream = client.retrieveFileStream("xx")
	buf = ""
	print "C:reading from stream byte by byte"
	c = stream.read()
	while c != -1:
		buf += chr(c);
		c = stream.read()
	
	print "C:closing stream"	
	stream.close();
	print "C:File from stream:"
	print buf
	

	print "C: ask and close"
	stream = client.retrieveFileStream("xx2")
	stream.close();
	
	
	print "C:Healthy?"
	f = client.retrieveFile("xx2") # suppress aggresive optimization
	print "C:", (file is not None)
	
	client.changeWorkingDirectory("a_dir")
	client.changeWorkingDirectory("b_dir") # suppress aggresive optimization
	
	client.deleteFile("a_file")
	client.deleteFile("b_file") #suppress aggresive optimization
	
	client.logout()
	
	print "C:TestDone."
Exemplo n.º 8
0
def main(clientBug):
	server = Server()
	server.setExperimentErrorDataTransferConfirmation(True)
	commandNet = TestNetwork(server, False)
	dataNet = TestNetwork(server, True)
	host = "foo"
	client = Client(commandNet, dataNet)
	client.setDataTransferConfirmationBug(clientBug)
	client.setPasvResponseReadingBug(clientBug)
	suc = client.connect(host, 21)
	print "C:Test connected:", suc
	client.login("anonymous", "*****@*****.**")
	
	f = client.retrieveFile("xx")
	if f is not None:
		print "C:File is:\r\n", f
	else:
		print "C:File transfer failed."

	print "C:##Second shot..."
	
	f = client.retrieveFile("xx")
	if f is not None:
		print "C:File is(2):\r\n", f
	else:
		print "C:File transfer failed.(2)"
	
	print "C:##Third shot..."
	
	f = client.retrieveFile("xx")
	if f is not None:
		print "C:File is(3):\r\n", f
	else:
		print "C:File transfer failed.(3)"
	
	print "C:##Stream shot..."	
	
	stream = client.retrieveFileStream("xx")
	counter = 0
	while True:
		c = stream.read()
		if c == -1:
			stream.close()
			break
		else:
			counter += 1

	print "Stream contained %d bytes" % counter
	
	client.logout()
	
	print "C:TestDone."