From 89092877641e27ed37dcec9609220e136ae6efeb Mon Sep 17 00:00:00 2001 From: Augustas Nedzinskas Date: Mon, 7 Oct 2024 16:24:36 +0200 Subject: [PATCH 1/5] feat: key read update according to flysystem upgrade --- models/classes/ExceptionInterpreter.php | 2 +- .../Repository/PlatformKeyChainRepository.php | 54 +++++++++++-------- .../PlatformKeyChainRepositoryTest.php | 4 +- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/models/classes/ExceptionInterpreter.php b/models/classes/ExceptionInterpreter.php index 13b33dc1..5a722b6c 100644 --- a/models/classes/ExceptionInterpreter.php +++ b/models/classes/ExceptionInterpreter.php @@ -77,6 +77,6 @@ private function log($msg) ->get(FileSystemService::SERVICE_ID) ->getFileSystem(self::FILESYSTEM_ID_TO_LOG); - $fs->put('lti_' . $this->exception->getKey() . '.log', $msg); + $fs->write('lti_' . $this->exception->getKey() . '.log', $msg); } } diff --git a/models/classes/Security/DataAccess/Repository/PlatformKeyChainRepository.php b/models/classes/Security/DataAccess/Repository/PlatformKeyChainRepository.php index 11c8d235..7b042b97 100644 --- a/models/classes/Security/DataAccess/Repository/PlatformKeyChainRepository.php +++ b/models/classes/Security/DataAccess/Repository/PlatformKeyChainRepository.php @@ -23,7 +23,8 @@ namespace oat\taoLti\models\classes\Security\DataAccess\Repository; use common_exception_NoImplementation; -use League\Flysystem\FilesystemInterface; +use League\Flysystem\FilesystemException; +use League\Flysystem\FilesystemOperator; use OAT\Library\Lti1p3Core\Security\Key\Key; use OAT\Library\Lti1p3Core\Security\Key\KeyChain; use OAT\Library\Lti1p3Core\Security\Key\KeyChainInterface; @@ -69,25 +70,23 @@ protected function save(KeyChainInterface $keyChain, string $identifier): void $publicKeyPath = $configs[self::OPTION_DEFAULT_PUBLIC_KEY_PATH] ?? null; $privateKeyPath = $configs[self::OPTION_DEFAULT_PRIVATE_KEY_PATH] ?? null; - $isPublicKeySaved = false; - $isPrivateKeySaved = false; if ($publicKeyPath !== null && $privateKeyPath !== null) { - $isPublicKeySaved = $this->getFileSystem() - ->put( - ltrim($publicKeyPath, DIRECTORY_SEPARATOR), - $keyChain->getPublicKey()->getContent() - ); - - $isPrivateKeySaved = $this->getFileSystem() - ->put( - ltrim($privateKeyPath, DIRECTORY_SEPARATOR), - $keyChain->getPrivateKey()->getContent() - ); - } - - if (!$isPublicKeySaved || !$isPrivateKeySaved) { - throw new PlatformKeyChainException('Impossible to write LTI keys'); + try { + $this->getFileSystem() + ->write( + ltrim($publicKeyPath, DIRECTORY_SEPARATOR), + $keyChain->getPublicKey()->getContent() + ); + + $this->getFileSystem() + ->write( + ltrim($privateKeyPath, DIRECTORY_SEPARATOR), + $keyChain->getPrivateKey()->getContent() + ); + } catch (\Exception $e) { + throw new PlatformKeyChainException('Impossible to write LTI keys', 0, $e); + } } } @@ -114,8 +113,8 @@ public function find(string $identifier): ?KeyChainInterface throw new PlatformKeyChainException('The key path is not defined'); } - $publicKey = $this->getFileSystem()->read($publicKeyPath); - $privateKey = $this->getFileSystem()->read($privateKeyPath); + $publicKey = $this->readKey($publicKeyPath); + $privateKey = $this->readKey($privateKeyPath); if ($publicKey === false || $privateKey === false) { throw new PlatformKeyChainException('Impossible to read LTI keys'); @@ -140,8 +139,8 @@ public function findAll(KeyChainQuery $query): KeyChainCollection $privateKeyPassphrase = $configs[self::OPTION_DEFAULT_PRIVATE_KEY_PASSPHRASE] ?? null; if ($defaultKeyId && $publicKeyPath && $privateKeyPath) { - $publicKey = $this->getFileSystem()->read($publicKeyPath); - $privateKey = $this->getFileSystem()->read($privateKeyPath); + $publicKey = $this->readKey($publicKeyPath); + $privateKey = $this->readKey($privateKeyPath); $keyChains[] = new TaoKeyChain( $defaultKeyId, @@ -168,7 +167,16 @@ public function findByKeySetName(string $keySetName): array throw new common_exception_NoImplementation(); } - private function getFileSystem(): FilesystemInterface + private function readKey(string $path): string + { + try { + return $this->getFileSystem()->read($path); + } catch (FilesystemException $e) { + throw new PlatformKeyChainException('Impossible to read LTI keys'); + } + } + + private function getFileSystem(): FilesystemOperator { /** @var FileSystemService $fileSystemService */ $fileSystemService = $this->getServiceLocator() diff --git a/test/unit/models/classes/Security/DataAccess/Repository/PlatformKeyChainRepositoryTest.php b/test/unit/models/classes/Security/DataAccess/Repository/PlatformKeyChainRepositoryTest.php index e16b5988..44767e13 100644 --- a/test/unit/models/classes/Security/DataAccess/Repository/PlatformKeyChainRepositoryTest.php +++ b/test/unit/models/classes/Security/DataAccess/Repository/PlatformKeyChainRepositoryTest.php @@ -147,7 +147,7 @@ public function testFindWithEmptyPathFails(): void public function testSaveDefaultKeyChain(): void { $this->fileSystem - ->method('put') + ->method('write') ->willReturn(true); $this->subject->saveDefaultKeyChain( @@ -160,7 +160,7 @@ public function testSaveDefaultKeyChain(): void public function testSaveDefaultKeyChainFails(): void { $this->fileSystem - ->method('put') + ->method('write') ->willReturn(false); $this->expectException(PlatformKeyChainException::class); From 05fbc1b7fa8873296323aced313080f4f98472d2 Mon Sep 17 00:00:00 2001 From: Augustas Nedzinskas Date: Mon, 7 Oct 2024 18:02:52 +0200 Subject: [PATCH 2/5] chore: update unit test --- .../Repository/PlatformKeyChainRepositoryTest.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/unit/models/classes/Security/DataAccess/Repository/PlatformKeyChainRepositoryTest.php b/test/unit/models/classes/Security/DataAccess/Repository/PlatformKeyChainRepositoryTest.php index 44767e13..a7d03b4a 100644 --- a/test/unit/models/classes/Security/DataAccess/Repository/PlatformKeyChainRepositoryTest.php +++ b/test/unit/models/classes/Security/DataAccess/Repository/PlatformKeyChainRepositoryTest.php @@ -22,6 +22,8 @@ namespace oat\taoLti\test\unit\models\classes\Security\DataAccess\Repository; +use League\Flysystem\UnableToReadFile; +use League\Flysystem\UnableToWriteFile; use oat\generis\test\ServiceManagerMockTrait; use OAT\Library\Lti1p3Core\Security\Key\Key; use OAT\Library\Lti1p3Core\Security\Key\KeyChain; @@ -129,7 +131,7 @@ public function testFindFails(): void { $this->fileSystem ->method('read') - ->willReturn(false); + ->willThrowException(new UnableToReadFile()); $keyChain = $this->subject->find(''); @@ -147,8 +149,7 @@ public function testFindWithEmptyPathFails(): void public function testSaveDefaultKeyChain(): void { $this->fileSystem - ->method('write') - ->willReturn(true); + ->method('write'); $this->subject->saveDefaultKeyChain( new KeyChain('keyId', '', new Key(''), new Key('')) @@ -161,7 +162,7 @@ public function testSaveDefaultKeyChainFails(): void { $this->fileSystem ->method('write') - ->willReturn(false); + ->willThrowException(new UnableToWriteFile()); $this->expectException(PlatformKeyChainException::class); $this->expectExceptionMessage('Impossible to write LTI keys'); From 45ebb3bc778273f5b2cbec62f4d81e100a54a86e Mon Sep 17 00:00:00 2001 From: Augustas Nedzinskas Date: Wed, 16 Oct 2024 10:54:01 +0200 Subject: [PATCH 3/5] chore: update ci php version runs --- .github/workflows/continuous-integration.yaml | 4 ++-- composer.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 7829b6f1..21e22795 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -14,9 +14,9 @@ jobs: fail-fast: false matrix: operating-system: [ ubuntu-latest ] - php-version: [ '7.4', '8.0', '8.1' ] + php-version: [ '8.1', '8.2', '8.3' ] include: - - php-version: '8.1' + - php-version: '8.3' coverage: true steps: diff --git a/composer.json b/composer.json index 1d243504..ce3e27ec 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,7 @@ "oat-sa/oatbox-extension-installer": "~1.1||dev-master", "oat-sa/lib-lti1p3-ags": "^1.2", "oat-sa/lib-lti1p3-core": "^6.0.0", - "oat-sa/generis" : ">=15.22", + "oat-sa/generis" : "dev-feat/REL-1723/update-flysystem-lib as 16.0.0", "oat-sa/tao-core" : ">=54.10.0" }, "autoload" : { From 220dcb82cac2859a0e8913ae97b4a97090010163 Mon Sep 17 00:00:00 2001 From: Augustas Nedzinskas Date: Wed, 23 Oct 2024 22:12:04 +0200 Subject: [PATCH 4/5] chore: depend on generis implementation --- .../DataAccess/Repository/PlatformKeyChainRepository.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/classes/Security/DataAccess/Repository/PlatformKeyChainRepository.php b/models/classes/Security/DataAccess/Repository/PlatformKeyChainRepository.php index 7b042b97..02d282f0 100644 --- a/models/classes/Security/DataAccess/Repository/PlatformKeyChainRepository.php +++ b/models/classes/Security/DataAccess/Repository/PlatformKeyChainRepository.php @@ -23,12 +23,12 @@ namespace oat\taoLti\models\classes\Security\DataAccess\Repository; use common_exception_NoImplementation; -use League\Flysystem\FilesystemException; -use League\Flysystem\FilesystemOperator; use OAT\Library\Lti1p3Core\Security\Key\Key; use OAT\Library\Lti1p3Core\Security\Key\KeyChain; use OAT\Library\Lti1p3Core\Security\Key\KeyChainInterface; use OAT\Library\Lti1p3Core\Security\Key\KeyChainRepositoryInterface; +use oat\oatbox\filesystem\FilesystemException; +use oat\oatbox\filesystem\FilesystemInterface; use oat\oatbox\filesystem\FileSystemService; use oat\oatbox\service\ConfigurableService; use oat\tao\model\security\Business\Domain\Key\Key as TaoKey; @@ -176,7 +176,7 @@ private function readKey(string $path): string } } - private function getFileSystem(): FilesystemOperator + private function getFileSystem(): FilesystemInterface { /** @var FileSystemService $fileSystemService */ $fileSystemService = $this->getServiceLocator() From c4c90820f3d7c3e157be857cb2242c5883ae2352 Mon Sep 17 00:00:00 2001 From: Augustas Nedzinskas Date: Thu, 28 Nov 2024 10:11:17 +0100 Subject: [PATCH 5/5] chore: update generis and tao-core dependency --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ce3e27ec..9840e242 100644 --- a/composer.json +++ b/composer.json @@ -60,8 +60,8 @@ "oat-sa/oatbox-extension-installer": "~1.1||dev-master", "oat-sa/lib-lti1p3-ags": "^1.2", "oat-sa/lib-lti1p3-core": "^6.0.0", - "oat-sa/generis" : "dev-feat/REL-1723/update-flysystem-lib as 16.0.0", - "oat-sa/tao-core" : ">=54.10.0" + "oat-sa/generis": ">=16.0.0", + "oat-sa/tao-core": ">=54.26.0" }, "autoload" : { "psr-4" : {