Skip to content

Commit fc1dbeb

Browse files
committed
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.
1 parent 4884c36 commit fc1dbeb

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Jose\Tests\Bundle\JoseFramework\Functional\Encryption;
6+
7+
use Jose\Bundle\JoseFramework\DataCollector\JWECollector;
8+
use Jose\Bundle\JoseFramework\Services\JWEBuilderFactory as JWEBuilderFactoryService;
9+
use Jose\Bundle\JoseFramework\Services\JWEDecrypterFactory as JWEDecrypterFactoryService;
10+
use Jose\Bundle\JoseFramework\Services\JWELoaderFactory as JWELoaderFactoryAlias;
11+
use PHPUnit\Framework\Attributes\Test;
12+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
13+
use Symfony\Component\DependencyInjection\ContainerInterface;
14+
use Symfony\Component\HttpFoundation\Request;
15+
use Symfony\Component\HttpFoundation\Response;
16+
17+
/**
18+
* @internal
19+
*/
20+
final class JWECollectorTest extends WebTestCase
21+
{
22+
#[Test]
23+
public function aJWEBuilderCanBeCollectedWithoutACompressionMethodManager(): void
24+
{
25+
static::ensureKernelShutdown();
26+
$client = static::createClient();
27+
$container = $client->getContainer();
28+
static::assertInstanceOf(ContainerInterface::class, $container);
29+
30+
$jweFactory = $container->get(JWEBuilderFactoryService::class);
31+
static::assertInstanceOf(JWEBuilderFactoryService::class, $jweFactory);
32+
33+
$jweBuilder = $jweFactory->create(['RSA1_5', 'A256GCM']);
34+
35+
$jweCollector = new JWECollector();
36+
$jweCollector->addJWEBuilder('builder2', $jweBuilder);
37+
38+
$data = [];
39+
$jweCollector->collect($data, new Request(), new Response());
40+
41+
static::assertArrayHasKey('jwe', $data);
42+
static::assertArrayNotHasKey('compression_methods', $data['jwe']);
43+
static::assertArrayHasKey('jwe_builders', $data['jwe']);
44+
static::assertArrayHasKey('builder2', $data['jwe']['jwe_builders']);
45+
}
46+
47+
#[Test]
48+
public function aJWEDecrypterCanBeCollectedWithoutACompressionMethodManager(): void
49+
{
50+
static::ensureKernelShutdown();
51+
$client = static::createClient();
52+
$container = $client->getContainer();
53+
static::assertInstanceOf(ContainerInterface::class, $container);
54+
55+
$jweDecrypterFactory = $container->get(JWEDecrypterFactoryService::class);
56+
static::assertInstanceOf(JWEDecrypterFactoryService::class, $jweDecrypterFactory);
57+
58+
$jweDecrypter = $jweDecrypterFactory->create(['RSA1_5', 'A256GCM']);
59+
60+
$jweCollector = new JWECollector();
61+
$jweCollector->addJWEDecrypter('decrypter2', $jweDecrypter);
62+
63+
$data = [];
64+
$jweCollector->collect($data, new Request(), new Response());
65+
66+
static::assertArrayHasKey('jwe', $data);
67+
static::assertArrayNotHasKey('compression_methods', $data['jwe']);
68+
69+
static::assertArrayHasKey('jwe_decrypters', $data['jwe']);
70+
static::assertArrayHasKey('decrypter2', $data['jwe']['jwe_decrypters']);
71+
}
72+
73+
#[Test]
74+
public function aJWELoaderCanBeCollectedWithoutACompressionMethodManager(): void
75+
{
76+
static::ensureKernelShutdown();
77+
$client = static::createClient();
78+
$container = $client->getContainer();
79+
static::assertInstanceOf(ContainerInterface::class, $container);
80+
81+
$jweLoaderFactory = $container->get(JWELoaderFactoryAlias::class);
82+
static::assertInstanceOf(JWELoaderFactoryAlias::class, $jweLoaderFactory);
83+
84+
$jweLoader = $jweLoaderFactory->create(['jwe_compact'], ['RSA1_5', 'A256GCM']);
85+
86+
$jweCollector = new JWECollector();
87+
$jweCollector->addJWELoader('loader2', $jweLoader);
88+
89+
$data = [];
90+
$jweCollector->collect($data, new Request(), new Response());
91+
92+
static::assertArrayHasKey('jwe', $data);
93+
static::assertArrayNotHasKey('compression_methods', $data['jwe']);
94+
static::assertArrayHasKey('jwe_loaders', $data['jwe']);
95+
static::assertArrayHasKey('loader2', $data['jwe']['jwe_loaders']);
96+
}
97+
}

0 commit comments

Comments
 (0)