Compare commits

...

8 commits

Author SHA1 Message Date
3c151bfd99
Added support for one-time password verification in session creation
Some checks are pending
CI / check-phpdoc (push) Waiting to run
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / release_executable (push) Waiting to run
CI / debug_executable (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / generate-phpdoc (push) Blocked by required conditions
CI / test (push) Blocked by required conditions
CI / release-documentation (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
2025-03-26 18:07:27 -04:00
42498f45db
Added additional invalid state test cases 2025-03-26 15:37:25 -04:00
a8acda8155
Moved test case testPeerResolution to SocialClientTest 2025-03-26 15:23:34 -04:00
4cce8bf91b
Moved information field test cases to the more appropriate test class SettingsTest 2025-03-26 15:22:49 -04:00
60e0884af5
Added additional test cases for AddressBookTest 2025-03-26 15:15:03 -04:00
3b0cf38ee4
Added SettingsTest 2025-03-26 15:14:51 -04:00
2e184ebc74
Enforced domain to be lowercase for case-sensitivity purposes and corrected some PhpDoc strings 2025-03-26 15:13:26 -04:00
463e86f59f
Refactored AddressBookGetContact to produce an error rather than returning null if the contact does not exist. 2025-03-26 15:12:09 -04:00
7 changed files with 761 additions and 433 deletions

View file

@ -24,6 +24,8 @@
*/ */
public static function resolveDomain(string $domain, bool $useDatabase=true): DnsRecord public static function resolveDomain(string $domain, bool $useDatabase=true): DnsRecord
{ {
$domain = strtolower($domain);
// Return the mocked record if the mocking record is set // Return the mocked record if the mocking record is set
if(isset(self::$mockedRecords[$domain])) if(isset(self::$mockedRecords[$domain]))
{ {
@ -124,11 +126,13 @@
* Adds a mock DNS record for a specific domain. * Adds a mock DNS record for a specific domain.
* *
* @param string $domain The domain name for which the DNS record is being mocked. * @param string $domain The domain name for which the DNS record is being mocked.
* @param DnsRecord $record The DNS record to be associated with the specified domain. * @param DnsRecord|string $record The DNS record to be associated with the specified domain.
* @return void * @return void
*/ */
public static function addMock(string $domain, DnsRecord|string $record): void public static function addMock(string $domain, DnsRecord|string $record): void
{ {
$domain = strtolower($domain);
if(isset(self::$mockedRecords[$domain])) if(isset(self::$mockedRecords[$domain]))
{ {
return; return;

View file

@ -35,7 +35,7 @@
{ {
if(!ContactManager::isContact($request->getPeer(), $peerAddress)) if(!ContactManager::isContact($request->getPeer(), $peerAddress))
{ {
return $rpcRequest->produceResponse(); return $rpcRequest->produceError(StandardError::NOT_FOUND, sprintf('The requested contact for %s does not exist', $peerAddress->getAddress()));
} }
return $rpcRequest->produceResponse(ContactManager::getStandardContact($request->getPeer(), $peerAddress)); return $rpcRequest->produceResponse(ContactManager::getStandardContact($request->getPeer(), $peerAddress));

View file

@ -62,6 +62,7 @@
{ {
Logger::getLogger()->debug('Creating a session for an enabled peer'); Logger::getLogger()->debug('Creating a session for an enabled peer');
$flags[] = SessionFlags::AUTHENTICATION_REQUIRED; $flags[] = SessionFlags::AUTHENTICATION_REQUIRED;
if(PasswordManager::usesPassword($peer->getUuid())) if(PasswordManager::usesPassword($peer->getUuid()))
{ {
$flags[] = SessionFlags::VER_PASSWORD; $flags[] = SessionFlags::VER_PASSWORD;
@ -71,6 +72,11 @@
{ {
$flags[] = SessionFlags::VER_IMAGE_CAPTCHA; $flags[] = SessionFlags::VER_IMAGE_CAPTCHA;
} }
if(OneTimePasswordManager::usesOtp($peer->getUuid()))
{
$flags[] = SessionFlags::VER_OTP;
}
} }
else else
{ {

View file

@ -616,4 +616,158 @@
$this->assertFalse($johnClient->addressBookDeleteContact(Helper::generateRandomPeer($johnClient->getIdentifiedAs()->getDomain()))); $this->assertFalse($johnClient->addressBookDeleteContact(Helper::generateRandomPeer($johnClient->getIdentifiedAs()->getDomain())));
} }
/**
* @throws DatabaseOperationException
* @throws ResolutionException
* @throws CryptographyException
* @throws RpcException
*/
public function testAddressBookAddDuplicateContact(): void
{
$johnClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'johnDupTest');
$johnClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe');
$johnClient->settingsSetPassword('SecretTestingPassword123');
$aliceClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'aliceDupTest');
$aliceClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'Alice Smith');
$aliceClient->settingsSetPassword('SecretTestingPassword123');
// First addition should succeed
$this->assertTrue($johnClient->addressBookAddContact($aliceClient->getIdentifiedAs()));
// Second addition should fail
$this->assertFalse($johnClient->addressBookAddContact($aliceClient->getIdentifiedAs()));
}
/**
* @throws DatabaseOperationException
* @throws ResolutionException
* @throws CryptographyException
* @throws RpcException
*/
public function testAddressBookUpdateRelationshipToBlocked(): void
{
$johnClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'johnBlockTest');
$johnClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe', PrivacyState::PUBLIC);
$johnClient->settingsSetPassword('SecretTestingPassword123');
$aliceClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'aliceBlockTest');
$aliceClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'Alice Smith', PrivacyState::PUBLIC);
$aliceClient->settingsAddInformationField(InformationFieldName::EMAIL_ADDRESS, 'alice@example.com', PrivacyState::CONTACTS);
$aliceClient->settingsSetPassword('SecretTestingPassword123');
$johnClient->addressBookAddContact($aliceClient->getIdentifiedAs());
$johnClient->addressBookUpdateRelationship($aliceClient->getIdentifiedAs(), ContactRelationshipType::BLOCKED);
$resolved = $johnClient->resolvePeer($aliceClient->getIdentifiedAs());
$this->assertCount(1, $resolved->getInformationFields(), 'Blocked contacts should return not return anything but public information');
}
/**
* @throws DatabaseOperationException
* @throws ResolutionException
* @throws CryptographyException
* @throws RpcException
*/
public function testInvalidContactAddressFormat(): void
{
$johnClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'johnInvalidTest');
$johnClient->settingsSetPassword('SecretTestingPassword123');
$this->expectException(RpcException::class);
$johnClient->addressBookAddContact('invalid-email-format');
}
/**
* @throws DatabaseOperationException
* @throws ResolutionException
* @throws CryptographyException
* @throws RpcException
*/
public function testCaseInsensitiveContactAddress(): void
{
$johnClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'johnCaseTest');
$johnClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe');
$johnClient->settingsSetPassword('SecretTestingPassword123');
$aliceClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'aliceCaseTest');
$aliceClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'Alice Smith');
$aliceClient->settingsSetPassword('SecretTestingPassword123');
$aliceAddress = $aliceClient->getIdentifiedAs();
$mixedCaseAddress = ucfirst(strtolower($aliceAddress->getUsername())).'@'.strtoupper($aliceAddress->getDomain());
$johnClient->addressBookAddContact($mixedCaseAddress);
$this->assertTrue($johnClient->addressBookContactExists($aliceAddress), 'Address comparison should be case-insensitive');
}
/**
* @throws DatabaseOperationException
* @throws ResolutionException
* @throws CryptographyException
* @throws RpcException
*/
public function testContactInformationUpdatePropagation(): void
{
$johnClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'johnUpdateTest');
$johnClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe');
$johnClient->settingsSetPassword('SecretTestingPassword123');
$aliceClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'aliceUpdateTest');
$aliceClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'Alice Smith');
$aliceClient->settingsSetPassword('SecretTestingPassword123');
$johnClient->addressBookAddContact($aliceClient->getIdentifiedAs());
// Update Alice's information
$aliceClient->settingsUpdateInformationField(InformationFieldName::DISPLAY_NAME, 'New Name');
// Verify John sees the update
$resolved = $johnClient->resolvePeer($aliceClient->getIdentifiedAs());
$this->assertEquals('New Name', $resolved->getInformationField(InformationFieldName::DISPLAY_NAME)->getValue());
}
/**
* @throws DatabaseOperationException
* @throws ResolutionException
* @throws CryptographyException
* @throws RpcException
*/
public function testRevokeNonExistentSignature(): void
{
$johnClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'johnRevokeTest');
$johnClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe');
$johnClient->settingsSetPassword('SecretTestingPassword123');
$aliceClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'aliceRevokeTest');
$aliceClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'Alice Smith');
$aliceClient->settingsSetPassword('SecretTestingPassword123');
$this->assertFalse($johnClient->addressBookRevokeSignature($aliceClient->getIdentifiedAs(), 'non-existent-uuid'));
}
/**
* @throws DatabaseOperationException
* @throws ResolutionException
* @throws CryptographyException
* @throws RpcException
*/
public function testAddressBookGetSingleContact(): void
{
$johnClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'johnGetSingleTest');
$johnClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe');
$johnClient->settingsSetPassword('SecretTestingPassword123');
$aliceClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'aliceGetSingleTest');
$aliceClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'Alice Smith');
$aliceClient->settingsSetPassword('SecretTestingPassword123');
$johnClient->addressBookAddContact($aliceClient->getIdentifiedAs());
$contact = $johnClient->addressBookGetContact($aliceClient->getIdentifiedAs());
$this->assertInstanceOf(Contact::class, $contact);
$this->assertEquals($aliceClient->getIdentifiedAs(), $contact->getAddress()->getAddress());
$this->expectException(RpcException::class);
$johnClient->addressBookGetContact('non-existent@coffee.com');
}
} }

