HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/librepanel_corrupt/tests/Backup/DataDumpTest.php
<?php
use PHPUnit\Framework\TestCase;

use LibrePanel\Settings;
use LibrePanel\Database\Database;
use LibrePanel\Api\Commands\Customers;
use LibrePanel\Api\Commands\DataDump;

/**
 *
 * @covers \LibrePanel\Api\ApiCommand
 * @covers \LibrePanel\Api\ApiParameter
 * @covers \LibrePanel\Api\Commands\DataDump
 */
class DataDumpTest extends TestCase
{

	public function testAdminDataDumpNotEnabled()
	{
		global $admin_userdata;

		Settings::Set('system.exportenabled', 0, true);

		// get customer
		$json_result = Customers::getLocal($admin_userdata, array(
			'loginname' => 'test1'
		))->get();
		$customer_userdata = json_decode($json_result, true)['data'];
		$this->expectExceptionCode(405);
		$this->expectExceptionMessage("You cannot access this resource");
		DataDump::getLocal($customer_userdata)->add();
	}

	/**
	 *
	 * @depends testAdminDataDumpNotEnabled
	 */
	public function testAdminDataDumpExtrasHidden()
	{
		global $admin_userdata;

		Settings::Set('system.exportenabled', 1, true);
		Settings::Set('panel.customer_hide_options', 'extras', true);

		// get customer
		$json_result = Customers::getLocal($admin_userdata, array(
			'loginname' => 'test1'
		))->get();
		$customer_userdata = json_decode($json_result, true)['data'];
		$this->expectExceptionCode(405);
		$this->expectExceptionMessage("You cannot access this resource");
		DataDump::getLocal($customer_userdata)->add();
	}

	/**
	 *
	 * @depends testAdminDataDumpExtrasHidden
	 */
	public function testAdminDataDumpExtrasExportHidden()
	{
		global $admin_userdata;

		Settings::Set('panel.customer_hide_options', 'extras.export', true);

		// get customer
		$json_result = Customers::getLocal($admin_userdata, array(
			'loginname' => 'test1'
		))->get();
		$customer_userdata = json_decode($json_result, true)['data'];
		$this->expectExceptionCode(405);
		$this->expectExceptionMessage("You cannot access this resource");
		DataDump::getLocal($customer_userdata)->add();
	}

	/**
	 *
	 * @depends testAdminDataDumpExtrasExportHidden
	 */
	public function testCustomerDataDumpAdd()
	{
		global $admin_userdata;

		Settings::Set('panel.customer_hide_options', '', true);
		Database::query("TRUNCATE TABLE `panel_tasks`;");

		// get customer
		$json_result = Customers::getLocal($admin_userdata, array(
			'loginname' => 'test1'
		))->get();
		$customer_userdata = json_decode($json_result, true)['data'];

		$data = [
			'path' => '/my-dump',
			'dump_dbs' => 2,
			'dump_mail' => 3,
			'dump_web' => 4
		];
		$json_result = DataDump::getLocal($customer_userdata, $data)->add();
		$result = json_decode($json_result, true)['data'];
		$this->assertEquals($customer_userdata['documentroot'] . 'my-dump/', $result['destdir']);
		$this->assertEquals('1', $result['dump_dbs']);
		$this->assertEquals('1', $result['dump_mail']);
		$this->assertEquals('1', $result['dump_web']);
	}

	/**
	 *
	 * @depends testCustomerDataDumpAdd
	 */
	public function testCustomerDataDumpAddPathNotDocroot()
	{
		global $admin_userdata;

		// get customer
		$json_result = Customers::getLocal($admin_userdata, array(
			'loginname' => 'test1'
		))->get();
		$customer_userdata = json_decode($json_result, true)['data'];

		$data = [
			'path' => '/'
		];

		$this->expectExceptionCode(400);
		$this->expectExceptionMessage('The folder for data-dumps cannot be your homedir, please chose a folder within your homedir, e.g. /dumps');
		$json_result = DataDump::getLocal($customer_userdata, $data)->add();
	}

	public function testAdminDataDumpGet()
	{
		global $admin_userdata;
		$this->expectExceptionCode(303);
		DataDump::getLocal($admin_userdata)->get();
	}

	public function testAdminDataDumpUpdate()
	{
		global $admin_userdata;
		$this->expectExceptionCode(303);
		DataDump::getLocal($admin_userdata)->update();
	}

	/**
	 *
	 * @depends testCustomerDataDumpAdd
	 */
	public function testAdminDataDumpListing()
	{
		global $admin_userdata;

		$json_result = DataDump::getLocal($admin_userdata)->listing();
		$result = json_decode($json_result, true)['data'];
		$this->assertEquals(1, $result['count']);
		$this->assertEquals('1', $result['list'][0]['data']['dump_dbs']);
		$this->assertEquals('1', $result['list'][0]['data']['dump_mail']);
		$this->assertEquals('1', $result['list'][0]['data']['dump_web']);

		$json_result = DataDump::getLocal($admin_userdata)->listingCount();
		$result = json_decode($json_result, true)['data'];
		$this->assertEquals(1, $result);
	}

	/**
	 *
	 * @depends testCustomerDataDumpAdd
	 */
	public function testCustomerDataDumpDelete()
	{
		global $admin_userdata;

		// get customer
		$json_result = Customers::getLocal($admin_userdata, array(
			'loginname' => 'test1'
		))->get();
		$customer_userdata = json_decode($json_result, true)['data'];

		$data = [
			'job_entry' => 1
		];
		$json_result = DataDump::getLocal($customer_userdata, $data)->delete();
		$result = json_decode($json_result, true)['data'];
		$this->assertTrue($result);
	}

	/**
	 *
	 * @depends testAdminDataDumpListing
	 */
	public function testCustomerDataDumpDeleteNotFound()
	{
		global $admin_userdata;

		// get customer
		$json_result = Customers::getLocal($admin_userdata, array(
			'loginname' => 'test1'
		))->get();
		$customer_userdata = json_decode($json_result, true)['data'];

		$data = [
			'job_entry' => 1337
		];
		$this->expectExceptionCode(404);
		$this->expectExceptionMessage('Data export job with id #1337 could not be found');
		DataDump::getLocal($customer_userdata, $data)->delete();
	}
}