Refactor Docker configuration and update encryption channels schema
Some checks are pending
CI / release_executable (push) Waiting to run
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / debug_executable (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (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
Some checks are pending
CI / release_executable (push) Waiting to run
CI / release (push) Waiting to run
CI / debug (push) Waiting to run
CI / debug_executable (push) Waiting to run
CI / check-phpunit (push) Waiting to run
CI / check-phpdoc (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
This commit is contained in:
parent
40f871dbea
commit
71563e51ee
9 changed files with 60 additions and 153 deletions
|
@ -2,81 +2,36 @@
|
|||
|
||||
namespace Socialbox;
|
||||
|
||||
use Exception;
|
||||
use Helper;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Socialbox\Classes\ServerResolver;
|
||||
use Socialbox\Enums\Flags\SessionFlags;
|
||||
use Socialbox\Enums\Types\InformationFieldName;
|
||||
|
||||
class SocialClientTest extends TestCase
|
||||
{
|
||||
private const string COFFEE_DOMAIN = 'coffee.com';
|
||||
private const string TEAPOT_DOMAIN = 'teapot.com';
|
||||
|
||||
|
||||
protected function setUp(): void
|
||||
public function testCoffeePing(): void
|
||||
{
|
||||
putenv('LOG_LEVEL=debug');
|
||||
|
||||
// Add mocked records for the test domains
|
||||
ServerResolver::addMock('coffee.com', 'v=socialbox;sb-rpc=http://127.0.0.0:8086/;sb-key=sig:g59Cf8j1wmQmRg1MkveYbpdiZ-1-_hFU9eRRJmQAwmc;sb-exp=0');
|
||||
ServerResolver::addMock('teapot.com', 'v=socialbox;sb-rpc=http://127.0.0.0:8087/;sb-key=sig:MDXUuripAo_IAv-EZTEoFhpIdhsXxfMLNunSnQzxYiY;sb-exp=0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random username based on the given domain.
|
||||
*
|
||||
* @param string $domain The domain to be appended to the generated username.
|
||||
* @return string Returns a randomly generated username in the format 'user<randomString>@<domain>'.
|
||||
*/
|
||||
private static function generateUsername(string $domain): string
|
||||
{
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
|
||||
for ($i = 0; $i < 16; $i++)
|
||||
try
|
||||
{
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
$rpcClient = new SocialClient(Helper::generateRandomPeer(COFFEE_DOMAIN, prefix: 'pingTest'));
|
||||
$this->assertTrue($rpcClient->ping(), sprintf('Failed to ping %s', COFFEE_DOMAIN));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail('Failed to create RPC client: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
return 'user' . $randomString . '@' . $domain;
|
||||
}
|
||||
|
||||
private static function registerUser(string $domain, string $displayName): SocialClient
|
||||
public function testTeapotPing(): void
|
||||
{
|
||||
$client = new SocialClient(self::generateUsername($domain));
|
||||
$client->settingsSetPassword("password");
|
||||
$client->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, $displayName);
|
||||
return $client;
|
||||
}
|
||||
|
||||
public function testRegistration(): void
|
||||
{
|
||||
$coffeeClient = new SocialClient(self::generateUsername(self::COFFEE_DOMAIN));
|
||||
|
||||
// Check initial session state
|
||||
$this->assertFalse($coffeeClient->getSessionState()->isAuthenticated());
|
||||
$this->assertTrue($coffeeClient->getSessionState()->containsFlag(SessionFlags::REGISTRATION_REQUIRED));
|
||||
$this->assertTrue($coffeeClient->getSessionState()->containsFlag(SessionFlags::SET_PASSWORD));
|
||||
$this->assertTrue($coffeeClient->getSessionState()->containsFlag(SessionFlags::SET_DISPLAY_NAME));
|
||||
|
||||
// Check progressive session state
|
||||
$this->assertTrue($coffeeClient->settingsSetPassword('coffeePassword'));
|
||||
$this->assertFalse($coffeeClient->getSessionState()->containsFlag(SessionFlags::SET_PASSWORD));
|
||||
$this->assertTrue($coffeeClient->settingsAddInformationField(InformationFieldName::DISPLAY_NAME, 'Coffee User'));
|
||||
$this->assertFalse($coffeeClient->getSessionState()->containsFlag(SessionFlags::SET_DISPLAY_NAME));
|
||||
|
||||
$this->assertFalse($coffeeClient->getSessionState()->containsFlag(SessionFlags::REGISTRATION_REQUIRED));
|
||||
$this->assertTrue($coffeeClient->getSessionState()->isAuthenticated());
|
||||
}
|
||||
|
||||
public function testResolveDecentralizedPeer(): void
|
||||
{
|
||||
$coffeeUser = self::registerUser(self::COFFEE_DOMAIN, "Coffee Lover");
|
||||
$this->assertTrue($coffeeUser->getSessionState()->isAuthenticated());
|
||||
$teapotUser = self::registerUser(self::TEAPOT_DOMAIN, "Tea & Biscuits");
|
||||
$this->assertTrue($teapotUser->getSessionState()->isAuthenticated());
|
||||
|
||||
$coffeePeer = $coffeeUser->resolvePeer($teapotUser->getIdentifiedAs());
|
||||
try
|
||||
{
|
||||
$rpcClient = new SocialClient(Helper::generateRandomPeer(TEAPOT_DOMAIN, prefix: 'pingTest'));
|
||||
$this->assertTrue($rpcClient->ping(), sprintf('Failed to ping %s', TEAPOT_DOMAIN));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->fail('Failed to create RPC client: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
require 'ncc';
|
||||
import('net.nosial.socialbox');
|
||||
|
||||
\Socialbox\Classes\ServerResolver::addMock('coffee.com', 'v=socialbox;sb-rpc=http://127.0.0.0:8086/;sb-key=sig:g59Cf8j1wmQmRg1MkveYbpdiZ-1-_hFU9eRRJmQAwmc;sb-exp=0');
|
||||
\Socialbox\Classes\ServerResolver::addMock('teapot.com', 'v=socialbox;sb-rpc=http://127.0.0.0:8087/;sb-key=sig:MDXUuripAo_IAv-EZTEoFhpIdhsXxfMLNunSnQzxYiY;sb-exp=0');
|
||||
|
||||
$client = new \Socialbox\SocialClient(generateRandomPeer());
|
||||
var_dump($client->getSessionState());
|
||||
|
||||
|
||||
function generateRandomPeer()
|
||||
{
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
|
||||
for ($i = 0; $i < 16; $i++)
|
||||
{
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
|
||||
return 'userTest' . $randomString . '@coffee.com';
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue