Skip to content

Commit

Permalink
Merge branch 'release-16.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Nov 28, 2024
2 parents f51c2f8 + 60ef6b7 commit 346b9ba
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
"oat-sa/oatbox-extension-installer": "~1.1||dev-master",
"oat-sa/lib-lti1p3-ags": "~2",
"oat-sa/lib-lti1p3-core": "~7",
"oat-sa/generis" : ">=15.40.0",
"oat-sa/tao-core" : ">=54.10.0"
"oat-sa/generis": ">=16.0.0",
"oat-sa/tao-core": ">=54.26.0"
},
"autoload" : {
"psr-4" : {
Expand Down
2 changes: 1 addition & 1 deletion models/classes/ExceptionInterpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
namespace oat\taoLti\models\classes\Security\DataAccess\Repository;

use common_exception_NoImplementation;
use League\Flysystem\FilesystemInterface;
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;
Expand Down Expand Up @@ -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);
}
}
}

Expand All @@ -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');
Expand All @@ -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,
Expand All @@ -168,6 +167,15 @@ public function findByKeySetName(string $keySetName): array
throw new common_exception_NoImplementation();
}

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(): FilesystemInterface
{
/** @var FileSystemService $fileSystemService */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -129,7 +131,7 @@ public function testFindFails(): void
{
$this->fileSystem
->method('read')
->willReturn(false);
->willThrowException(new UnableToReadFile());

$keyChain = $this->subject->find('');

Expand All @@ -147,8 +149,7 @@ public function testFindWithEmptyPathFails(): void
public function testSaveDefaultKeyChain(): void
{
$this->fileSystem
->method('put')
->willReturn(true);
->method('write');

$this->subject->saveDefaultKeyChain(
new KeyChain('keyId', '', new Key(''), new Key(''))
Expand All @@ -160,8 +161,8 @@ public function testSaveDefaultKeyChain(): void
public function testSaveDefaultKeyChainFails(): void
{
$this->fileSystem
->method('put')
->willReturn(false);
->method('write')
->willThrowException(new UnableToWriteFile());

$this->expectException(PlatformKeyChainException::class);
$this->expectExceptionMessage('Impossible to write LTI keys');
Expand Down

0 comments on commit 346b9ba

Please sign in to comment.