__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
namespace Tuf\Tests\Unit;
use PHPUnit\Framework\TestCase;
use Tuf\Exception\MetadataException;
use Tuf\Role;
/**
* @coversDefaultClass \Tuf\Role
*/
class RoleTest extends TestCase
{
/**
* The test role.
*
* @var \Tuf\Role
*/
protected $role;
/**
* @covers ::createFromMetadata
* @covers ::getName
* @covers ::getThreshold
*/
public function testCreateFromMetadata(): void
{
$this->role = $this->createTestRole();
self::assertSame(1000, $this->role->getThreshold());
self::assertSame('my_role', $this->role->getName());
}
/**
* @covers ::createFromMetadata
*
* @param $data
* Invalid data.
*
* @dataProvider providerInvalidMetadata
*/
public function testInvalidMetadata($data): void
{
$this->expectException(MetadataException::class);
$this->createTestRole($data);
}
/**
* Data provider for testInvalidMetadata().
*
* @return array[]
*/
public function providerInvalidMetadata(): array
{
return [
'nothing' => [[]],
'no keyids' => [['threshold' => 1]],
'no threshold' => [['keyids' => ['good_key']]],
'invalid threshold' => [['threshold' => '1', 'keyids' => ['good_key']]],
'invalid keyids' => [['threshold' => 1, 'keyids' => 'good_key_1,good_key_2']],
'extra field' => [['threshold' => 1, 'keyids' => ['good_key'], 'extra_field' => 1]],
];
}
/**
* @covers ::isKeyIdAcceptable
*
* @param string $keyId
* @param bool $expected
*
* @dataProvider providerIsKeyIdAcceptable
*/
public function testIsKeyIdAcceptable(string $keyId, bool $expected): void
{
self::assertSame($expected, $this->createTestRole()->isKeyIdAcceptable($keyId));
}
/**
* Data provider for testIsKeyIdAcceptable().
*
* @return array[]
*/
public function providerIsKeyIdAcceptable(): array
{
return [
['good_key_1', true],
['good_key_2', true],
['bad_key', false],
];
}
/**
* Creates a test role.
*
* @param array|null $data
* The data for the role or null.
*
* @return \Tuf\Role
*/
protected function createTestRole(?array $data = null): Role
{
$data = $data ?? [
'threshold' => 1000,
'keyids' => [
'good_key_1',
'good_key_2',
]
];
return Role::createFromMetadata($data, 'my_role');
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| Client | Folder | 0775 |
|
|
| CanonicalJsonTraitTest.php | File | 3.16 KB | 0664 |
|
| DelegatedRoleTest.php | File | 5.39 KB | 0664 |
|
| FileStorageTest.php | File | 5.03 KB | 0664 |
|
| KeyTest.php | File | 1.59 KB | 0664 |
|
| RepositoryTest.php | File | 2.43 KB | 0664 |
|
| RoleTest.php | File | 2.58 KB | 0664 |
|
| SizeCheckingLoaderTest.php | File | 4.46 KB | 0664 |
|