View file

@ -0,0 +1,515 @@
<?php
namespace Socialbox;
use Helper;
use PHPUnit\Framework\TestCase;
use Socialbox\Enums\PrivacyState;
use Socialbox\Enums\Types\InformationFieldName;
use Socialbox\Exceptions\CryptographyException;
use Socialbox\Exceptions\DatabaseOperationException;
use Socialbox\Exceptions\ResolutionException;
use Socialbox\Exceptions\RpcException;
class SettingsTest extends TestCase
{
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInformationFieldDisplayName(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'validInputTest');
$displayName = Helper::generateRandomString(32);
$rpcClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, $displayName);
$this->assertTrue($rpcClient->settingsInformationFieldExists(InformationFieldName::DISPLAY_NAME));
$this->assertEquals($displayName, $rpcClient->settingsGetInformationField(InformationFieldName::DISPLAY_NAME)->getValue());
}
/**
* @throws ResolutionException
* @throws RpcException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInformationFieldInvalidDisplayName(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'malformedInputTest');
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, Helper::generateRandomString(2048));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::DISPLAY_NAME));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, '');
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::DISPLAY_NAME));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInformationFieldFirstName(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'validInputTest');
$firstName = Helper::generateRandomString(32);
$rpcClient->settingsAddInformationField(InformationFieldName::FIRST_NAME, $firstName);
$this->assertTrue($rpcClient->settingsInformationFieldExists(InformationFieldName::FIRST_NAME));
$this->assertEquals($firstName, $rpcClient->settingsGetInformationField(InformationFieldName::FIRST_NAME)->getValue());
}
/**
* @throws ResolutionException
* @throws RpcException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInformationFieldInvalidFirstName(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'malformedInputTest');
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::FIRST_NAME, Helper::generateRandomString(2012));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::FIRST_NAME));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::FIRST_NAME, '');
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::FIRST_NAME));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInformationFieldMiddleName(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'validInputTest');
$middleName = Helper::generateRandomString(32);
$rpcClient->settingsAddInformationField(InformationFieldName::MIDDLE_NAME, $middleName);
$this->assertTrue($rpcClient->settingsInformationFieldExists(InformationFieldName::MIDDLE_NAME));
$this->assertEquals($middleName, $rpcClient->settingsGetInformationField(InformationFieldName::MIDDLE_NAME)->getValue());
}
/**
* @throws ResolutionException
* @throws RpcException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInformationFieldInvalidMiddleName(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'malformedInputTest');
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::MIDDLE_NAME, Helper::generateRandomString(2012));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::MIDDLE_NAME));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::MIDDLE_NAME, '');
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::MIDDLE_NAME));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInformationFieldLastName(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'validInputTest');
$lastName = Helper::generateRandomString(32);
$rpcClient->settingsAddInformationField(InformationFieldName::LAST_NAME, $lastName);
$this->assertTrue($rpcClient->settingsInformationFieldExists(InformationFieldName::LAST_NAME));
$this->assertEquals($lastName, $rpcClient->settingsGetInformationField(InformationFieldName::LAST_NAME)->getValue());
}
/**
* @throws ResolutionException
* @throws RpcException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInformationFieldInvalidLastName(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'malformedInputTest');
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::LAST_NAME, Helper::generateRandomString(2012));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::LAST_NAME));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::LAST_NAME, '');
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::LAST_NAME));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
}
/**
* @throws ResolutionException
* @throws RpcException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInformationFieldPhoneNumber(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'validInputTest');
$phoneNumber = sprintf('+%d', Helper::generateRandomNumber(12));
$rpcClient->settingsAddInformationField(InformationFieldName::PHONE_NUMBER, $phoneNumber);
$this->assertTrue($rpcClient->settingsInformationFieldExists(InformationFieldName::PHONE_NUMBER));
$this->assertEquals($phoneNumber, $rpcClient->settingsGetInformationField(InformationFieldName::PHONE_NUMBER)->getValue());
}
/**
* @throws ResolutionException
* @throws RpcException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInformationFieldInvalidPhoneNumber(): void
{
$rpcClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'malformedTest');
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::PHONE_NUMBER, Helper::generateRandomString(2048));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::PHONE_NUMBER));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::PHONE_NUMBER, Helper::generateRandomNumber(152));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::PHONE_NUMBER));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::PHONE_NUMBER, Helper::generateRandomNumber(2));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::PHONE_NUMBER));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::PHONE_NUMBER, '');
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::PHONE_NUMBER));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInformationFieldEmailAddress(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'validInputTest');
$rpcClient->settingsAddInformationField(InformationFieldName::EMAIL_ADDRESS, 'testing@example.com');
$this->assertTrue($rpcClient->settingsInformationFieldExists(InformationFieldName::EMAIL_ADDRESS));
$this->assertEquals('testing@example.com', $rpcClient->settingsGetInformationField(InformationFieldName::EMAIL_ADDRESS)->getValue());
}
/**
* @throws ResolutionException
* @throws RpcException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInformationFieldInvalidEmailAddress(): void
{
$rpcClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'malformedTest');
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::EMAIL_ADDRESS, Helper::generateRandomString(2048));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::EMAIL_ADDRESS));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::EMAIL_ADDRESS, '');
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::EMAIL_ADDRESS));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInformationFieldUrl(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'validInputTest');
$rpcClient->settingsAddInformationField(InformationFieldName::URL, 'https://example.com');
$this->assertTrue($rpcClient->settingsInformationFieldExists(InformationFieldName::URL));
$this->assertEquals('https://example.com', $rpcClient->settingsGetInformationField(InformationFieldName::URL)->getValue());
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInformationFieldInvalidUrl(): void
{
$rpcClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'malformedTest');
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::URL, Helper::generateRandomString(2048));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::URL));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::URL, '');
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::URL));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInformationFieldBirthday(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'validInputTest');
$rpcClient->settingsAddInformationField(InformationFieldName::BIRTHDAY, '2021-01-01');
$this->assertTrue($rpcClient->settingsInformationFieldExists(InformationFieldName::BIRTHDAY));
$this->assertEquals('2021-01-01', $rpcClient->settingsGetInformationField(InformationFieldName::BIRTHDAY)->getValue());
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInformationFieldInvalidBirthday(): void
{
$rpcClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'malformedTest');
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::BIRTHDAY, Helper::generateRandomString(2048));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::BIRTHDAY));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::BIRTHDAY, '');
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::BIRTHDAY));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInvalidInformationField(): void
{
$testClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'invalidInformationFieldTest');
$this->assertTrue($testClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe'));
$this->assertTrue($testClient->settingsSetPassword('SecretTestingPassword123'));
$this->assertTrue($testClient->getSessionState()->isAuthenticated());
$this->expectException(RpcException::class);
$testClient->settingsAddInformationField('Invalid', 'foo bar');
}
/**
* @throws ResolutionException
* @throws RpcException
* @throws CryptographyException
* @throws DatabaseOperationException
* @noinspection HttpUrlsUsage
*/
public function testInvalidInformationFieldPrivacy(): void
{
$testClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'invalidInformationFieldPrivacyTest');
$this->assertTrue($testClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe'));
$this->assertTrue($testClient->settingsSetPassword('SecretTestingPassword123'));
$this->assertTrue($testClient->getSessionState()->isAuthenticated());
$this->expectException(RpcException::class);
$testClient->settingsAddInformationField(InformationFieldName::URL, 'http://example.com/', 'Invalid Privacy');
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testDeleteRequiredInformationField(): void
{
$testClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'invalidInformationFieldPrivacyTest');
$this->assertTrue($testClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe'));
$this->assertTrue($testClient->settingsSetPassword('SecretTestingPassword123'));
$this->assertTrue($testClient->getSessionState()->isAuthenticated());
$this->expectException(RpcException::class);
$testClient->settingsDeleteInformationField(InformationFieldName::DISPLAY_NAME);
}
/**
* @throws RpcException
* @throws DatabaseOperationException
* @throws ResolutionException
* @throws CryptographyException
*/
public function testDeleteInformationField(): void
{
$johnClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'johnDeleteInformationFieldTest');
$this->assertTrue($johnClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe'));
$this->assertTrue($johnClient->settingsAddInformationField(InformationFieldName::FIRST_NAME, 'John', PrivacyState::PUBLIC));
$this->assertTrue($johnClient->settingsSetPassword('SecretTestingPassword123'));
$this->assertTrue($johnClient->getSessionState()->isAuthenticated());
$aliceClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'aliceDeleteInformationFieldTest');
$this->assertTrue($aliceClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'Alice Smith'));
$this->assertTrue($aliceClient->settingsAddInformationField(InformationFieldName::FIRST_NAME, 'Alice', PrivacyState::PUBLIC));
$this->assertTrue($aliceClient->settingsSetPassword('SecretTestingPassword123'));
$this->assertTrue($aliceClient->getSessionState()->isAuthenticated());
$johnResolved = $aliceClient->resolvePeer($johnClient->getIdentifiedAs());
$this->assertNotNull($johnResolved);
$this->assertCount(2, $johnResolved->getInformationFields());
$this->assertTrue($johnResolved->informationFieldExists(InformationFieldName::DISPLAY_NAME));
$this->assertEquals('John Doe', $johnResolved->getInformationField(InformationFieldName::DISPLAY_NAME)->getValue());
$this->assertTrue($johnResolved->informationFieldExists(InformationFieldName::FIRST_NAME));
$this->assertEquals('John', $johnResolved->getInformationField(InformationFieldName::FIRST_NAME)->getValue());
$aliceResolved = $johnClient->resolvePeer($aliceClient->getIdentifiedAs());
$this->assertNotNull($aliceResolved);
$this->assertCount(2, $aliceResolved->getInformationFields());
$this->assertTrue($aliceResolved->informationFieldExists(InformationFieldName::DISPLAY_NAME));
$this->assertEquals('Alice Smith', $aliceResolved->getInformationField(InformationFieldName::DISPLAY_NAME)->getValue());
$this->assertTrue($aliceResolved->informationFieldExists(InformationFieldName::FIRST_NAME));
$this->assertEquals('Alice', $aliceResolved->getInformationField(InformationFieldName::FIRST_NAME)->getValue());
$aliceClient->settingsDeleteInformationField(InformationFieldName::FIRST_NAME);
$johnClient->settingsDeleteInformationField(InformationFieldName::FIRST_NAME);
$johnResolved = $aliceClient->resolvePeer($johnClient->getIdentifiedAs());
$this->assertNotNull($johnResolved);
$this->assertCount(1, $johnResolved->getInformationFields());
$this->assertTrue($johnResolved->informationFieldExists(InformationFieldName::DISPLAY_NAME));
$this->assertEquals('John Doe', $johnResolved->getInformationField(InformationFieldName::DISPLAY_NAME)->getValue());
$aliceResolved = $johnClient->resolvePeer($aliceClient->getIdentifiedAs());
$this->assertNotNull($aliceResolved);
$this->assertCount(1, $aliceResolved->getInformationFields());
$this->assertTrue($aliceResolved->informationFieldExists(InformationFieldName::DISPLAY_NAME));
$this->assertEquals('Alice Smith', $aliceResolved->getInformationField(InformationFieldName::DISPLAY_NAME)->getValue());
}
}

