|
57 | 57 | ->and($jarTracker['installerJarRan'])->toBeFalse(); |
58 | 58 | }); |
59 | 59 |
|
60 | | -test('install aborts on zip-slip archive before running the installer', function (): void { |
61 | | - $installer = buildInstallerZipWithChecksum('cmd-slip', [ |
62 | | - ['name' => '../evil.txt', 'content' => 'pwned'], |
63 | | - ]); |
64 | | - |
65 | | - fakeInstallerDownload($installer['bytes'], $installer['sha256']); |
66 | | - |
67 | | - $jarTracker = fakeJavaProcessTrackingJar(); |
| 60 | +test('install aborts on zip-slip archive', function (bool $force, bool $seedExisting): void { |
| 61 | + $base = $seedExisting ? seedCliInstallLayout() : (string) config('verapdf.base_path'); |
68 | 62 |
|
69 | | - $this->artisan('verapdf:install') |
70 | | - ->expectsOutputToContain('unsafe ZIP entry') |
71 | | - ->assertFailed(); |
| 63 | + if ($seedExisting) { |
| 64 | + file_put_contents($base.'/bin/cli-1.30.1.jar', 'existing-cli'); |
| 65 | + } |
72 | 66 |
|
73 | | - $base = (string) config('verapdf.base_path'); |
74 | | - expect(is_file($base.'/verapdf'))->toBeFalse() |
75 | | - ->and($jarTracker['installerJarRan'])->toBeFalse(); |
76 | | - |
77 | | - File::delete($installer['path']); |
78 | | -}); |
79 | | - |
80 | | -test('install aborts on zip-slip with --force without wiping an existing install', function (): void { |
81 | | - $base = seedCliInstallLayout(); |
82 | | - file_put_contents($base.'/bin/cli-1.30.1.jar', 'existing-cli'); |
83 | | - |
84 | | - $installer = buildInstallerZipWithChecksum('cmd-force-slip', [ |
| 67 | + $installer = buildInstallerZipWithChecksum('cmd-slip', [ |
85 | 68 | ['name' => '../evil.txt', 'content' => 'pwned'], |
86 | 69 | ]); |
87 | 70 |
|
88 | 71 | fakeInstallerDownload($installer['bytes'], $installer['sha256']); |
89 | 72 |
|
90 | 73 | $jarTracker = fakeJavaProcessTrackingJar(); |
91 | 74 |
|
92 | | - $this->artisan('verapdf:install', ['--force' => true]) |
93 | | - ->expectsOutputToContain('unsafe ZIP entry') |
94 | | - ->assertFailed(); |
| 75 | + $command = $this->artisan('verapdf:install', $force ? ['--force' => true] : []); |
| 76 | + $command->expectsOutputToContain('unsafe ZIP entry')->assertFailed(); |
95 | 77 |
|
96 | | - expect(is_file($base.'/verapdf'))->toBeTrue() |
97 | | - ->and(is_file($base.'/bin/cli-1.30.1.jar'))->toBeTrue() |
98 | | - ->and((string) file_get_contents($base.'/bin/cli-1.30.1.jar'))->toBe('existing-cli') |
99 | | - ->and($jarTracker['installerJarRan'])->toBeFalse(); |
| 78 | + if ($seedExisting) { |
| 79 | + expect(is_file($base.'/verapdf'))->toBeTrue() |
| 80 | + ->and(is_file($base.'/bin/cli-1.30.1.jar'))->toBeTrue() |
| 81 | + ->and((string) file_get_contents($base.'/bin/cli-1.30.1.jar'))->toBe('existing-cli'); |
| 82 | + } else { |
| 83 | + expect(is_file($base.'/verapdf'))->toBeFalse(); |
| 84 | + } |
| 85 | + |
| 86 | + expect($jarTracker['installerJarRan'])->toBeFalse(); |
100 | 87 |
|
101 | 88 | File::delete($installer['path']); |
102 | | -}); |
| 89 | +})->with([ |
| 90 | + 'before running the installer' => [false, false], |
| 91 | + 'with --force without wiping an existing install' => [true, true], |
| 92 | +]); |
0 commit comments