From f18e798fa0a9954d30c55ab075622fa6c2085910 Mon Sep 17 00:00:00 2001 From: Vadim Lebedev Date: Tue, 9 Aug 2022 21:03:28 +0200 Subject: [PATCH] Fix to test for password protection --- .github/workflows/build-wheels.yaml | 104 ---------------------------- libarchive/zip.py | 2 +- tests.py | 19 +++++ 3 files changed, 20 insertions(+), 105 deletions(-) delete mode 100644 .github/workflows/build-wheels.yaml diff --git a/.github/workflows/build-wheels.yaml b/.github/workflows/build-wheels.yaml deleted file mode 100644 index ad0a5c6..0000000 --- a/.github/workflows/build-wheels.yaml +++ /dev/null @@ -1,104 +0,0 @@ -name: build-wheels - -on: - workflow_dispatch: - branches: - - master - - extended - -env: - libarchive_tag: v3.6.1 - -jobs: - many_linux_wheels: - name: manylinux-wheels - runs-on: ubuntu-latest - container: quay.io/pypa/manylinux2014_x86_64 - steps: - - uses: actions/checkout@v2 - - - name: Print System Information - run: | - echo "uname -a: $( uname -a )" - cat /etc/issue - echo "Shell: $SHELL" - echo "Mount points:"; mount - echo "nproc: $( nproc )" - env - - - name: Chose Python version - run: | - ln -s /opt/python/cp39-cp39/bin/python3 /usr/local/bin/python3 - export PATH="/opt/python/cp39-cp39/bin:$PATH" - - - name: Install dependencies - run: | - yum install -y epel-release libxml2-devel libzstd-devel xz-devel bzip2-devel - yum install -y libacl-devel lz4-devel e2fsprogs-devel libb2-devel lzo-devel openssl-devel - yum install -y librichacl-devel swig strace - - - name: Install python tools - run: | - python3 -m pip install pytest auditwheel - - - - name: Build libarchive C sources - run: | - git clone https://github.com/libarchive/libarchive.git libarchive-src - cd libarchive-src; git checkout ${{ env.libarchive_tag }} - mkdir build-libarchive; cd build-libarchive - cmake ../ - make -j$(nproc); make install - cd ../.. - - - - name: Prepare build environment - run: | - rm -rf build wheelhouse - touch libarchive/_libarchive.i - echo LD_LIBRARY_PATH=/usr/local/lib64/:/usr/local/lib:$LD_LIBRARY_PATH >>$GITHUB_ENV - echo LIBARCHIVE_PREFIX=/usr/local >>$GITHUB_ENV - - - name: Compile pyhton modules - run: | - python3 setup.py install - - - - name: Build wheels - run: | - python3 -m pip wheel --wheel-dir dist/ . - auditwheel repair dist/*.whl - python3 -m pip install --force-reinstall wheelhouse/*.whl - - - name: version - run: | - echo "::set-output name=version::$(cd /tmp; python3 -c 'import libarchive; print(libarchive.version())')" - id: version - - - uses: actions/upload-artifact@v3 - with: - name: python_libarchive_ext-${{ steps.version.outputs.version }}-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - path: ./wheelhouse/python_libarchive_ext-${{ steps.version.outputs.version }}-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - - - - name: release - uses: actions/create-release@v1 - id: create_release - with: - draft: false - prerelease: false - release_name: Release ${{ steps.version.outputs.version }} - tag_name: V${{ steps.version.outputs.version }}-${{ github.ref_name }}-${{ github.run_number }} - env: - GITHUB_TOKEN: ${{ github.token }} - - - name: upload artifact - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ github.token }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./wheelhouse/python_libarchive_ext-${{ steps.version.outputs.version }}-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - asset_name: python_libarchive_ext-${{ steps.version.outputs.version }}-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl - asset_content_type: application/zip - \ No newline at end of file diff --git a/libarchive/zip.py b/libarchive/zip.py index 62fe4c1..be65386 100644 --- a/libarchive/zip.py +++ b/libarchive/zip.py @@ -106,7 +106,7 @@ class ZipFile(SeekableArchive): def read(self, name, pwd=None): if pwd: self.add_passphrase(pwd) - return self.read(name) + return super(ZipFile, self).read(name) def writestr(self, member, data, compress_type=None): if compress_type != self.compression: diff --git a/tests.py b/tests.py index bf6cb61..bc3fdc4 100644 --- a/tests.py +++ b/tests.py @@ -182,6 +182,25 @@ class TestZipWrite(unittest.TestCase): with open(os.path.join(TMPDIR, fname), 'r') as f: z.writepath(f) z.close() + self.f.close() + + + nz = ZipFile(ZIPPATH, 'r', password='test') + for fname in FILENAMES: + ffname = os.path.join(TMPDIR, fname) + with open(ffname, 'r') as f: + self.assertEqual(f.read(), nz.read(ffname)) + + nz.close() + + nz = ZipFile(ZIPPATH, 'r') + with self.assertRaises(Exception) as ctx: + ffname = os.path.join(TMPDIR, FILENAMES[0]) + with open(ffname, 'r') as f: + self.assertEqual(f.read(), nz.read(ffname)) + nz.close() + + def test_writepath_directory(self): """Test writing a directory."""