2006-11-30 15:36:53 +01:00
|
|
|
#
|
|
|
|
# Copyright 2006 sense.lab e.V.
|
|
|
|
#
|
|
|
|
# This file is part of the CryptoBox.
|
|
|
|
#
|
|
|
|
# The CryptoBox is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# The CryptoBox is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with the CryptoBox; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2006-11-27 20:25:26 +01:00
|
|
|
import cryptobox.web.testclass
|
2006-11-06 17:05:00 +01:00
|
|
|
from network import CHANGE_IP_DELAY
|
|
|
|
|
|
|
|
|
2006-11-27 20:25:26 +01:00
|
|
|
class unittests(cryptobox.web.testclass.WebInterfaceTestClass):
|
2006-11-06 17:05:00 +01:00
|
|
|
|
|
|
|
def test_ip_change(self):
|
|
|
|
'''change of network address'''
|
|
|
|
## the time module is necessary for the CHANGE_IP_DELAY
|
|
|
|
import time
|
|
|
|
self.register_auth(self.URL + "network")
|
|
|
|
self.cmd.go(self.URL + "network")
|
|
|
|
## extract the current IP from the network plugin output
|
|
|
|
def getCurrentIP():
|
|
|
|
self.cmd.go(self.URL + "network")
|
|
|
|
self.cmd.find(u'Data.Status.Plugins.network=([0-9\.]*)$', "m")
|
|
|
|
return self.locals["__match__"]
|
|
|
|
origIPtext = getCurrentIP()
|
|
|
|
origIPocts = origIPtext.split(".")
|
|
|
|
## check, if the original IP is valid (contains four octets)
|
|
|
|
self.assertEquals(4, len(origIPocts))
|
|
|
|
wrongIP = "192.168.123.321"
|
|
|
|
def setIP((ip1, ip2, ip3, ip4)):
|
|
|
|
self.cmd.go(self.URL + "network")
|
|
|
|
self.cmd.formvalue("set_ip", "ip1", str(ip1))
|
|
|
|
self.cmd.formvalue("set_ip", "ip2", str(ip2))
|
|
|
|
self.cmd.formvalue("set_ip", "ip3", str(ip3))
|
|
|
|
self.cmd.formvalue("set_ip", "ip4", str(ip4))
|
|
|
|
self.cmd.submit()
|
|
|
|
## sleep a little bit longer than the delay necessary for ip-change
|
|
|
|
time.sleep(CHANGE_IP_DELAY + 0.2)
|
|
|
|
setIP([1,-2,0,1])
|
|
|
|
self.assertEquals(origIPtext, getCurrentIP())
|
|
|
|
setIP([1,0,0,256])
|
|
|
|
self.assertEquals(origIPtext, getCurrentIP())
|
|
|
|
setIP([1,"foo",0,1])
|
|
|
|
self.assertEquals(origIPtext, getCurrentIP())
|
|
|
|
setIP([10,12,0,2])
|
|
|
|
self.assertEquals("10.12.0.2", getCurrentIP())
|
|
|
|
setIP(origIPocts)
|
|
|
|
self.assertEquals(origIPtext, getCurrentIP())
|
|
|
|
|
|
|
|
|
2006-11-30 15:36:53 +01:00
|
|
|
def test_inputs(self):
|
|
|
|
self.register_auth(self.URL + "network")
|
|
|
|
self.cmd.go(self.URL + "network" + "?redirected=1")
|
|
|
|
self.cmd.notfind("problem")
|
|
|
|
self.cmd.go(self.URL + "network" + "?store=1")
|
|
|
|
self.cmd.find("invalid network address")
|
|
|
|
|