Esempio n. 1
0
  def test_tgz(self):
    FILE = os.path.realpath('apps/filebrowser/src/filebrowser/test_data/test.tar.gz')

    # Extract the file
    # This file should only have 'test.txt' in it
    directory = archives.archive_factory(FILE, 'tgz').extract()
    assert_true(os.path.exists(directory))
    assert_true(os.path.isdir(directory))
    assert_true(os.path.isfile(directory + '/test.txt'))
    assert_equal(os.path.getsize(directory + '/test.txt'), 4)

    FILE = os.path.realpath('apps/filebrowser/src/filebrowser/test_data/test2.tar.gz')

    # Extract the file
    # This file should only have 'test.txt' in it
    directory = archives.archive_factory(FILE, 'tar.gz').extract()
    assert_true(os.path.exists(directory))
    assert_true(os.path.isdir(directory))
    assert_true(os.path.isfile(directory + '/home/docs/test.txt'))
    assert_equal(os.path.getsize(directory + '/home/docs/test.txt'), 4)

    # This file should not be extracted as it contains illegal path '../../../Desktop/test.txt'
    FILE = os.path.realpath('apps/filebrowser/src/filebrowser/test_data/test3.tar.gz')

    factory = archives.archive_factory(FILE, 'tar.gz')
    self.assertRaises(IllegalPathException, factory.extract)

    # This file should not be extracted as it contains absolute path
    FILE = os.path.realpath('apps/filebrowser/src/filebrowser/test_data/test4.tar.gz')

    factory = archives.archive_factory(FILE, 'tar.gz')
    self.assertRaises(IllegalPathException, factory.extract)
Esempio n. 2
0
  def test_tgz(self):
    FILE = os.path.realpath('apps/filebrowser/src/filebrowser/test_data/test.tar.gz')

    # Extract the file
    # This file should only have 'test.txt' in it
    directory = archives.archive_factory(FILE, 'tgz').extract()
    assert_true(os.path.exists(directory))
    assert_true(os.path.isdir(directory))
    assert_true(os.path.isfile(directory + '/test.txt'))
    assert_equal(os.path.getsize(directory + '/test.txt'), 4)

    FILE = os.path.realpath('apps/filebrowser/src/filebrowser/test_data/test2.tar.gz')

    # Extract the file
    # This file should only have 'test.txt' in it
    directory = archives.archive_factory(FILE, 'tar.gz').extract()
    assert_true(os.path.exists(directory))
    assert_true(os.path.isdir(directory))
    assert_true(os.path.isfile(directory + '/home/docs/test.txt'))
    assert_equal(os.path.getsize(directory + '/home/docs/test.txt'), 4)

    # This file should not be extracted as it contains illegal path '../../../Desktop/test.txt'
    FILE = os.path.realpath('apps/filebrowser/src/filebrowser/test_data/test3.tar.gz')

    factory = archives.archive_factory(FILE, 'tar.gz')
    self.assertRaises(IllegalPathException, factory.extract)

    # This file should not be extracted as it contains absolute path
    FILE = os.path.realpath('apps/filebrowser/src/filebrowser/test_data/test4.tar.gz')

    factory = archives.archive_factory(FILE, 'tar.gz')
    self.assertRaises(IllegalPathException, factory.extract)
Esempio n. 3
0
  def test_zip(self):
    FILE = os.path.realpath('apps/filebrowser/src/filebrowser/test_data/test.zip')

    # Extract the file
    # This file should only have 'test.txt' in it
    directory = archives.archive_factory(FILE, 'zip').extract()
    assert_true(os.path.exists(directory))
    assert_true(os.path.isdir(directory))
    assert_true(os.path.isfile(directory + '/test.txt'))
    assert_equal(os.path.getsize(directory + '/test.txt'), 4)
Esempio n. 4
0
  def test_tgz(self):
    FILE = os.path.realpath('apps/filebrowser/src/filebrowser/test_data/test.tar.gz')

    # Extract the file
    # This file should only have 'test.txt' in it
    directory = archives.archive_factory(FILE, 'tgz').extract()
    assert_true(os.path.exists(directory))
    assert_true(os.path.isdir(directory))
    assert_true(os.path.isfile(directory + '/test.txt'))
    assert_equal(os.path.getsize(directory + '/test.txt'), 4)