Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .ci-tools/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4818,6 +4818,16 @@ parameters:
count: 1
path: ../src/Bundle/Helper/ConfigurationHelper.php

-
rawMessage: '''
Access to constant on deprecated class Jose\Component\Encryption\Algorithm\KeyEncryption\RSA15:
since 4.3.0, will be removed in 5.0.0. The RSA1_5 algorithm moved to the "web-token/jwt-rsa15"
package: use Jose\Rsa15\KeyEncryption\RSA15 instead.
'''
identifier: classConstant.deprecatedClass
count: 1
path: ../src/Bundle/Resources/config/Algorithms/encryption_rsa15.php

-
rawMessage: '''
Access to constant on deprecated class Jose\Component\Signature\Algorithm\EdDSA:
Expand All @@ -4838,6 +4848,16 @@ parameters:
count: 1
path: ../src/Bundle/Resources/config/Algorithms/signature_experimental.php

-
rawMessage: '''
Access to constant on deprecated class Jose\Component\Signature\Algorithm\None:
since 4.3.0, will be removed in 5.0.0. The "none" algorithm moved to the "web-token/jwt-unsecured"
package: use Jose\Unsecured\Signature\None instead.
'''
identifier: classConstant.deprecatedClass
count: 1
path: ../src/Bundle/Resources/config/Algorithms/signature_none.php

-
rawMessage: Access to constant on internal class Jose\Component\Core\Util\Ecc\NistCurve.
identifier: classConstant.internalClass
Expand Down
8 changes: 8 additions & 0 deletions src/Bundle/Resources/config/Algorithms/encryption_rsa15.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use Jose\Component\Encryption\Algorithm\KeyEncryption\RSA15 as LibraryRSA15;
use Jose\Rsa15\KeyEncryption\RSA15;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

Expand All @@ -16,4 +17,11 @@
->tag('jose.algorithm', [
'alias' => 'RSA1_5',
]);

$container->set(LibraryRSA15::class)
->deprecate(
'web-token/jwt-framework',
'4.3.0',
'The "%service_id%" service is deprecated and will be removed in 5.0.0: the "RSA1_5" algorithm is now shipped by the "web-token/jwt-rsa15" package and registered as "' . RSA15::class . '", under the same "RSA1_5" alias.'
);
};
8 changes: 8 additions & 0 deletions src/Bundle/Resources/config/Algorithms/signature_none.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use Jose\Component\Signature\Algorithm\None as LibraryNone;
use Jose\Unsecured\Signature\None;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

Expand All @@ -16,4 +17,11 @@
->tag('jose.algorithm', [
'alias' => 'none',
]);

$container->set(LibraryNone::class)
->deprecate(
'web-token/jwt-framework',
'4.3.0',
'The "%service_id%" service is deprecated and will be removed in 5.0.0: the "none" algorithm is now shipped by the "web-token/jwt-unsecured" package and registered as "' . None::class . '", under the same "none" alias.'
);
};
64 changes: 64 additions & 0 deletions tests/Bundle/JoseFramework/Functional/Rsa15AlgorithmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
namespace Jose\Tests\Bundle\JoseFramework\Functional;

use Jose\Component\Core\AlgorithmManagerFactory;
use Jose\Component\Encryption\Algorithm\KeyEncryption\RSA15 as LibraryRSA15;
use Jose\Rsa15\KeyEncryption\RSA15;
use Jose\Tests\Bundle\JoseFramework\TestBundle\Service\DeprecatedRSA15Consumer;
use Jose\Tests\Bundle\JoseFramework\WebTestCase;
use PHPUnit\Framework\Attributes\Test;
use function restore_error_handler;
use function set_error_handler;
use const E_USER_DEPRECATED;

/**
* The "RSA1_5" algorithm of the jose-rsa15 package is registered by its own configuration file. That file is only
Expand Down Expand Up @@ -45,4 +50,63 @@ public function theRsa15AlgorithmIsTheOneOfTheRsa15Package(): void

static::assertInstanceOf(RSA15::class, $factory->create(['RSA1_5'])->get('RSA1_5'));
}

/**
* Until 4.2, the bundle registered the algorithm under the id of the library class, which an application could
* reference or autowire. That class moved to the jose-rsa15 package in 4.3: the "RSA1_5" alias is served by the
* class of the package, and the library class survives as a deprecated service until 5.0.0: using it triggers
* the deprecation of the service, then that of the class.
*/
#[Test]
public function theLibraryClassIsStillADeprecatedService(): void
{
static::ensureKernelShutdown();
$container = static::createClient()
->getContainer();

/** @var AlgorithmManagerFactory $factory */
$factory = $container->get(AlgorithmManagerFactory::class);
static::assertSame(RSA15::class, $factory->create(['RSA1_5'])->get('RSA1_5')::class);

$consumer = null;
$deprecations = $this->collectDeprecations(static function () use ($container, &$consumer): void {
$consumer = $container->get(DeprecatedRSA15Consumer::class);
});

static::assertInstanceOf(DeprecatedRSA15Consumer::class, $consumer);
static::assertSame(LibraryRSA15::class, $consumer->algorithm::class);
static::assertSame('RSA1_5', $consumer->algorithm->name());
static::assertCount(2, $deprecations);
static::assertSame(
'Since web-token/jwt-framework 4.3.0: The "' . LibraryRSA15::class . '" service is deprecated and will be removed in 5.0.0: the "RSA1_5" algorithm is now shipped by the "web-token/jwt-rsa15" package and registered as "' . RSA15::class . '", under the same "RSA1_5" alias.',
$deprecations[0]
);
static::assertStringStartsWith(
'Since web-token/jwt-framework 4.3.0: The class "' . LibraryRSA15::class . '" is deprecated',
$deprecations[1]
);
}

/**
* @param callable(): void $callback
*
* @return list<string>
*/
private function collectDeprecations(callable $callback): array
{
$deprecations = [];
set_error_handler(static function (int $type, string $message) use (&$deprecations): bool {
$deprecations[] = $message;

return true;
}, E_USER_DEPRECATED);

try {
$callback();
} finally {
restore_error_handler();
}

return $deprecations;
}
}
64 changes: 64 additions & 0 deletions tests/Bundle/JoseFramework/Functional/UnsecuredAlgorithmTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
namespace Jose\Tests\Bundle\JoseFramework\Functional;

use Jose\Component\Core\AlgorithmManagerFactory;
use Jose\Component\Signature\Algorithm\None as LibraryNone;
use Jose\Tests\Bundle\JoseFramework\TestBundle\Service\DeprecatedNoneConsumer;
use Jose\Tests\Bundle\JoseFramework\WebTestCase;
use Jose\Unsecured\Signature\None;
use PHPUnit\Framework\Attributes\Test;
use function restore_error_handler;
use function set_error_handler;
use const E_USER_DEPRECATED;

/**
* The "none" algorithm of the jose-unsecured package is registered by its own configuration file. That file is only
Expand Down Expand Up @@ -45,4 +50,63 @@ public function theNoneAlgorithmIsTheOneOfTheUnsecuredPackage(): void

static::assertInstanceOf(None::class, $factory->create(['none'])->get('none'));
}

/**
* Until 4.2, the bundle registered the algorithm under the id of the library class, which an application could
* reference or autowire. That class moved to the jose-unsecured package in 4.3: the "none" alias is served by the
* class of the package, and the library class survives as a deprecated service until 5.0.0: using it triggers
* the deprecation of the service, then that of the class.
*/
#[Test]
public function theLibraryClassIsStillADeprecatedService(): void
{
static::ensureKernelShutdown();
$container = static::createClient()
->getContainer();

/** @var AlgorithmManagerFactory $factory */
$factory = $container->get(AlgorithmManagerFactory::class);
static::assertSame(None::class, $factory->create(['none'])->get('none')::class);

$consumer = null;
$deprecations = $this->collectDeprecations(static function () use ($container, &$consumer): void {
$consumer = $container->get(DeprecatedNoneConsumer::class);
});

static::assertInstanceOf(DeprecatedNoneConsumer::class, $consumer);
static::assertSame(LibraryNone::class, $consumer->algorithm::class);
static::assertSame('none', $consumer->algorithm->name());
static::assertCount(2, $deprecations);
static::assertSame(
'Since web-token/jwt-framework 4.3.0: The "' . LibraryNone::class . '" service is deprecated and will be removed in 5.0.0: the "none" algorithm is now shipped by the "web-token/jwt-unsecured" package and registered as "' . None::class . '", under the same "none" alias.',
$deprecations[0]
);
static::assertStringStartsWith(
'Since web-token/jwt-framework 4.3.0: The class "' . LibraryNone::class . '" is deprecated',
$deprecations[1]
);
}

/**
* @param callable(): void $callback
*
* @return list<string>
*/
private function collectDeprecations(callable $callback): array
{
$deprecations = [];
set_error_handler(static function (int $type, string $message) use (&$deprecations): bool {
$deprecations[] = $message;

return true;
}, E_USER_DEPRECATED);

try {
$callback();
} finally {
restore_error_handler();
}

return $deprecations;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Jose\Tests\Bundle\JoseFramework\TestBundle\Checker\CustomChecker;
use Jose\Tests\Bundle\JoseFramework\TestBundle\Checker\MaximumLifetime;
use Jose\Tests\Bundle\JoseFramework\TestBundle\Service\DeprecatedES256KConsumer;
use Jose\Tests\Bundle\JoseFramework\TestBundle\Service\DeprecatedNoneConsumer;
use Jose\Tests\Bundle\JoseFramework\TestBundle\Service\DeprecatedRSA15Consumer;
use Jose\Tests\Bundle\JoseFramework\TestBundle\Service\NestedTokenServiceConsumer;
use Jose\Tests\Bundle\JoseFramework\TestBundle\Service\SelectiveDisclosureServiceConsumer;
use Psr\Clock\ClockInterface;
Expand Down Expand Up @@ -56,6 +58,14 @@
->public()
;

$container->set(DeprecatedNoneConsumer::class)
->public()
;

$container->set(DeprecatedRSA15Consumer::class)
->public()
;

$container->set(JWEDecrypterFactory::class);
$container->set(JWELoaderFactory::class)
->public()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Jose\Tests\Bundle\JoseFramework\TestBundle\Service;

use Jose\Component\Signature\Algorithm\None;

/**
* A service autowired with the deprecated "none" class of the library, which the bundle keeps until 5.0.0.
*/
final readonly class DeprecatedNoneConsumer
{
public function __construct(
public None $algorithm
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Jose\Tests\Bundle\JoseFramework\TestBundle\Service;

use Jose\Component\Encryption\Algorithm\KeyEncryption\RSA15;

/**
* A service autowired with the deprecated "RSA1_5" class of the library, which the bundle keeps until 5.0.0.
*/
final readonly class DeprecatedRSA15Consumer
{
public function __construct(
public RSA15 $algorithm
) {
}
}
Loading