Beispiel #1
0
    def test_garbage(self):
        t = TarFile(f("garbage.bin"))
        assert t.handles() is False
        assert not t.f.selected

        with pytest.raises(NotSupportedError):
            t.unpack()
Beispiel #2
0
 def test_garbage2(self):
     t = TarFile(f(b"tar_garbage.tar"))
     assert t.handles() is True
     assert not t.f.selected
     files = t.unpack()
     assert len(files) == 1
     assert not files[0].children
     assert files[0].mode == "failed"
Beispiel #3
0
 def test_garbage2(self):
     t = TarFile(f("tar_garbage.tar"))
     assert t.handles() is True
     assert not t.f.selected
     files = t.unpack()
     assert len(files) == 1
     assert not files[0].children
     assert files[0].mode == "failed"
Beispiel #4
0
    def test_garbage2(self):
        t = TarFile(f("tar_garbage.tar"))
        assert t.handles() is True
        assert not t.f.selected
        files = t.unpack()

        # The child file is garbage data. It should not be attempted
        # to unpack.
        assert len(files) == 1
        assert not files[0].children
        assert files[0].mode is None
Beispiel #5
0
 def test_tar_plain(self):
     assert "POSIX tar" in f("tar_plain.tar").magic
     t = TarFile(f("tar_plain.tar"))
     assert t.handles() is True
     assert not t.f.selected
     files = list(t.unpack())
     assert len(files) == 1
     assert files[0].relapath == "sflock.txt"
     assert files[0].contents == "sflock_plain_tar\n"
     assert files[0].magic == "ASCII text"
     assert files[0].parentdirs == []
     assert not files[0].selected
Beispiel #6
0
    def test_tar_noext(self):
        t = TarFile(f("tar_noext"))
        assert t.handles() is True
        assert not t.f.selected
        files = list(t.unpack())
        assert len(files) == 1

        assert files[0].relapath == "foo/bar.txt"
        assert files[0].parentdirs == ["foo"]
        assert files[0].contents == b"hello world\n"
        assert not files[0].password
        assert files[0].magic == "ASCII text"
        assert not files[0].selected
Beispiel #7
0
    def test_nested_plain(self):
        assert "POSIX tar archive" in f(b"tar_nested.tar").magic
        t = TarFile(f(b"tar_nested.tar"))
        assert t.handles() is True
        assert not t.f.selected
        files = list(t.unpack())
        assert len(files) == 1

        assert files[0].relapath == b"foo/bar.txt"
        assert files[0].parentdirs == [b"foo"]
        assert files[0].contents == b"hello world\n"
        assert not files[0].password
        assert files[0].magic == "ASCII text"
        assert not files[0].selected
Beispiel #8
0
    def test_nested_plain(self):
        assert "POSIX tar archive" in f("tar_nested.tar").magic
        t = TarFile(f("tar_nested.tar"))
        assert t.handles() is True
        assert not t.f.selected
        files = list(t.unpack())
        assert len(files) == 1

        assert files[0].relapath == "foo/bar.txt"
        assert files[0].parentdirs == ["foo"]
        assert files[0].contents == "hello world\n"
        assert not files[0].password
        assert files[0].magic == "ASCII text"
        assert not files[0].selected
Beispiel #9
0
    def test_nested_plain(self):
        assert "POSIX tar archive" in f("tar_nested.tar").magic
        t = TarFile(f("tar_nested.tar"))
        assert t.handles() is True
        files = list(t.unpack())
        assert len(files) == 1

        assert files[0].filepath == "foo/bar.txt"
        assert files[0].parentdirs == ["foo"]
        assert files[0].contents == "hello world\n"
        assert not files[0].password
        assert files[0].magic == "ASCII text"

        s = f("tar_nested.tar").get_signature()
        assert s is None
Beispiel #10
0
    def test_tar_plain(self):
        assert "POSIX tar" in f("tar_plain.tar").magic
        t = TarFile(f("tar_plain.tar"))
        assert t.handles() is True
        files = list(t.unpack())
        assert len(files) == 1
        assert files[0].filepath == "sflock.txt"
        assert files[0].contents == "sflock_plain_tar\n"
        assert files[0].magic == "ASCII text"
        assert files[0].parentdirs == []

        # TODO A combination of file extension, file magic, and initial bytes
        # signature should be used instead of just the bytes (as this call
        # should not yield None).
        assert f("tar_plain.tar").get_signature() is None
Beispiel #11
0
    def test_tar_plain2(self):
        assert "POSIX tar" in f("tar_plain2.tar").magic
        t = TarFile(f("tar_plain2.tar"))
        assert t.handles() is True
        files = list(t.unpack())
        assert len(files) == 2
        assert files[0].filepath == "sflock.txt"
        assert files[0].contents == "sflock_plain_tar\n"
        assert files[0].magic == "ASCII text"
        assert files[0].parentdirs == []
        assert files[1].filepath == "sflock2.txt"
        assert files[1].contents == "sflock_plain_tar2\n"
        assert files[1].magic == "ASCII text"
        assert files[1].parentdirs == []

        # TODO See item above for tar_plain.tar.
        assert f("tar_plain2.tar").get_signature() is None
Beispiel #12
0
 def test_garbage(self):
     t = TarFile(f(b"garbage.bin"))
     assert t.handles() is False
     assert not t.f.selected
     assert not t.unpack()
     assert t.f.mode == "failed"
Beispiel #13
0
 def test_garbage(self):
     t = TarFile(f("garbage.bin"))
     assert t.handles() is False
     assert not t.f.selected
     assert not t.unpack()
     assert t.f.mode == "failed"