View file

@ -58,437 +58,6 @@
$this->assertTrue($rpcClient->getSessionState()->isAuthenticated()); $this->assertTrue($rpcClient->getSessionState()->isAuthenticated());
} }
/**
* @throws ResolutionException
* @throws RpcException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInvalidDisplayName(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'malformedInputTest');
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, Helper::generateRandomString(2048));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::DISPLAY_NAME));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, '');
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::DISPLAY_NAME));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testValidDisplayName(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'validInputTest');
$displayName = Helper::generateRandomString(32);
$rpcClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, $displayName);
$this->assertTrue($rpcClient->settingsInformationFieldExists(InformationFieldName::DISPLAY_NAME));
$this->assertEquals($displayName, $rpcClient->settingsGetInformationField(InformationFieldName::DISPLAY_NAME)->getValue());
}
/**
* @throws ResolutionException
* @throws RpcException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInvalidFirstName(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'malformedInputTest');
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::FIRST_NAME, Helper::generateRandomString(2012));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::FIRST_NAME));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::FIRST_NAME, '');
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::FIRST_NAME));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testValidFirstName(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'validInputTest');
$firstName = Helper::generateRandomString(32);
$rpcClient->settingsAddInformationField(InformationFieldName::FIRST_NAME, $firstName);
$this->assertTrue($rpcClient->settingsInformationFieldExists(InformationFieldName::FIRST_NAME));
$this->assertEquals($firstName, $rpcClient->settingsGetInformationField(InformationFieldName::FIRST_NAME)->getValue());
}
/**
* @throws ResolutionException
* @throws RpcException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInvalidMiddleName(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'malformedInputTest');
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::MIDDLE_NAME, Helper::generateRandomString(2012));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::MIDDLE_NAME));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::MIDDLE_NAME, '');
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::MIDDLE_NAME));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testValidMiddleName(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'validInputTest');
$middleName = Helper::generateRandomString(32);
$rpcClient->settingsAddInformationField(InformationFieldName::MIDDLE_NAME, $middleName);
$this->assertTrue($rpcClient->settingsInformationFieldExists(InformationFieldName::MIDDLE_NAME));
$this->assertEquals($middleName, $rpcClient->settingsGetInformationField(InformationFieldName::MIDDLE_NAME)->getValue());
}
/**
* @throws ResolutionException
* @throws RpcException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInvalidLastName(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'malformedInputTest');
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::LAST_NAME, Helper::generateRandomString(2012));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::LAST_NAME));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::LAST_NAME, '');
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::LAST_NAME));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testValidLastName(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'validInputTest');
$lastName = Helper::generateRandomString(32);
$rpcClient->settingsAddInformationField(InformationFieldName::LAST_NAME, $lastName);
$this->assertTrue($rpcClient->settingsInformationFieldExists(InformationFieldName::LAST_NAME));
$this->assertEquals($lastName, $rpcClient->settingsGetInformationField(InformationFieldName::LAST_NAME)->getValue());
}
public function testInvalidPhoneNumber(): void
{
$rpcClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'malformedTest');
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::PHONE_NUMBER, Helper::generateRandomString(2048));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::PHONE_NUMBER));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::PHONE_NUMBER, Helper::generateRandomNumber(152));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::PHONE_NUMBER));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::PHONE_NUMBER, Helper::generateRandomNumber(2));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::PHONE_NUMBER));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::PHONE_NUMBER, '');
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::PHONE_NUMBER));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
}
public function testValidPhoneNumber(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'validInputTest');
$phoneNumber = sprintf('+%d', Helper::generateRandomNumber(12));
$rpcClient->settingsAddInformationField(InformationFieldName::PHONE_NUMBER, $phoneNumber);
$this->assertTrue($rpcClient->settingsInformationFieldExists(InformationFieldName::PHONE_NUMBER));
$this->assertEquals($phoneNumber, $rpcClient->settingsGetInformationField(InformationFieldName::PHONE_NUMBER)->getValue());
}
/**
* @throws ResolutionException
* @throws RpcException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testInvalidEmail(): void
{
$rpcClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'malformedTest');
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::EMAIL_ADDRESS, Helper::generateRandomString(2048));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::EMAIL_ADDRESS));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::EMAIL_ADDRESS, '');
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::EMAIL_ADDRESS));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testValidEmail(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'validInputTest');
$rpcClient->settingsAddInformationField(InformationFieldName::EMAIL_ADDRESS, 'testing@example.com');
$this->assertTrue($rpcClient->settingsInformationFieldExists(InformationFieldName::EMAIL_ADDRESS));
$this->assertEquals('testing@example.com', $rpcClient->settingsGetInformationField(InformationFieldName::EMAIL_ADDRESS)->getValue());
}
public function testInvalidUrl(): void
{
$rpcClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'malformedTest');
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::URL, Helper::generateRandomString(2048));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::URL));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::URL, '');
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::URL));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
}
public function testValidUrl(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'validInputTest');
$rpcClient->settingsAddInformationField(InformationFieldName::URL, 'https://example.com');
$this->assertTrue($rpcClient->settingsInformationFieldExists(InformationFieldName::URL));
$this->assertEquals('https://example.com', $rpcClient->settingsGetInformationField(InformationFieldName::URL)->getValue());
}
public function testInvalidBirthday(): void
{
$rpcClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'malformedTest');
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::BIRTHDAY, Helper::generateRandomString(2048));
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::BIRTHDAY));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
try
{
$rpcClient->settingsAddInformationField(InformationFieldName::BIRTHDAY, '');
$this->assertFalse($rpcClient->settingsInformationFieldExists(InformationFieldName::BIRTHDAY));
}
catch(RpcException $e)
{
$this->assertEquals(-1001, $e->getCode(), sprintf('Unexpected error code: %d', $e->getCode()));
}
}
public function testValidBirthday(): void
{
$rpcClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'validInputTest');
$rpcClient->settingsAddInformationField(InformationFieldName::BIRTHDAY, '2021-01-01');
$this->assertTrue($rpcClient->settingsInformationFieldExists(InformationFieldName::BIRTHDAY));
$this->assertEquals('2021-01-01', $rpcClient->settingsGetInformationField(InformationFieldName::BIRTHDAY)->getValue());
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testPeerResolution(): void
{
$johnClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'johnDoe');
$johnClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'Test User');
$this->assertEquals('Test User', $johnClient->settingsGetInformationField(InformationFieldName::DISPLAY_NAME)->getValue());
$johnClient->settingsAddInformationField(InformationFieldName::FIRST_NAME, 'John');
$this->assertEquals('John', $johnClient->settingsGetInformationField(InformationFieldName::FIRST_NAME)->getValue());
$johnClient->settingsAddInformationField(InformationFieldName::LAST_NAME, 'Doe');
$this->assertEquals('Doe', $johnClient->settingsGetInformationField(InformationFieldName::LAST_NAME)->getValue());
$johnClient->settingsSetPassword('SecuredTestingPassword123');
$this->assertTrue($johnClient->getSessionState()->isAuthenticated());
$this->assertFalse($johnClient->getSessionState()->containsFlag(SessionFlags::REGISTRATION_REQUIRED));
$this->assertFalse($johnClient->getSessionState()->containsFlag(SessionFlags::AUTHENTICATION_REQUIRED));
$aliceClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'aliceSmith');
$aliceClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'Test User');
$this->assertEquals('Test User', $aliceClient->settingsGetInformationField(InformationFieldName::DISPLAY_NAME)->getValue());
$aliceClient->settingsAddInformationField(InformationFieldName::FIRST_NAME, 'Alice');
$this->assertEquals('Alice', $aliceClient->settingsGetInformationField(InformationFieldName::FIRST_NAME)->getValue());
$aliceClient->settingsAddInformationField(InformationFieldName::LAST_NAME, 'Smith');
$this->assertEquals('Smith', $aliceClient->settingsGetInformationField(InformationFieldName::LAST_NAME)->getValue());
$aliceClient->settingsSetPassword('SecuredTestingPassword123');
$this->assertTrue($aliceClient->getSessionState()->isAuthenticated());
$this->assertFalse($aliceClient->getSessionState()->containsFlag(SessionFlags::REGISTRATION_REQUIRED));
$this->assertFalse($aliceClient->getSessionState()->containsFlag(SessionFlags::AUTHENTICATION_REQUIRED));
$aliceResolved = $aliceClient->resolvePeer($aliceClient->getSelf()->getPeerAddress());
foreach($aliceResolved->getInformationFields() as $informationField)
{
switch($informationField->getName())
{
case InformationFieldName::DISPLAY_NAME:
$this->assertEquals('Test User', $informationField->getValue());
break;
case InformationFieldName::FIRST_NAME:
$this->assertEquals('Alice', $informationField->getValue());
break;
case InformationFieldName::LAST_NAME:
$this->assertEquals('Smith', $informationField->getValue());
break;
default:
$this->fail('Unexpected information field: ' . $informationField->getName()->value);
}
}
$johnResolved = $aliceClient->resolvePeer($johnClient->getSelf()->getPeerAddress());
foreach($johnResolved->getInformationFields() as $informationField)
{
switch($informationField->getName())
{
case InformationFieldName::DISPLAY_NAME:
$this->assertEquals('Test User', $informationField->getValue());
break;
case InformationFieldName::FIRST_NAME:
$this->assertEquals('John', $informationField->getValue());
break;
case InformationFieldName::LAST_NAME:
$this->assertEquals('Doe', $informationField->getValue());
break;
default:
$this->fail('Unexpected information field: ' . $informationField->getName()->value);
}
}
$this->assertEquals($johnClient->getSelf()->getPeerAddress(), $johnResolved->getPeerAddress());
$this->assertEquals($aliceClient->getSelf()->getPeerAddress(), $aliceResolved->getPeerAddress());
}
/** /**
* @throws ResolutionException * @throws ResolutionException
* @throws RpcException * @throws RpcException

View file

@ -5,6 +5,12 @@
use Exception; use Exception;
use Helper; use Helper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Socialbox\Enums\Flags\SessionFlags;
use Socialbox\Enums\Types\InformationFieldName;
use Socialbox\Exceptions\CryptographyException;
use Socialbox\Exceptions\DatabaseOperationException;
use Socialbox\Exceptions\ResolutionException;
use Socialbox\Exceptions\RpcException;
class SocialClientTest extends TestCase class SocialClientTest extends TestCase
{ {
@ -34,4 +40,78 @@
$this->fail('Failed to create RPC client: ' . $e->getMessage()); $this->fail('Failed to create RPC client: ' . $e->getMessage());
} }
} }
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testPeerResolution(): void
{
$johnClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'johnDoe');
$johnClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'Test User');
$this->assertEquals('Test User', $johnClient->settingsGetInformationField(InformationFieldName::DISPLAY_NAME)->getValue());
$johnClient->settingsAddInformationField(InformationFieldName::FIRST_NAME, 'John');
$this->assertEquals('John', $johnClient->settingsGetInformationField(InformationFieldName::FIRST_NAME)->getValue());
$johnClient->settingsAddInformationField(InformationFieldName::LAST_NAME, 'Doe');
$this->assertEquals('Doe', $johnClient->settingsGetInformationField(InformationFieldName::LAST_NAME)->getValue());
$johnClient->settingsSetPassword('SecuredTestingPassword123');
$this->assertTrue($johnClient->getSessionState()->isAuthenticated());
$this->assertFalse($johnClient->getSessionState()->containsFlag(SessionFlags::REGISTRATION_REQUIRED));
$this->assertFalse($johnClient->getSessionState()->containsFlag(SessionFlags::AUTHENTICATION_REQUIRED));
$aliceClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'aliceSmith');
$aliceClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'Test User');
$this->assertEquals('Test User', $aliceClient->settingsGetInformationField(InformationFieldName::DISPLAY_NAME)->getValue());
$aliceClient->settingsAddInformationField(InformationFieldName::FIRST_NAME, 'Alice');
$this->assertEquals('Alice', $aliceClient->settingsGetInformationField(InformationFieldName::FIRST_NAME)->getValue());
$aliceClient->settingsAddInformationField(InformationFieldName::LAST_NAME, 'Smith');
$this->assertEquals('Smith', $aliceClient->settingsGetInformationField(InformationFieldName::LAST_NAME)->getValue());
$aliceClient->settingsSetPassword('SecuredTestingPassword123');
$this->assertTrue($aliceClient->getSessionState()->isAuthenticated());
$this->assertFalse($aliceClient->getSessionState()->containsFlag(SessionFlags::REGISTRATION_REQUIRED));
$this->assertFalse($aliceClient->getSessionState()->containsFlag(SessionFlags::AUTHENTICATION_REQUIRED));
$aliceResolved = $aliceClient->resolvePeer($aliceClient->getSelf()->getPeerAddress());
foreach($aliceResolved->getInformationFields() as $informationField)
{
switch($informationField->getName())
{
case InformationFieldName::DISPLAY_NAME:
$this->assertEquals('Test User', $informationField->getValue());
break;
case InformationFieldName::FIRST_NAME:
$this->assertEquals('Alice', $informationField->getValue());
break;
case InformationFieldName::LAST_NAME:
$this->assertEquals('Smith', $informationField->getValue());
break;
default:
$this->fail('Unexpected information field: ' . $informationField->getName()->value);
}
}
$johnResolved = $aliceClient->resolvePeer($johnClient->getSelf()->getPeerAddress());
foreach($johnResolved->getInformationFields() as $informationField)
{
switch($informationField->getName())
{
case InformationFieldName::DISPLAY_NAME:
$this->assertEquals('Test User', $informationField->getValue());
break;
case InformationFieldName::FIRST_NAME:
$this->assertEquals('John', $informationField->getValue());
break;
case InformationFieldName::LAST_NAME:
$this->assertEquals('Doe', $informationField->getValue());
break;
default:
$this->fail('Unexpected information field: ' . $informationField->getName()->value);
}
}
$this->assertEquals($johnClient->getSelf()->getPeerAddress(), $johnResolved->getPeerAddress());
$this->assertEquals($aliceClient->getSelf()->getPeerAddress(), $aliceResolved->getPeerAddress());
}
} }