Exemplo n.º 1
0
    def test_rar_decryption_fail(self):
        z = RarFile(f("sflock_encrypted2.rar"))
        assert z.handles() is True
        assert not z.f.selected

        with pytest.raises(DecryptionFailedError) as e:
            z.unpack()
Exemplo n.º 2
0
def test_norar_plain():
    assert "RAR archive" in f("rar_plain.rar").magic
    t = RarFile(f("rar_plain.rar"))
    assert t.handles() is True

    with pytest.raises(UnpackException):
        t.unpack()
Exemplo n.º 3
0
    def test_garbage(self):
        t = RarFile(f("garbage.bin"))
        assert t.handles() is False
        assert not t.f.selected
        with pytest.raises(UnpackException) as e:
            t.unpack()

        assert e.value.state == Errors.NOTHING_EXTRACTED
Exemplo n.º 4
0
 def test_garbage2(self):
     t = RarFile(f("rar_garbage.rar"))
     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"
Exemplo n.º 5
0
 def test_garbage2(self):
     t = RarFile(f(b"rar_garbage.rar"))
     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"
Exemplo n.º 6
0
    def test_garbage2(self):
        t = RarFile(f("rar_garbage.rar"))
        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
Exemplo n.º 7
0
 def test_rar_encrypted(self):
     assert "RAR archive" in f("sflock_encrypted.rar").magic
     z = RarFile(f("sflock_encrypted.rar"))
     assert z.handles() is True
     files = list(z.unpack("infected"))
     assert len(files) == 1
     assert files[0].filepath == "sflock.txt"
     assert files[0].contents == "sflock_encrypted_rar"
     assert files[0].password == "infected"
     assert "ASCII text" in files[0].magic
     assert files[0].parentdirs == []
Exemplo n.º 8
0
 def test_plain(self):
     assert "RAR archive" in f("rar_plain.rar").magic
     t = RarFile(f("rar_plain.rar"))
     assert t.handles() is True
     assert not t.f.selected
     files = list(t.unpack())
     assert len(files) == 1
     assert files[0].relapath == "bar.txt"
     assert files[0].contents == "hello world\n"
     assert files[0].magic == "ASCII text"
     assert files[0].parentdirs == []
     assert not files[0].selected
Exemplo n.º 9
0
 def test_rar_encrypted(self):
     assert "RAR archive" in f("sflock_encrypted.rar").magic
     z = RarFile(f("sflock_encrypted.rar"))
     assert z.handles() is True
     assert not z.f.selected
     files = list(z.unpack())
     assert len(files) == 1
     assert files[0].relapath == "sflock.txt"
     assert files[0].contents == b"sflock_encrypted_rar"
     assert "ASCII text" in files[0].magic
     assert files[0].parentdirs == []
     assert not files[0].selected
Exemplo n.º 10
0
 def test_plain(self):
     assert "RAR archive" in f("rar_plain.rar").magic
     t = RarFile(f("rar_plain.rar"))
     assert t.handles() is True
     assert not t.f.selected
     files = list(t.unpack())
     assert len(files) == 1
     assert files[0].relapath == "bar.txt"
     assert files[0].contents == "hello world\n"
     assert files[0].magic == "ASCII text"
     assert files[0].parentdirs == []
     assert not files[0].selected
Exemplo n.º 11
0
    def test_nested2_plain(self):
        assert "RAR archive" in f(b"rar_nested2.rar").magic
        t = RarFile(f(b"rar_nested2.rar"))
        assert t.handles() is True
        assert not t.f.selected
        files = list(t.unpack())
        assert len(files) == 1

        assert files[0].relapath == b"deepfoo/foo/bar.txt"
        assert files[0].parentdirs == [b"deepfoo", 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
Exemplo n.º 12
0
    def test_plain(self):
        assert "RAR archive" in f("rar_plain.rar").magic
        t = RarFile(f("rar_plain.rar"))
        assert t.handles() is True
        files = list(t.unpack())
        assert len(files) == 1
        assert files[0].filepath == "bar.txt"
        assert files[0].contents == "hello world\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("rar_plain.rar").get_signature() is None
Exemplo n.º 13
0
    def test_plain(self):
        assert "RAR archive" in f("rar_plain.rar").magic
        t = RarFile(f("rar_plain.rar"))
        assert t.handles() is True
        files = list(t.unpack())
        assert len(files) == 1
        assert files[0].filepath == "bar.txt"
        assert files[0].contents == "hello world\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("rar_plain.rar").get_signature() is None
Exemplo n.º 14
0
    def test_nested2_plain(self):
        assert "RAR archive" in f("rar_nested2.rar").magic
        t = RarFile(f("rar_nested2.rar"))
        assert t.handles() is True
        files = list(t.unpack())
        assert len(files) == 1

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

        s = f("rar_nested2.rar").get_signature()
        assert s is None
Exemplo n.º 15
0
    def test_nested2_plain(self):
        assert "RAR archive" in f("rar_nested2.rar").magic
        t = RarFile(f("rar_nested2.rar"))
        assert t.handles() is True
        files = list(t.unpack())
        assert len(files) == 1

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

        s = f("rar_nested2.rar").get_signature()
        assert s is None
Exemplo n.º 16
0
 def test_garbage(self):
     t = RarFile(f(b"garbage.bin"))
     assert t.handles() is False
     assert not t.f.selected
     assert not t.unpack()
     assert t.f.mode == "failed"
Exemplo n.º 17
0
    def test_garbage(self):
        t = RarFile(f("garbage.bin"))
        assert t.handles() is False

        with pytest.raises(UnpackException):
            t.unpack()
Exemplo n.º 18
0
 def test_garbage(self):
     t = RarFile(f("garbage.bin"))
     assert t.handles() is False
     assert not t.f.selected
     assert not t.unpack()
     assert t.f.mode == "failed"