Skip to content

Commit

Permalink
fix: prevent delete binary files when execute unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <[email protected]>
  • Loading branch information
vitormattos authored and backportbot-libresign[bot] committed Jan 29, 2025
1 parent 26f6dcf commit 75aed24
Showing 1 changed file with 43 additions and 4 deletions.
47 changes: 43 additions & 4 deletions tests/Unit/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,42 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace Test;

/**
* Overwrite opendir in the Test namespace.
*/

function testCaseWillIgnore(string $node): bool {
$libresignPath = current(glob(\OC::$SERVERROOT . '/data/appdata_*/libresign'));
$knownEntries = [
$libresignPath . '/aarch',
$libresignPath . '/arm64',
$libresignPath . '/cfssl_config',
$libresignPath . '/x86_64',
];
foreach ($knownEntries as $ignored) {
if (str_starts_with($node, $ignored)) {
return true;
}
}
return false;
}

function rmdir($dir) {
if (testCaseWillIgnore($dir)) {
return false;
}
return \rmdir($dir);
}

function unlink($file) {
if (testCaseWillIgnore($file)) {
return false;
}
return \unlink($file);
}

namespace OCA\Libresign\Tests\Unit;

use donatj\MockWebServer\MockWebServer;
Expand Down Expand Up @@ -204,11 +240,14 @@ private function getBinariesFromCache(): void {
}

private function getFullLiresignAppFolder(): string {
$libresignPath = glob('../../data/appdata_*/libresign');
if (empty($libresignPath)) {
return '';
$path = '../../data/appdata_' . \OC_Util::getInstanceId() . '/libresign';
if (!is_dir($path)) {
mkdir($path, 0777, true);
$user = fileowner(__FILE__);
chown($path, $user);
chgrp($path, $user);
}
return realpath(current($libresignPath));
return realpath($path);
}

private function backupBinaries(): void {
Expand Down

0 comments on commit 75aed24

Please sign in to comment.