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
|
|
|
|
#
|
|
|
|
|
2007-03-21 19:35:31 +01:00
|
|
|
__revision__ = "$Id$"
|
2006-12-05 13:24:47 +01:00
|
|
|
|
2007-01-08 06:08:07 +01:00
|
|
|
from cryptobox.tests.base import WebInterfaceTestClass
|
|
|
|
import cryptobox.tests.tools as cbox_tools
|
2006-11-06 17:05:00 +01:00
|
|
|
|
2007-01-08 06:08:07 +01:00
|
|
|
class unittests(WebInterfaceTestClass):
|
2006-11-06 17:05:00 +01:00
|
|
|
|
|
|
|
def test_read_form(self):
|
2006-12-12 14:34:05 +01:00
|
|
|
"""Check if the 'volume_rename' plugin works.
|
|
|
|
"""
|
2007-01-08 06:08:07 +01:00
|
|
|
url = self.url + "volume_rename?weblang=en&device=" + self.device_html
|
2006-11-06 17:05:00 +01:00
|
|
|
self.register_auth(url)
|
2007-01-08 06:08:07 +01:00
|
|
|
## umount, if necessary
|
|
|
|
cbox_tools.umount(self.device)
|
|
|
|
## check a language string
|
2006-11-06 17:05:00 +01:00
|
|
|
self.cmd.go(url)
|
2007-02-03 12:40:22 +01:00
|
|
|
self.cmd.find('Change name')
|
2006-12-12 14:34:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_rename(self):
|
|
|
|
"""Try to rename the volume.
|
|
|
|
"""
|
2007-01-08 06:08:07 +01:00
|
|
|
## umount, if necessary
|
|
|
|
cbox_tools.umount(self.device)
|
2006-12-12 14:34:05 +01:00
|
|
|
save_name = self.__get_name()
|
2006-12-14 14:19:37 +01:00
|
|
|
## rename if the name is already "foo"
|
|
|
|
if save_name == "foo":
|
|
|
|
self.__set_name("bar")
|
2006-12-12 14:34:05 +01:00
|
|
|
## set 'foo'
|
|
|
|
self.__set_name("foo")
|
|
|
|
self.cmd.find('The name of this volume was changed successfully.')
|
|
|
|
self.assertEquals("foo", self.__get_name())
|
|
|
|
## set 'bar'
|
|
|
|
self.__set_name("bar")
|
|
|
|
self.cmd.find('The name of this volume was changed successfully.')
|
|
|
|
self.assertEquals("bar", self.__get_name())
|
|
|
|
## set the same name twice to catch all lines of code
|
|
|
|
self.__set_name("bar")
|
|
|
|
self.cmd.notfind('The name of this volume was changed successfully.')
|
|
|
|
self.assertEquals("bar", self.__get_name())
|
|
|
|
self.__set_name(save_name)
|
|
|
|
self.assertEquals(save_name, self.__get_name())
|
|
|
|
|
|
|
|
|
|
|
|
def test_invalid_names(self):
|
|
|
|
"""Setting of invalid names should fail.
|
|
|
|
"""
|
2007-01-08 06:08:07 +01:00
|
|
|
## umount, if necessary
|
|
|
|
cbox_tools.umount(self.device)
|
2006-12-12 14:34:05 +01:00
|
|
|
save_name = self.__get_name()
|
|
|
|
## we want to avoid, that if the previous name is (by accident) 'foo'
|
|
|
|
## then the later search for "changed successfully" would fail
|
|
|
|
if save_name == "foo":
|
|
|
|
self.__set_name("bar")
|
|
|
|
self.__set_name("foo")
|
|
|
|
self.cmd.find('The name of this volume was changed successfully.')
|
|
|
|
self.assertEquals("foo", self.__get_name())
|
|
|
|
self.__set_name("foo:")
|
|
|
|
self.cmd.find("Changing of volume's name failed")
|
|
|
|
self.assertEquals("foo", self.__get_name())
|
|
|
|
self.__set_name("foo/")
|
|
|
|
self.cmd.find("Changing of volume's name failed")
|
|
|
|
self.assertEquals("foo", self.__get_name())
|
2006-12-14 14:19:37 +01:00
|
|
|
self.__set_name("foo/")
|
2006-12-12 14:34:05 +01:00
|
|
|
self.cmd.find("Changing of volume's name failed")
|
|
|
|
self.assertEquals("foo", self.__get_name())
|
|
|
|
self.__set_name("foo*")
|
|
|
|
self.cmd.find("Changing of volume's name failed")
|
|
|
|
self.assertEquals("foo", self.__get_name())
|
|
|
|
self.__set_name("foo(")
|
|
|
|
self.cmd.find("Changing of volume's name failed")
|
|
|
|
self.assertEquals("foo", self.__get_name())
|
|
|
|
self.__set_name("")
|
|
|
|
self.cmd.notfind("Changing of volume's name failed")
|
|
|
|
self.assertEquals("foo", self.__get_name())
|
|
|
|
self.__set_name(save_name)
|
|
|
|
self.assertEquals(save_name, self.__get_name())
|
|
|
|
|
|
|
|
|
|
|
|
def test_rename_while_open(self):
|
|
|
|
"""Try to change the name of the volume while it is open.
|
|
|
|
"""
|
2007-01-08 06:08:07 +01:00
|
|
|
## umount, if necessary
|
|
|
|
cbox_tools.umount(self.device)
|
2006-12-12 14:34:05 +01:00
|
|
|
save_name = self.__get_name()
|
|
|
|
## first set the name to 'bar'
|
|
|
|
self.__set_name("bar")
|
2007-01-08 06:08:07 +01:00
|
|
|
mount_url = self.url + "volume_mount?weblang=en&device=" + self.device_html
|
2006-12-12 14:34:05 +01:00
|
|
|
self.register_auth(mount_url)
|
2007-01-08 06:08:07 +01:00
|
|
|
name_url = self.url + "volume_rename?weblang=en&device=" + self.device_html
|
2006-12-12 14:34:05 +01:00
|
|
|
self.register_auth(name_url)
|
|
|
|
self.cmd.go(mount_url + "&action=mount_plain")
|
|
|
|
self.cmd.find('Volume opened')
|
|
|
|
## we have to do it manually, as there is no form when it is open
|
|
|
|
self.cmd.go(name_url + "&store=1&vol_name=foo")
|
|
|
|
self.cmd.find('You may not rename a volume while it is open.')
|
|
|
|
self.assertEquals("bar", self.__get_name())
|
|
|
|
self.cmd.go(mount_url + "&action=umount")
|
|
|
|
self.__set_name(save_name)
|
|
|
|
self.assertEquals(save_name, self.__get_name())
|
|
|
|
|
|
|
|
|
|
|
|
def test_name_in_use(self):
|
|
|
|
"""Try to set a name that is already in use.
|
|
|
|
"""
|
2007-01-08 06:08:07 +01:00
|
|
|
## umount, if necessary
|
|
|
|
cbox_tools.umount(self.device)
|
2006-12-12 14:34:05 +01:00
|
|
|
used_name = [ e.get_name() for e in self.cbox.get_container_list()
|
2007-01-08 06:08:07 +01:00
|
|
|
if e.get_device() != self.device ]
|
2006-12-12 14:34:05 +01:00
|
|
|
if not used_name:
|
|
|
|
self.fail("could not find another device for this test")
|
|
|
|
old_name = self.__get_name()
|
|
|
|
self.assertNotEquals(old_name, used_name[0])
|
|
|
|
self.__set_name(used_name[0])
|
|
|
|
self.cmd.find('The new name is already in use by another volume.')
|
|
|
|
self.assertEquals(old_name, self.__get_name())
|
|
|
|
|
|
|
|
|
|
|
|
def __set_name(self, name):
|
|
|
|
"""Set the name of a volume.
|
|
|
|
"""
|
2006-12-14 14:19:37 +01:00
|
|
|
name = name.replace(" ", "%20")
|
2007-01-08 06:08:07 +01:00
|
|
|
url = self.url + "volume_rename?weblang=en&device=" + self.device_html
|
2006-12-12 14:34:05 +01:00
|
|
|
self.register_auth(url)
|
2006-12-14 14:19:37 +01:00
|
|
|
# the following should work, but twill seems to have problems to recognize
|
|
|
|
# the form - fix this later
|
|
|
|
#self.cmd.go(url)
|
|
|
|
#self.cmd.formvalue("set_name", "vol_name", name)
|
|
|
|
#self.cmd.submit()
|
|
|
|
self.cmd.go(url + "&vol_name=%s&store=1" % name)
|
2006-12-12 14:34:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
def __get_name(self):
|
|
|
|
"""Retrieve the current name of the volume.
|
|
|
|
"""
|
2007-01-08 06:08:07 +01:00
|
|
|
url = self.url + "volume_rename?weblang=en&device=" + self.device_html
|
2006-12-12 14:34:05 +01:00
|
|
|
self.register_auth(url)
|
|
|
|
self.cmd.go(url)
|
|
|
|
self.cmd.find("Data.Status.Plugins.volume_rename=(.*)$", "m")
|
|
|
|
return self.locals["__match__"]
|
2007-01-08 06:08:07 +01:00
|
|
|
|