2018-02-11 23:32:45 +00:00
|
|
|
<?php
|
|
|
|
|
2021-01-23 20:09:16 +00:00
|
|
|
namespace Pterodactyl\Tests\Unit\Services\Acl\Api;
|
2018-02-11 23:32:45 +00:00
|
|
|
|
|
|
|
use Pterodactyl\Models\ApiKey;
|
2021-01-23 20:09:16 +00:00
|
|
|
use Pterodactyl\Tests\TestCase;
|
2018-02-11 23:32:45 +00:00
|
|
|
use Pterodactyl\Services\Acl\Api\AdminAcl;
|
|
|
|
|
|
|
|
class AdminAclTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test that permissions return the expects values.
|
|
|
|
*
|
|
|
|
* @dataProvider permissionsDataProvider
|
|
|
|
*/
|
|
|
|
public function testPermissions(int $permission, int $check, bool $outcome)
|
|
|
|
{
|
|
|
|
$this->assertSame($outcome, AdminAcl::can($permission, $check));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-13 14:50:56 +00:00
|
|
|
* Test that checking against a model works as expected.
|
2018-02-11 23:32:45 +00:00
|
|
|
*/
|
|
|
|
public function testCheck()
|
|
|
|
{
|
2021-01-23 20:09:16 +00:00
|
|
|
$model = ApiKey::factory()->make(['r_servers' => AdminAcl::READ | AdminAcl::WRITE]);
|
2018-02-11 23:32:45 +00:00
|
|
|
|
|
|
|
$this->assertTrue(AdminAcl::check($model, AdminAcl::RESOURCE_SERVERS, AdminAcl::WRITE));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provide valid and invalid permissions combos for testing.
|
|
|
|
*/
|
2023-02-23 19:30:16 +00:00
|
|
|
public static function permissionsDataProvider(): array
|
2018-02-11 23:32:45 +00:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
[AdminAcl::READ, AdminAcl::READ, true],
|
|
|
|
[AdminAcl::READ | AdminAcl::WRITE, AdminAcl::READ, true],
|
|
|
|
[AdminAcl::READ | AdminAcl::WRITE, AdminAcl::WRITE, true],
|
|
|
|
[AdminAcl::WRITE, AdminAcl::WRITE, true],
|
|
|
|
[AdminAcl::READ, AdminAcl::WRITE, false],
|
|
|
|
[AdminAcl::NONE, AdminAcl::READ, false],
|
|
|
|
[AdminAcl::NONE, AdminAcl::WRITE, false],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|