Added tests for password deletion and OTP settings in AddressBookTest and SettingsTest

This commit is contained in:
netkas 2025-03-27 12:52:16 -04:00
parent 3c151bfd99
commit df519ad89b
Signed by: netkas
GPG key ID: 4D8629441B76E4CC
2 changed files with 47 additions and 4 deletions

View file

@ -688,12 +688,14 @@
public function testCaseInsensitiveContactAddress(): void
{
$johnClient = Helper::generateRandomClient(TEAPOT_DOMAIN, prefix: 'johnCaseTest');
$johnClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe');
$johnClient->settingsSetPassword('SecretTestingPassword123');
$this->assertTrue($johnClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe'));
$this->assertTrue($johnClient->settingsSetPassword('SecretTestingPassword123'));
$this->assertTrue($johnClient->getSessionState()->isAuthenticated());
$aliceClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'aliceCaseTest');
$aliceClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'Alice Smith');
$aliceClient->settingsSetPassword('SecretTestingPassword123');
$this->assertTrue($aliceClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'Alice Smith'));
$this->assertTrue($aliceClient->settingsSetPassword('SecretTestingPassword123'));
$this->assertTrue($aliceClient->getSessionState()->isAuthenticated());
$aliceAddress = $aliceClient->getIdentifiedAs();
$mixedCaseAddress = ucfirst(strtolower($aliceAddress->getUsername())).'@'.strtoupper($aliceAddress->getDomain());

View file

@ -4,7 +4,9 @@
use Helper;
use PHPUnit\Framework\TestCase;
q use Socialbox\Enums\Flags\SessionFlags;
use Socialbox\Enums\PrivacyState;
use Socialbox\Enums\SessionState;
use Socialbox\Enums\Types\InformationFieldName;
use Socialbox\Exceptions\CryptographyException;
use Socialbox\Exceptions\DatabaseOperationException;
@ -512,4 +514,43 @@
$this->assertTrue($aliceResolved->informationFieldExists(InformationFieldName::DISPLAY_NAME));
$this->assertEquals('Alice Smith', $aliceResolved->getInformationField(InformationFieldName::DISPLAY_NAME)->getValue());
}
/**
* @throws RpcException
* @throws ResolutionException
* @throws CryptographyException
* @throws DatabaseOperationException
*/
public function testDeleteRequiredPassword(): void
{
$testClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'deleteRequiredPassword');
$this->assertTrue($testClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe'));
$this->assertTrue($testClient->settingsSetPassword('SecretTestingPassword123'));
$this->assertTrue($testClient->getSessionState()->isAuthenticated());
$this->expectException(RpcException::class);
$testClient->settingsDeletePassword();
}
/**
* @throws RpcException
* @throws DatabaseOperationException
* @throws ResolutionException
* @throws CryptographyException
*/
public function testSettingsSetOtp(): void
{
$testClient = Helper::generateRandomClient(COFFEE_DOMAIN, prefix: 'testSetOtp');
$testAddress = $testClient->getIdentifiedAs();
$this->assertTrue($testClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'John Doe'));
$this->assertTrue($testClient->settingsSetPassword('SecretTestingPassword123'));
$this->assertTrue($testClient->getSessionState()->isAuthenticated());
$secret = $testClient->settingsSetOtp('SecretTestingPassword123');
$this->assertNotEmpty($secret);
$testClient = new SocialClient($testAddress);
$this->assertFalse($testClient->getSessionState()->isAuthenticated());
$this->assertTrue($testClient->getSessionState()->containsFlag(SessionFlags::VER_OTP));
}
}