コード例 #1
0
ファイル: test_zipify.py プロジェクト: jbremer/sflock
def test_zipify5():
    a = unpack("tests/files/tar_plain2.tar")

    b = unpack("foo.zip", zipify(a, "notthepassword"))
    assert b.children[0].mode == "failed"

    # Fortunately sflock is capable of bruteforcing "password".
    b = unpack("foo.zip", zipify(a, "password"))
    assert len(a.children) == len(b.children)
    assert a.children[0].relapath == b.children[0].relapath
    assert a.children[0].contents == b.children[0].contents
    assert a.children[1].relapath == b.children[1].relapath
    assert a.children[1].contents == b.children[1].contents
コード例 #2
0
def test_zipify5():
    a = unpack("tests/files/tar_plain2.tar")

    b = unpack("foo.zip", zipify(a, "notthepassword"))
    assert b.children[0].mode == "failed"

    # Fortunately sflock is capable of bruteforcing "password".
    b = unpack("foo.zip", zipify(a, "password"))
    assert len(a.children) == len(b.children)
    assert a.children[0].relapath == b.children[0].relapath
    assert a.children[0].contents == b.children[0].contents
    assert a.children[1].relapath == b.children[1].relapath
    assert a.children[1].contents == b.children[1].contents
コード例 #3
0
ファイル: test_zip.py プロジェクト: doomedraven/sflock
    def test_invalid_characters(self):
        """Tests .zip files with invalid character filenames in it, which
        can't be unpacked on Windows."""
        buf = io.BytesIO()
        z = zipfile.ZipFile(buf, "w")
        z.writestr('foo"bar', "foo1")
        z.writestr("foo*bar", "foo2")
        z.writestr("foo<bar", "foo3")
        z.writestr("foo>bar", "foo4")
        z.writestr("foo?bar", "foo5")
        z.writestr("foo@bar", "foo5")
        z.writestr("1.js", "bar")
        z.close()

        dirpath = tempfile.mkdtemp()

        # Test that zipfile.ZipFile().extractall() works on our zipped
        # version after unpacking. Zipception, basically.
        f = zipify(unpack(contents=buf.getvalue()))
        zipfile.ZipFile(io.BytesIO(f)).extractall(dirpath)

        assert len(os.listdir(dirpath)) == 2
        filepath1 = os.path.join(dirpath, "foo@bar")
        filepath2 = os.path.join(dirpath, "1.js")
        assert open(filepath1, "rb").read() == b"foo5"
        assert open(filepath2, "rb").read() == b"bar"
コード例 #4
0
ファイル: test_zipify.py プロジェクト: skftn/sflock
def test_zipify4():
    a = unpack("tests/files/tar_plain2.tar")
    b = unpack("foo.zip", zipify(a))
    assert len(a.children) == len(b.children)
    assert a.children[0].filepath == b.children[0].filepath
    assert a.children[0].contents == b.children[0].contents
    assert a.children[1].filepath == b.children[1].filepath
    assert a.children[1].contents == b.children[1].contents
コード例 #5
0
ファイル: test_zipify.py プロジェクト: doomedraven/sflock
def test_zipify4():
    a = unpack(b"tests/files/tar_plain2.tar")
    b = unpack(b"foo.zip", zipify(a))
    assert len(a.children) == len(b.children)
    assert a.children[0].relapath == b.children[0].relapath
    assert a.children[0].contents == b.children[0].contents
    assert a.children[1].relapath == b.children[1].relapath
    assert a.children[1].contents == b.children[1].contents
コード例 #6
0
def test_zipify4():
    a = unpack("tests/files/tar_plain2.tar")
    b = unpack(File(contents=zipify(a)).temp_path())
    assert len(a.children) == len(b.children)
    assert a.children[0].relapath == b.children[0].relapath
    assert a.children[0].contents == b.children[0].contents
    assert a.children[1].relapath == b.children[1].relapath
    assert a.children[1].contents == b.children[1].contents
コード例 #7
0
ファイル: test_zip.py プロジェクト: doomedraven/sflock
    def test_corrupt_directory(self):
        """Tests .zip files with an incorrectly named directory in it, namely
        by its filename missing the trailing slash."""
        buf = io.BytesIO()
        z = zipfile.ZipFile(buf, "w")
        z.writestr("foo", "")
        z.writestr("foo/bar", "baz")
        z.close()

        dirpath = tempfile.mkdtemp()

        # Test that zipfile.ZipFile().extractall() works on our zipped
        # version after unpacking. Zipception, basically.
        f = zipify(unpack(contents=buf.getvalue()))
        zipfile.ZipFile(io.BytesIO(f)).extractall(dirpath)
        filepath = os.path.join(dirpath, "foo", "bar")
        assert open(filepath, "rb").read() == b"baz"
コード例 #8
0
ファイル: test_zip.py プロジェクト: doomedraven/sflock
    def test_whitespace_filename(self):
        """Tests .zip files with whitespace filenames in it, which can't be
        unpacked on Windows."""
        buf = io.BytesIO()
        z = zipfile.ZipFile(buf, "w")
        z.writestr(" ", "foo")
        z.writestr("  ", "bar")
        z.writestr("1.js", "baz")
        z.close()

        dirpath = tempfile.mkdtemp()

        # Test that zipfile.ZipFile().extractall() works on our zipped
        # version after unpacking. Zipception, basically.
        f = zipify(unpack(contents=buf.getvalue()))
        zipfile.ZipFile(io.BytesIO(f)).extractall(dirpath)
        assert len(os.listdir(dirpath)) == 3
        filepath = os.path.join(dirpath, "1.js")
        assert open(filepath, "rb").read() == b"baz"
コード例 #9
0
ファイル: test_zipify.py プロジェクト: skftn/sflock
def test_zipify3():
    a = unpack("tests/files/7z_nested2.7z")
    b = unpack("foo.zip", zipify(a))
    assert len(a.children) == len(b.children)
    assert a.children[0].filepath == b.children[0].filepath
    assert a.children[0].contents == b.children[0].contents
コード例 #10
0
ファイル: test_zipify.py プロジェクト: doomedraven/sflock
def test_zipify3():
    a = unpack(b"tests/files/7z_nested2.7z")
    b = unpack(b"foo.zip", zipify(a))
    assert len(a.children) == len(b.children)
    assert a.children[0].relapath == b.children[0].relapath
    assert a.children[0].contents == b.children[0].contents
コード例 #11
0
def test_zipify3():
    a = unpack("tests/files/7z_nested2.7z")
    b = unpack(File(contents=zipify(a)).temp_path())
    assert len(a.children) == len(b.children)
    assert a.children[0].relapath == b.children[0].relapath
    assert a.children[0].contents == b.children[0].contents
コード例 #12
0
ファイル: test_zipify.py プロジェクト: razuz/sflock
def test_zipify1():
    a = unpack("tests/files/tar_plain.tar")
    b = unpack("foo.zip", zipify(a))
    assert len(a.children) == len(b.children)
    assert a.children[0].filepath == b.children[0].filepath
    assert a.children[0].contents == b.children[0].contents
コード例 #13
0
ファイル: test_zipify.py プロジェクト: razuz/sflock
def test_zipify2():
    a = unpack("tests/files/zip_nested.zip")
    b = unpack("foo.zip", zipify(a))
    assert len(a.children) == len(b.children)
    assert a.children[0].filepath == b.children[0].filepath
    assert a.children[0].contents == b.children[0].contents
コード例 #14
0
ファイル: test_zipify.py プロジェクト: jbremer/sflock
def test_zipify2():
    a = unpack("tests/files/zip_nested.zip")
    b = unpack("foo.zip", zipify(a))
    assert len(a.children) == len(b.children)
    assert a.children[0].relapath == b.children[0].relapath
    assert a.children[0].contents == b.children[0].contents