From b9c84aeb2730bbb347344fdfb37bf8d2f4501291 Mon Sep 17 00:00:00 2001 From: netkas Date: Fri, 13 Sep 2024 13:52:26 -0400 Subject: [PATCH] Add unit tests for SessionManager --- .../Socialbox/Managers/SessionManagerTest.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/Socialbox/Managers/SessionManagerTest.php diff --git a/tests/Socialbox/Managers/SessionManagerTest.php b/tests/Socialbox/Managers/SessionManagerTest.php new file mode 100644 index 0000000..6b0f954 --- /dev/null +++ b/tests/Socialbox/Managers/SessionManagerTest.php @@ -0,0 +1,49 @@ +expectException(InvalidArgumentException::class); + SessionManager::createSession($publicKey); + } + + public function testCreateSession(): void + { + $keyPair = Cryptography::generateKeyPair(); + $uuid = SessionManager::createSession($keyPair->getPublicKey()); + + $this->assertTrue(SessionManager::sessionExists($uuid)); + } + + public function testGetSessionWithInvalidUuid(): void + { + $uuid = 'invalid_uuid'; + + $this->expectException(DatabaseOperationException::class); + SessionManager::getSession($uuid); + } + + public function testGetSessionWithValidUuid(): void + { + $keyPair = Cryptography::generateKeyPair(); + $uuid = SessionManager::createSession($keyPair->getPublicKey()); + + $session = SessionManager::getSession($uuid); + + $this->assertInstanceOf(SessionRecord::class, $session); + $this->assertEquals($uuid, $session->getUuid()); + $this->assertEquals($keyPair->getPublicKey(), Utilities::base64encode($session->getPublicKey())); + } +}