Skip to content

Commit 5926524

Browse files
authored
Merge pull request #4542 from LibreSign/fix/prevent-delete-binary-files-when-execute-unit-tests
fix: prevent delete binary files when execute unit tests
2 parents e545836 + 5a071ac commit 5926524

1 file changed

Lines changed: 43 additions & 4 deletions

File tree

tests/Unit/TestCase.php

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,42 @@
66
* SPDX-License-Identifier: AGPL-3.0-or-later
77
*/
88

9+
namespace Test;
10+
11+
/**
12+
* Overwrite opendir in the Test namespace.
13+
*/
14+
15+
function testCaseWillIgnore(string $node): bool {
16+
$libresignPath = current(glob(\OC::$SERVERROOT . '/data/appdata_*/libresign'));
17+
$knownEntries = [
18+
$libresignPath . '/aarch',
19+
$libresignPath . '/arm64',
20+
$libresignPath . '/cfssl_config',
21+
$libresignPath . '/x86_64',
22+
];
23+
foreach ($knownEntries as $ignored) {
24+
if (str_starts_with($node, $ignored)) {
25+
return true;
26+
}
27+
}
28+
return false;
29+
}
30+
31+
function rmdir($dir) {
32+
if (testCaseWillIgnore($dir)) {
33+
return false;
34+
}
35+
return \rmdir($dir);
36+
}
37+
38+
function unlink($file) {
39+
if (testCaseWillIgnore($file)) {
40+
return false;
41+
}
42+
return \unlink($file);
43+
}
44+
945
namespace OCA\Libresign\Tests\Unit;
1046

1147
use donatj\MockWebServer\MockWebServer;
@@ -204,11 +240,14 @@ private function getBinariesFromCache(): void {
204240
}
205241

206242
private function getFullLiresignAppFolder(): string {
207-
$libresignPath = glob('../../data/appdata_*/libresign');
208-
if (empty($libresignPath)) {
209-
return '';
243+
$path = '../../data/appdata_' . \OC_Util::getInstanceId() . '/libresign';
244+
if (!is_dir($path)) {
245+
mkdir($path, 0777, true);
246+
$user = fileowner(__FILE__);
247+
chown($path, $user);
248+
chgrp($path, $user);
210249
}
211-
return realpath(current($libresignPath));
250+
return realpath($path);
212251
}
213252

214253
private function backupBinaries(): void {

0 commit comments

Comments
 (0)