CoreFiles by mySites.guru
SignatureVerifierTest.php67 lines, 2,353 bytes, from Joomla_6.3.0-alpha1-Alpha-Full_Package.zip
Raw History Compare with 6.2.0-alpha3
md5
7eeed9022a773dd7ba83410cc156441f
sha1
aee66d6d998a97d813f30ad937d7ebcd8518d4e9
sha256
50fe48b271a4d5f7df7311c004b54115a58390c2f7800347af0a38f37b741e89
<?php

namespace Tuf\Tests;

use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Tuf\Client\SignatureVerifier;
use Tuf\Exception\NotFoundException;
use Tuf\Metadata\RootMetadata;
use Tuf\Metadata\TimestampMetadata;
use Tuf\Tests\TestHelpers\FixturesTrait;

/**
 * @coversDefaultClass \Tuf\Client\SignatureVerifier
 */
class SignatureVerifierTest extends TestCase
{
    use FixturesTrait;
    use ProphecyTrait;

    /**
     * @covers ::createFromRootMetadata
     * @covers ::addKey
     */
    public function testCreateFromRootMetadata(): void
    {
        $rootJsonPath = static::getFixturePath(
            'Delegated/consistent',
            'client/metadata/current/2.root.json',
            false
        );
        $rootMetadata = RootMetadata::createFromJson(file_get_contents($rootJsonPath))
            ->trust();

        $verifier = SignatureVerifier::createFromRootMetadata($rootMetadata);
        $verifierKeys = new \ReflectionProperty($verifier, 'keys');
        $verifierKeys->setAccessible(true);
        $verifierKeys = $verifierKeys->getValue($verifier);

        // All of the root metadata keys should be loaded into the verifier.
        foreach ($rootMetadata->getKeys() as $keyId => $key) {
            $this->assertArrayHasKey($keyId, $verifierKeys);
            self::assertSame($key->getPublic(), $verifierKeys[$keyId]->getPublic());
            self::assertSame($key->getType(), $verifierKeys[$keyId]->getType());
            self::assertSame($key->getComputedKeyId(), $verifierKeys[$keyId]->getComputedKeyId());
        }
    }

    /**
     * @covers ::checkSignatures
     */
    public function testCheckSignatureWithInvalidRole(): void
    {
        $fixturePath = static::getFixturePath('Simple/consistent', 'server/metadata');

        $rootMetadata = file_get_contents($fixturePath . '/1.root.json');
        $rootMetadata = RootMetadata::createFromJson($rootMetadata)->trust();

        $timestampMetadata = $this->prophesize(TimestampMetadata::class);
        $timestampMetadata->getRole()->willReturn('unknown')->shouldBeCalled();

        $this->expectException(NotFoundException::class);
        $this->expectExceptionMessage("role not found: unknown");
        SignatureVerifier::createFromRootMetadata($rootMetadata)
            ->checkSignatures($timestampMetadata->reveal());
    }
}

The same content is in 136 releases, Joomla 5.1.0-beta1 to 6.3.0-alpha1. See them all, or every version of this file.