From 4b6daef6b775e5372dce62ccaaba6faac3cff6c2 Mon Sep 17 00:00:00 2001 From: Tobia De Koninck Date: Sun, 15 Oct 2017 08:50:55 +0200 Subject: Escape characters allowed in the NC username which is not allowed in the XMPP username. - `@`, `'`, ` `, will now be replaced by `_ojsxc_esc_space_`, `_ojsxc_squote_space_` and `_ojsxc_esc_at_` respectively - cleanuped tests and code to always store the userId and not a JID in the database Signed-off-by: Tobia De Koninck --- tests/integration/db/IqRosterPushTest.php | 12 ++++----- tests/integration/db/IqRosterTest.php | 12 ++++----- tests/integration/db/MessageMapperTest.php | 26 +++++++++--------- tests/integration/db/PresenceMapperTest.php | 16 +++++------ tests/integration/db/PresenceTest.php | 42 ++++++++++++++++++++++++----- tests/integration/db/StanzaMapperTest.php | 30 ++++++++++----------- 6 files changed, 85 insertions(+), 53 deletions(-) (limited to 'tests/integration') diff --git a/tests/integration/db/IqRosterPushTest.php b/tests/integration/db/IqRosterPushTest.php index e6e8c0d..7be4278 100644 --- a/tests/integration/db/IqRosterPushTest.php +++ b/tests/integration/db/IqRosterPushTest.php @@ -16,15 +16,15 @@ class IqRosterPushTest extends TestCase $writer->writeAttribute('xmlns', 'http://jabber.org/protocol/httpbind'); $iqRosterPush = new IQRosterPush(); - $iqRosterPush->setJid('john@localhost'); - $iqRosterPush->setTo('jan@localhost'); + $iqRosterPush->setJid('john', 'localhost'); + $iqRosterPush->setTo('jan', 'localhost'); $iqRosterPush->setName('john'); $iqRosterPush->setSubscription('both'); - $this->assertEquals($iqRosterPush->getJid(), 'john@localhost'); - $this->assertEquals($iqRosterPush->getTo(), 'jan@localhost'); - $this->assertEquals($iqRosterPush->getName(), 'john'); - $this->assertEquals($iqRosterPush->getSubscription(), 'both'); + $this->assertEquals('john@localhost', $iqRosterPush->getJid()); + $this->assertEquals('jan@localhost', $iqRosterPush->getTo()); + $this->assertEquals('john', $iqRosterPush->getName()); + $this->assertEquals('both', $iqRosterPush->getSubscription()); $writer->write($iqRosterPush); // needed to test the xmlSerialize function diff --git a/tests/integration/db/IqRosterTest.php b/tests/integration/db/IqRosterTest.php index beb60bb..0ecb4dc 100644 --- a/tests/integration/db/IqRosterTest.php +++ b/tests/integration/db/IqRosterTest.php @@ -17,15 +17,15 @@ class IqRosterTest extends TestCase $iqRoster = new IQRoster(); $iqRoster->setType('result'); - $iqRoster->setTo('john@localhost'); + $iqRoster->setTo('john', 'localhost'); $iqRoster->setQid(4434); $iqRoster->addItem('test@test.be', 'Test Test'); $iqRoster->addItem('test2@test.be', 'Test2 Test'); - $this->assertEquals($iqRoster->getType(), 'result'); - $this->assertEquals($iqRoster->getTo(), 'john@localhost'); - $this->assertEquals($iqRoster->getQid(), 4434); - $this->assertEquals($iqRoster->getItems(), [ + $this->assertEquals('result', $iqRoster->getType()); + $this->assertEquals('john@localhost', $iqRoster->getTo()); + $this->assertEquals(4434, $iqRoster->getQid()); + $this->assertEquals([ [ "name" => "item", "attributes" => [ @@ -44,7 +44,7 @@ class IqRosterTest extends TestCase ], "value" => '' ], - ]); + ], $iqRoster->getItems()); $writer->write($iqRoster); // needed to test the xmlSerialize function diff --git a/tests/integration/db/MessageMapperTest.php b/tests/integration/db/MessageMapperTest.php index 638b00f..7094b94 100644 --- a/tests/integration/db/MessageMapperTest.php +++ b/tests/integration/db/MessageMapperTest.php @@ -2,6 +2,7 @@ namespace OCA\OJSXC\Db; +use OCA\OJSXC\AppInfo\Application; use OCA\OJSXC\Utility\MapperTestUtility; use OCP\AppFramework\Db\DoesNotExistException; @@ -33,12 +34,13 @@ class MessageMapperTest extends MapperTestUtility { return [ [ - 'john@localhost', - 'thomas@localhost', + ['john', 'localhost'], + ['thomas', 'localhost'], 'abcd', 'test', 'Test Message', - 'Test Message' + // save stanza without host or resource + 'Test Message' ] ]; } @@ -49,14 +51,14 @@ class MessageMapperTest extends MapperTestUtility public function testInsert($from, $to, $data, $type, $msg, $expectedStanza) { $stanza = new Message(); - $stanza->setFrom($from); - $stanza->setTo($to); + $stanza->setFrom($from[0]); + $stanza->setTo($to[0]); $stanza->setStanza($data); $stanza->setType($type); $stanza->setValue($msg); - $this->assertEquals($stanza->getFrom(), $from); - $this->assertEquals($stanza->getTo(), $to); + $this->assertEquals($stanza->getFrom(), $from[0]); + $this->assertEquals($stanza->getTo(), $to[0]); $this->assertEquals($stanza->getStanza(), $data); $this->assertEquals($stanza->getType(), $type); @@ -85,8 +87,8 @@ class MessageMapperTest extends MapperTestUtility public function testFindByToNotFound2() { $stanza = new Message(); - $stanza->setFrom('john@localhost'); - $stanza->setTo('john@localhost'); + $stanza->setFrom('john', 'localhost'); + $stanza->setTo('john', 'localhost'); $stanza->setStanza('abcd'); $stanza->setType('test'); $stanza->setValue('message abc'); @@ -157,15 +159,15 @@ class MessageMapperTest extends MapperTestUtility $this->assertCount(2, $result); // check findByTo - $result = $this->mapper->findByTo('john@localhost.com'); + $result = $this->mapper->findByTo(Application::santizeUserId('john@localhost.com')); $this->assertCount(1, $result); - $this->assertEquals('Messageabc', $result[0]->getStanza()); + $this->assertEquals('Messageabc', $result[0]->getStanza()); // check if element is deleted $result = $this->fetchAll(); $this->assertCount(1, $result); $this->assertEquals($stanza2->getFrom(), $result[0]->getFrom()); $this->assertEquals($stanza2->getTo(), $result[0]->getTo()); - $this->assertEquals('Message', $result[0]->getStanza()); + $this->assertEquals('Message', $result[0]->getStanza()); } } diff --git a/tests/integration/db/PresenceMapperTest.php b/tests/integration/db/PresenceMapperTest.php index 23b1624..a81cdd3 100644 --- a/tests/integration/db/PresenceMapperTest.php +++ b/tests/integration/db/PresenceMapperTest.php @@ -207,15 +207,15 @@ class PresenceMapperTest extends MapperTestUtility $expected1->setUserid('derp'); $expected1->setPresence('online'); $expected1->setLastActive(23434353); - $expected1->setTo('admin@localhost/internal'); - $expected1->setFrom('derp@localhost/internal'); + $expected1->setTo('admin', 'localhost/internal'); + $expected1->setFrom('derp', 'localhost/internal'); $expected2 = new PresenceEntity(); $expected2->setUserid('derpina'); $expected2->setPresence('chat'); $expected2->setLastActive(23445645634); - $expected2->setTo('admin@localhost/internal'); - $expected2->setFrom('derpina@localhost/internal'); + $expected2->setTo('admin', 'localhost/internal'); + $expected2->setFrom('derpina', 'localhost/internal'); return [ [ [$input1, $input2, $input3, $input4, $input5], @@ -321,13 +321,13 @@ class PresenceMapperTest extends MapperTestUtility $expStanza1 = new PresenceEntity(); $expStanza1->setPresence('unavailable'); - $expStanza1->setFrom('derp' . '@localhost/internal'); - $expStanza1->setTo('admin' . '@localhost/internal'); + $expStanza1->setFrom('derp', 'localhost/internal'); + $expStanza1->setTo('admin', 'localhost/internal'); $expStanza2 = new PresenceEntity(); $expStanza2->setPresence('unavailable'); - $expStanza2->setFrom('derpina' . '@localhost/internal'); - $expStanza2->setTo('admin' . '@localhost/internal'); + $expStanza2->setFrom('derpina', 'localhost/internal'); + $expStanza2->setTo('admin', 'localhost/internal'); return [ [ diff --git a/tests/integration/db/PresenceTest.php b/tests/integration/db/PresenceTest.php index 7c7bfa0..47519a4 100644 --- a/tests/integration/db/PresenceTest.php +++ b/tests/integration/db/PresenceTest.php @@ -88,12 +88,42 @@ class PresenceTest extends TestCase public function serializeProvider() { return [ - $this->generateSerializeData('admin@own.dev', 'derp@own.dev', 'chat', 'chat'), - $this->generateSerializeData('admin@own.dev', 'derp@own.dev', 'online', ''), - $this->generateSerializeData('admin@own.dev', 'derp@own.dev', 'away', 'away'), - $this->generateSerializeData('admin@own.dev', 'derp@own.dev', 'unavailable', ''), - $this->generateSerializeData('admin@own.dev', 'derp@own.dev', 'ea', 'ea'), - $this->generateSerializeData('admin@own.dev', 'derp@own.dev', 'dnd', 'dnd'), + $this->generateSerializeData( + 'admin', + 'derp', + 'chat', + 'chat' + ), + $this->generateSerializeData( + 'admin', + 'derp', + 'online', + '' + ), + $this->generateSerializeData( + 'admin', + 'derp', + 'away', + 'away' + ), + $this->generateSerializeData( + 'admin', + 'derp', + 'unavailable', + '' + ), + $this->generateSerializeData( + 'admin', + 'derp', + 'ea', + 'ea' + ), + $this->generateSerializeData( + 'admin', + 'derp', + 'dnd', + 'dnd' + ), ]; } diff --git a/tests/integration/db/StanzaMapperTest.php b/tests/integration/db/StanzaMapperTest.php index 279b2a1..1cbb50b 100644 --- a/tests/integration/db/StanzaMapperTest.php +++ b/tests/integration/db/StanzaMapperTest.php @@ -27,8 +27,8 @@ class StanzaMapperTest extends MapperTestUtility { return [ [ - 'john@localhost', - 'thomas@localhost', + 'john', + 'thomas', 'abcd' ] ]; @@ -83,14 +83,14 @@ class StanzaMapperTest extends MapperTestUtility public function testFindByToFound() { $stanza1 = new Stanza(); - $stanza1->setFrom('jan@localhost'); - $stanza1->setTo('john@localhost'); + $stanza1->setFrom('jan'); + $stanza1->setTo('john'); $stanza1->setStanza('abcd1'); $this->mapper->insert($stanza1); $stanza2 = new Stanza(); - $stanza2->setFrom('thomas@localhost'); - $stanza2->setTo('jan@localhost'); + $stanza2->setFrom('thomas'); + $stanza2->setTo('jan'); $stanza2->setStanza('abcd2'); $this->mapper->insert($stanza2); @@ -100,7 +100,7 @@ class StanzaMapperTest extends MapperTestUtility $this->assertCount(2, $result); // check findByTo - $result = $this->mapper->findByTo('john@localhost'); + $result = $this->mapper->findByTo('john'); $this->assertCount(1, $result); $this->assertEquals($stanza1->getStanza(), $result[0]->getStanza()); @@ -116,30 +116,30 @@ class StanzaMapperTest extends MapperTestUtility public function testDeleteByTo() { $stanza1 = new Stanza(); - $stanza1->setFrom('jan@localhost'); - $stanza1->setTo('john@localhost'); + $stanza1->setFrom('jan'); + $stanza1->setTo('john'); $stanza1->setStanza('abcd1'); $this->mapper->insert($stanza1); $stanza2 = new Stanza(); - $stanza2->setFrom('thomas@localhost'); - $stanza2->setTo('jan@localhost'); + $stanza2->setFrom('thomas'); + $stanza2->setTo('jan'); $stanza2->setStanza('abcd2'); $this->mapper->insert($stanza2); // check if two elements are inserted $result = $this->fetchAllAsArray(); $this->assertArrayDbResultsEqual([ - ['from' => 'jan@localhost', 'to' => 'john@localhost', 'stanza' => 'abcd1'], - ['from' => 'thomas@localhost', 'to' => 'jan@localhost', 'stanza' => 'abcd2'] + ['from' => 'jan', 'to' => 'john', 'stanza' => 'abcd1'], + ['from' => 'thomas', 'to' => 'jan', 'stanza' => 'abcd2'] ], $result, ['from', 'to', 'stanza']); - $this->mapper->deleteByTo('jan@localhost'); + $this->mapper->deleteByTo('jan'); $result = $this->fetchAllAsArray(); $this->assertArrayDbResultsEqual([ - ['from' => 'jan@localhost', 'to' => 'john@localhost', 'stanza' => 'abcd1'] + ['from' => 'jan', 'to' => 'john', 'stanza' => 'abcd1'] ], $result, ['from', 'to', 'stanza']); } } -- cgit v1.2.3