-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JWECollector tests for builders, decrypters, and loaders
Introduce functional tests for `JWECollector` to verify support for JWE builders, decrypters, and loaders without requiring a compression method manager. These tests ensure proper data collection and structure validation for the `JWECollector` in various configurations.
- Loading branch information
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
tests/Bundle/JoseFramework/Functional/Encryption/JWECollectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jose\Tests\Bundle\JoseFramework\Functional\Encryption; | ||
|
||
use Jose\Bundle\JoseFramework\DataCollector\JWECollector; | ||
use Jose\Bundle\JoseFramework\Services\JWEBuilderFactory as JWEBuilderFactoryService; | ||
use Jose\Bundle\JoseFramework\Services\JWEDecrypterFactory as JWEDecrypterFactoryService; | ||
use Jose\Bundle\JoseFramework\Services\JWELoaderFactory as JWELoaderFactoryAlias; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class JWECollectorTest extends WebTestCase | ||
{ | ||
#[Test] | ||
public function aJWEBuilderCanBeCollectedWithoutACompressionMethodManager(): void | ||
{ | ||
static::ensureKernelShutdown(); | ||
$client = static::createClient(); | ||
$container = $client->getContainer(); | ||
static::assertInstanceOf(ContainerInterface::class, $container); | ||
|
||
$jweFactory = $container->get(JWEBuilderFactoryService::class); | ||
static::assertInstanceOf(JWEBuilderFactoryService::class, $jweFactory); | ||
|
||
$jweBuilder = $jweFactory->create(['RSA1_5', 'A256GCM']); | ||
|
||
$jweCollector = new JWECollector(); | ||
$jweCollector->addJWEBuilder('builder2', $jweBuilder); | ||
|
||
$data = []; | ||
$jweCollector->collect($data, new Request(), new Response()); | ||
|
||
static::assertArrayHasKey('jwe', $data); | ||
static::assertArrayNotHasKey('compression_methods', $data['jwe']); | ||
static::assertArrayHasKey('jwe_builders', $data['jwe']); | ||
static::assertArrayHasKey('builder2', $data['jwe']['jwe_builders']); | ||
} | ||
|
||
#[Test] | ||
public function aJWEDecrypterCanBeCollectedWithoutACompressionMethodManager(): void | ||
{ | ||
static::ensureKernelShutdown(); | ||
$client = static::createClient(); | ||
$container = $client->getContainer(); | ||
static::assertInstanceOf(ContainerInterface::class, $container); | ||
|
||
$jweDecrypterFactory = $container->get(JWEDecrypterFactoryService::class); | ||
static::assertInstanceOf(JWEDecrypterFactoryService::class, $jweDecrypterFactory); | ||
|
||
$jweDecrypter = $jweDecrypterFactory->create(['RSA1_5', 'A256GCM']); | ||
|
||
$jweCollector = new JWECollector(); | ||
$jweCollector->addJWEDecrypter('decrypter2', $jweDecrypter); | ||
|
||
$data = []; | ||
$jweCollector->collect($data, new Request(), new Response()); | ||
|
||
static::assertArrayHasKey('jwe', $data); | ||
static::assertArrayNotHasKey('compression_methods', $data['jwe']); | ||
|
||
static::assertArrayHasKey('jwe_decrypters', $data['jwe']); | ||
static::assertArrayHasKey('decrypter2', $data['jwe']['jwe_decrypters']); | ||
} | ||
|
||
#[Test] | ||
public function aJWELoaderCanBeCollectedWithoutACompressionMethodManager(): void | ||
{ | ||
static::ensureKernelShutdown(); | ||
$client = static::createClient(); | ||
$container = $client->getContainer(); | ||
static::assertInstanceOf(ContainerInterface::class, $container); | ||
|
||
$jweLoaderFactory = $container->get(JWELoaderFactoryAlias::class); | ||
static::assertInstanceOf(JWELoaderFactoryAlias::class, $jweLoaderFactory); | ||
|
||
$jweLoader = $jweLoaderFactory->create(['jwe_compact'], ['RSA1_5', 'A256GCM']); | ||
|
||
$jweCollector = new JWECollector(); | ||
$jweCollector->addJWELoader('loader2', $jweLoader); | ||
|
||
$data = []; | ||
$jweCollector->collect($data, new Request(), new Response()); | ||
|
||
static::assertArrayHasKey('jwe', $data); | ||
static::assertArrayNotHasKey('compression_methods', $data['jwe']); | ||
static::assertArrayHasKey('jwe_loaders', $data['jwe']); | ||
static::assertArrayHasKey('loader2', $data['jwe']['jwe_loaders']); | ||
} | ||
} |