def new_directory(user, project, **kwargs): save = kwargs.pop("save", False) kwargs["author"] = user kwargs["project"] = project kwargs["path"] = kwargs.get("path", "/testdir/") f = File.create(data=kwargs) if save: f.save() return f
def test_create_file_security(self): f = File.create(data={ "project": self.project, "path": "/../../../../evil/path" }) self.assertTrue(".." not in f.fspath) self.assertEquals("/evil/path", f.path) self.assertEquals(os.path.join(File.FILES_FOLDER, self.project.key, "evil/path"), f.fspath)
def new_file(user, project, **kwargs): save = kwargs.pop("save", False) kwargs["author"] = user kwargs["project"] = project kwargs["path"] = kwargs.get("path", "/testfile.txt") kwargs["file"] = kwargs.get("file", FileStorage(StringIO("hello world"), "testfile.txt")) f = File.create(data=kwargs) if save: f.save() return f
def test_create_file_security(self): f = File.create(data={ "project": self.project, "path": "/../../../../evil/path" }) self.assertTrue(".." not in f.fspath) self.assertEquals("/evil/path", f.path) self.assertEquals( os.path.join(File.FILES_FOLDER, self.project.key, "evil/path"), f.fspath)
def test_create_directory(self): f = File.create(data={"project": self.project, "path": "/directory/"}) fspath = os.path.join(File.FILES_FOLDER, self.project.key, "directory") + "/" self.assertEquals(fspath, f.fspath) self.assertFalse(os.path.exists(fspath)) f.save() self.assertTrue(os.path.exists(fspath)) self.assertTrue(os.path.isdir(fspath))
def new_file(user, project, **kwargs): save = kwargs.pop("save", False) kwargs["author"] = user kwargs["project"] = project kwargs["path"] = kwargs.get("path", "/testfile.txt") kwargs["file"] = kwargs.get( "file", FileStorage(StringIO("hello world"), "testfile.txt")) f = File.create(data=kwargs) if save: f.save() return f
def test_create_directory(self): f = File.create(data={ "project": self.project, "path": "/directory/" }) fspath = os.path.join(File.FILES_FOLDER, self.project.key, "directory") + "/" self.assertEquals(fspath, f.fspath) self.assertFalse(os.path.exists(fspath)) f.save() self.assertTrue(os.path.exists(fspath)) self.assertTrue(os.path.isdir(fspath))
def test_create_file(self): f = File.create(data={ "project": self.project, "path": "/newfile.txt", "file": FileStorage(*test_file("newfile.txt")) }) self.assertEquals("{}`{}".format(self.project.key, "/newfile.txt"), f.key) fspath = os.path.join(File.FILES_FOLDER, self.project.key, "newfile.txt") self.assertEquals(fspath, f.fspath) self.assertFalse(os.path.exists(fspath)) f.save() self.assertEquals("/newfile.txt", f.path) self.assertTrue(os.path.exists(fspath)) with open(fspath) as fi: c = fi.read().strip() self.assertEquals("hello world", c)
def test_create_file(self): f = File.create( data={ "project": self.project, "path": "/newfile.txt", "file": FileStorage(*test_file("newfile.txt")) }) self.assertEquals("{}`{}".format(self.project.key, "/newfile.txt"), f.key) fspath = os.path.join(File.FILES_FOLDER, self.project.key, "newfile.txt") self.assertEquals(fspath, f.fspath) self.assertFalse(os.path.exists(fspath)) f.save() self.assertEquals("/newfile.txt", f.path) self.assertTrue(os.path.exists(fspath)) with open(fspath) as fi: c = fi.read().strip() self.assertEquals("hello world", c)