From c073ad9a4af040e426f56c9db3027a5824da3469 Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Mon, 9 Mar 2020 20:12:01 +0100 Subject: [PATCH 1/4] Ignore .phpunit.result.cache --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fc7ea17..4b53aba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor composer.lock .DS_Store +.phpunit.result.cache From c995662758cddf789ca8dd4ead631bb12cb969bf Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Mon, 9 Mar 2020 20:12:39 +0100 Subject: [PATCH 2/4] Support for Laravel 7. Updated nelexa/zip-library. --- .travis.yml | 9 +++++++++ LICENSE.md | 2 +- README.md | 4 ++-- composer.json | 8 ++++---- src/Encryption.php | 8 ++++---- tests/BackupShieldTests.php | 20 ++++++++++++-------- 6 files changed, 32 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2119b85..0d380ff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,9 +20,18 @@ matrix: - php: 7.2.24 env: - ILLUMINATE_VERSION=6.0.* + - php: 7.2.24 + env: + - ILLUMINATE_VERSION=7.0.* - php: 7.2.24 env: - ILLUMINATE_VERSION=^6.0 - php: 7.3 env: - ILLUMINATE_VERSION=^6.0 + - php: 7.3 + env: + - ILLUMINATE_VERSION=^7.0 + - php: 7.4 + env: + - ILLUMINATE_VERSION=^7.0 diff --git a/LICENSE.md b/LICENSE.md index dad058a..558812c 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # The MIT License (MIT) -Copyright (c) 2019 Marcus Olsson +Copyright (c) 2020 Marcus Olsson > Permission is hereby granted, free of charge, to any person obtaining a copy > of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 1a6ed8a..27e7f4f 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Backup Shield simply listens for when the .zip-file generated by Laravel-backup composer require olssonm/laravel-backup-shield ``` -Requires `PHP: "^7.1"` and `laravel/framework: "^5.8"`. Compatible with Laravel 6. +Supports `laravel/framework: "^5.8"` and obove (including Laravel 6 & 7.) Requires `PHP: "^7.1"`. Please note that `spatie/laravel-backup: "^6"` and `laravel/framework: "^6.0"` requires PHP 7.2. @@ -82,7 +82,7 @@ $ phpunit The MIT License (MIT). Please see the [LICENSE.md](LICENSE.md) for more information. -© 2019 [Marcus Olsson](https://marcusolsson.me). +© 2020 [Marcus Olsson](https://marcusolsson.me). [ico-version]: https://img.shields.io/packagist/v/olssonm/laravel-backup-shield.svg?style=flat-square [ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square diff --git a/composer.json b/composer.json index 1f405cd..173149b 100644 --- a/composer.json +++ b/composer.json @@ -19,13 +19,13 @@ ], "require": { "php": ">=7.1", - "illuminate/support": "~5.8 || ^6.0", - "nelexa/zip": "^3.1", + "illuminate/support": "~5.8|^6.0|^7.0", + "nelexa/zip": "3.3", "spatie/laravel-backup": "~5.0|~6.0" }, "require-dev": { - "phpunit/phpunit": "^7.5 || ^8.0", - "orchestra/testbench": "^3.8 || ^4" + "phpunit/phpunit": "^7.5|^8.0", + "orchestra/testbench": "^3.8|^4|^5" }, "autoload": { "psr-4": { diff --git a/src/Encryption.php b/src/Encryption.php index 9efd73c..4e3c1fe 100644 --- a/src/Encryption.php +++ b/src/Encryption.php @@ -55,10 +55,10 @@ class Encryption * @var array */ private $zipFileOptions = [ - self::ENCRYPTION_DEFAULT => ZipFile::ENCRYPTION_METHOD_TRADITIONAL, - self::ENCRYPTION_WINZIP_AES_128 => ZipFile::ENCRYPTION_METHOD_WINZIP_AES_128, - self::ENCRYPTION_WINZIP_AES_192 => ZipFile::ENCRYPTION_METHOD_WINZIP_AES_192, - self::ENCRYPTION_WINZIP_AES_256 => ZipFile::ENCRYPTION_METHOD_WINZIP_AES_256, + self::ENCRYPTION_DEFAULT => \PhpZip\Constants\ZipEncryptionMethod::PKWARE, + self::ENCRYPTION_WINZIP_AES_128 => \PhpZip\Constants\ZipEncryptionMethod::WINZIP_AES_128, + self::ENCRYPTION_WINZIP_AES_192 => \PhpZip\Constants\ZipEncryptionMethod::WINZIP_AES_192, + self::ENCRYPTION_WINZIP_AES_256 => \PhpZip\Constants\ZipEncryptionMethod::WINZIP_AES_256, ]; /** diff --git a/tests/BackupShieldTests.php b/tests/BackupShieldTests.php index 16e40ee..a061c70 100644 --- a/tests/BackupShieldTests.php +++ b/tests/BackupShieldTests.php @@ -74,28 +74,32 @@ public function test_encryption_protection() // Test that the archive actually is encrypted and password protected $path = __DIR__ . '/resources/processed.zip'; + // Use Zip-file to check attributes of the file $zipFile = (new ZipFile())->openFile($path); $zipInfo = $zipFile->getAllInfo(); $this->assertEquals(true, $zipInfo['backup.zip']->isEncrypted()); $this->assertEquals('backup.zip', $zipInfo['backup.zip']->getName()); - $this->assertEquals(0, $zipInfo['backup.zip']->getEncryptionMethod()); + $this->assertEquals(1, $zipInfo['backup.zip']->getEncryptionMethod()); } /** Teardown */ public static function tearDownAfterClass(): void { // Delete config and test-files - unlink(__DIR__ . '/resources/processed.zip'); + $processedFile = __DIR__ . '/resources/processed.zip'; + if (file_exists($processedFile)) { + unlink($processedFile); + } - $configTestPath = __DIR__ . '/../vendor/orchestra/testbench-core/laravel/config/backup-shield.php'; - if (file_exists($configTestPath)) { - unlink(__DIR__ . '/../vendor/orchestra/testbench-core/laravel/config/backup-shield.php'); + $configTestFile = __DIR__ . '/../vendor/orchestra/testbench-core/laravel/config/backup-shield.php'; + if (file_exists($configTestFile)) { + unlink($configTestFile); } - $configTestPathAlt = __DIR__ . '/../vendor/orchestra/testbench-core/fixture/config/backup-shield.php'; - if (file_exists($configTestPathAlt)) { - unlink(__DIR__ . '/../vendor/orchestra/testbench-core/fixture/config/backup-shield.php'); + $configTestFileAlt = __DIR__ . '/../vendor/orchestra/testbench-core/fixture/config/backup-shield.php'; + if (file_exists($configTestFileAlt)) { + unlink($configTestFileAlt); } parent::tearDownAfterClass(); From ef468f0bddd8f93c9fcc9f75ffb401f4ff9db2fd Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Mon, 9 Mar 2020 20:28:52 +0100 Subject: [PATCH 3/4] Test for encrypter engine. --- tests/BackupShieldTests.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/BackupShieldTests.php b/tests/BackupShieldTests.php index a061c70..2defe2a 100644 --- a/tests/BackupShieldTests.php +++ b/tests/BackupShieldTests.php @@ -68,6 +68,25 @@ public function test_listener_return_data() $this->assertEquals($pathTest, $data[0]); } + /** @test **/ + public function test_correct_encrypter_engine() + { + $path = __DIR__ . '/resources/processed.zip'; + + // Use Zip-file to check attributes of the file + $zipFile = (new ZipFile())->openFile($path); + $zipInfo = $zipFile->getAllInfo(); + + // Assume PHP 7.2 and supporter ZipArchive + if (class_exists('ZipArchive') && in_array('setEncryptionIndex', get_class_methods('ZipArchive'))) { + $this->assertEquals(9, $zipInfo['backup.zip']->getCompressionLevel()); // 9 = ZipArchive + } + // Fallback on ZipFile + else { + $this->assertEquals(5, $zipInfo['backup.zip']->getCompressionLevel()); // 5 = ZipFile + } + } + /** @test **/ public function test_encryption_protection() { From d4fe826882edaf5bea0dc52788be78f3827236f8 Mon Sep 17 00:00:00 2001 From: Marcus Olsson Date: Tue, 10 Mar 2020 08:41:25 +0100 Subject: [PATCH 4/4] Copy-tweaks. --- README.md | 6 +++--- src/config/backup-shield.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 27e7f4f..c41ca99 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,9 @@ Backup Shield simply listens for when the .zip-file generated by Laravel-backup composer require olssonm/laravel-backup-shield ``` -Supports `laravel/framework: "^5.8"` and obove (including Laravel 6 & 7.) Requires `PHP: "^7.1"`. +Supports `laravel/framework: "^5.8"` and above (including Laravel 6 & 7.) Requires `PHP: "^7.1"`. -Please note that `spatie/laravel-backup: "^6"` and `laravel/framework: "^6.0"` requires PHP 7.2. +Please note that `spatie/laravel-backup: "^6"` and `laravel/framework: "^6.0|^7.0"` requires PHP 7.2. ## Configuration @@ -41,7 +41,7 @@ return [ #### Password -Your password (*duh*). The default is the application key (`APP_KEY` in your .env-file). You might want to set something more appropriate. Remember to use long strings and to keep your password safe – without it you will never be able to open your backup. +Your password (*duh*). The default is the application key (`APP_KEY` in your .env-file). You might want to set something more appropriate. Remember to use long strings and to keep your password safe – **without it you will never be able to open your backup**. Set to `NULL` if you want to keep your backup without a password. diff --git a/src/config/backup-shield.php b/src/config/backup-shield.php index 5c49b0f..60574e0 100644 --- a/src/config/backup-shield.php +++ b/src/config/backup-shield.php @@ -5,7 +5,7 @@ 'encryption' => \Olssonm\BackupShield\Encryption::ENCRYPTION_DEFAULT // Available encryption methods: - // \Olssonm\BackupShield\Encryption::ENCRYPTION_DEFAULT (PHP < 7.2: PKWARE/ZipCrypto, PHP >= 7.2 AES 128) + // \Olssonm\BackupShield\Encryption::ENCRYPTION_DEFAULT (PHP < 7.2: PKWARE/ZipCrypto, PHP >= 7.2: AES 128) // \Olssonm\BackupShield\Encryption::ENCRYPTION_WINZIP_AES_128 (AES 128) // \Olssonm\BackupShield\Encryption::ENCRYPTION_WINZIP_AES_192 (AES 192) // \Olssonm\BackupShield\Encryption::ENCRYPTION_WINZIP_AES_256 (AES 256)