mirror of
https://framagit.org/hubzilla/core.git
synced 2026-06-21 00:52:33 -04:00
tests: A few more xchan tests
This commit is contained in:
@@ -8,27 +8,67 @@
|
||||
|
||||
namespace Zotlabs\Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\Attributes\Before;
|
||||
use Zotlabs\Lib\Libzot;
|
||||
|
||||
class XChanTest extends UnitTestCase {
|
||||
|
||||
public function testXChanFetchShouldRejectInvalidArgs(): void {
|
||||
$addr = 'example';
|
||||
$guid = Libzot::new_uid($addr);
|
||||
$hash = Libzot::make_xchan_hash($guid, 'dummy-public-key');
|
||||
private string $addr;
|
||||
private string $guid;
|
||||
private string $hash;
|
||||
|
||||
#[Before]
|
||||
public function populateXChans(): void {
|
||||
$this->addr = 'example';
|
||||
$this->guid = Libzot::new_uid($this->addr);
|
||||
$this->hash = Libzot::make_xchan_hash($this->guid, 'dummy-public-key');
|
||||
|
||||
xchan_store_lowlevel([
|
||||
'xchan_hash' => $hash,
|
||||
'xchan_guid' => $guid,
|
||||
'xchan_addr' => $addr,
|
||||
'xchan_hash' => $this->hash,
|
||||
'xchan_guid' => $this->guid,
|
||||
'xchan_addr' => $this->addr,
|
||||
]);
|
||||
}
|
||||
|
||||
public function testXChanFetchReturnsStoredXchan(): void {
|
||||
$byHash = xchan_fetch(['hash' => $this->hash]);
|
||||
$this->assertIsArray($byHash);
|
||||
$this->assertEquals($this->addr, $byHash['address']);
|
||||
$this->assertEquals($this->guid, $byHash['guid']);
|
||||
$this->assertEquals($this->hash, $byHash['hash']);
|
||||
|
||||
$byGuid = xchan_fetch(['guid' => $this->guid]);
|
||||
$this->assertIsArray($byGuid);
|
||||
$this->assertEquals($this->addr, $byGuid['address']);
|
||||
$this->assertEquals($this->guid, $byGuid['guid']);
|
||||
$this->assertEquals($this->hash, $byGuid['hash']);
|
||||
|
||||
$byAddr = xchan_fetch(['address' => $this->addr]);
|
||||
$this->assertIsArray($byAddr);
|
||||
$this->assertEquals($this->addr, $byAddr['address']);
|
||||
$this->assertEquals($this->guid, $byAddr['guid']);
|
||||
$this->assertEquals($this->hash, $byAddr['hash']);
|
||||
}
|
||||
|
||||
public function testXChanFetchShouldRejectInvalidArgs(): void {
|
||||
// Trivial SQL Injection
|
||||
$this->assertFalse(xchan_fetch(['hash' => "{$hash}' or 1=1; -- "]));
|
||||
$this->assertFalse(xchan_fetch(['guid' => "{$guid}' or 1=1; -- "]));
|
||||
$this->assertFalse(xchan_fetch(['address' => "{$addr}' or 1=1; -- "]));
|
||||
$this->assertFalse(xchan_fetch(['hash' => "{$this->hash}' or 1=1; -- "]));
|
||||
$this->assertFalse(xchan_fetch(['guid' => "{$this->guid}' or 1=1; -- "]));
|
||||
$this->assertFalse(xchan_fetch(['address' => "{$this->addr}' or 1=1; -- "]));
|
||||
|
||||
// Not a valid key
|
||||
$this->assertFalse(xchan_fetch(['wrongkey' => $hash]));
|
||||
$this->assertFalse(xchan_fetch(['wrongkey' => $this->hash]));
|
||||
|
||||
// Empty values
|
||||
$this->assertFalse(xchan_fetch(['hash' => '']));
|
||||
$this->assertFalse(xchan_fetch(['guid' => '']));
|
||||
$this->assertFalse(xchan_fetch(['address' => '']));
|
||||
|
||||
// Non existing xchan hash/guid/address
|
||||
$this->assertFalse(xchan_fetch([
|
||||
'hash' => Libzot::make_xchan_hash(Libzot::new_uid('nobody'), 'another-dummy-key')
|
||||
]));
|
||||
$this->assertFalse(xchan_fetch(['guid' => Libzot::new_uid('nobody')]));
|
||||
$this->assertFalse(xchan_fetch(['address' => 'nobody']));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user