Пример #1
0
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
Пример #2
0
  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)
Пример #3
0
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
Пример #4
0
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
Пример #5
0
    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)
Пример #6
0
    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))
Пример #7
0
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
Пример #8
0
  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))
Пример #9
0
  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)
Пример #10
0
    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)