From 4d2e7ce6e23e94a4922f3c0bc3332319b84b90fa Mon Sep 17 00:00:00 2001 From: netkas Date: Wed, 26 Mar 2025 14:05:52 -0400 Subject: [PATCH] Add tests for address book functionality to handle contact addition scenarios --- tests/Socialbox/AddressBookTest.php | 52 +++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/Socialbox/AddressBookTest.php b/tests/Socialbox/AddressBookTest.php index fcf3c0c..18d18e8 100644 --- a/tests/Socialbox/AddressBookTest.php +++ b/tests/Socialbox/AddressBookTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\TestCase; use Socialbox\Classes\Cryptography; use Socialbox\Enums\PrivacyState; + use Socialbox\Enums\ReservedUsernames; use Socialbox\Enums\StandardError; use Socialbox\Enums\Types\ContactRelationshipType; use Socialbox\Enums\Types\InformationFieldName; @@ -176,6 +177,57 @@ $this->assertEquals('John Test Signature', $johnKnownSigningKeyTest->getName()); } + /** + * @throws DatabaseOperationException + * @throws ResolutionException + * @throws CryptographyException + * @throws RpcException + */ + public function testAddHostAsContact(): void + { + $johnClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'johnAddressBookTest'); + $this->assertTrue($johnClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe')); + $this->assertTrue($johnClient->settingsSetPassword('SecretTestingPassword123')); + $this->assertTrue($johnClient->getSessionState()->isAuthenticated()); + + $this->expectException(RpcException::class); + $johnClient->addressBookAddContact(sprintf('%s@%s', ReservedUsernames::HOST->value, TEAPOT_DOMAIN)); + } + + /** + * @throws DatabaseOperationException + * @throws ResolutionException + * @throws CryptographyException + * @throws RpcException + */ + public function testAddressBookTrustNonExistent(): void + { + $johnClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'johnAddressBookTest'); + $johnClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe'); + $johnClient->settingsSetPassword('SecretTestingPassword123'); + $this->assertTrue($johnClient->getSessionState()->isAuthenticated()); + + $this->expectException(RpcException::class); + $johnClient->addressBookUpdateRelationship(sprintf('phonyUser@%s', COFFEE_DOMAIN), ContactRelationshipType::TRUSTED); + } + + /** + * @throws RpcException + * @throws ResolutionException + * @throws CryptographyException + * @throws DatabaseOperationException + */ + public function testAddSelfAsContact(): void + { + $johnClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'johnAddressBookTest'); + $this->assertTrue($johnClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe')); + $this->assertTrue($johnClient->settingsSetPassword('SecretTestingPassword123')); + $this->assertTrue($johnClient->getSessionState()->isAuthenticated()); + + $this->expectException(RpcException::class); + $johnClient->addressBookAddContact($johnClient->getIdentifiedAs()); + } + /** * @throws DatabaseOperationException * @throws ResolutionException