Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/jsxc.nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobia De Koninck <tobia@ledfan.be>2017-10-15 09:50:55 +0300
committerTobia De Koninck <tobia@ledfan.be>2017-10-15 09:50:55 +0300
commit4b6daef6b775e5372dce62ccaaba6faac3cff6c2 (patch)
tree1c724b67028904ffbdc6b7507bff90552b4ada01 /tests/integration
parent75b7a02f9478b23365d5fb4b3bbac2d3114498e5 (diff)
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 <tobia@ledfan.be>
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/db/IqRosterPushTest.php12
-rw-r--r--tests/integration/db/IqRosterTest.php12
-rw-r--r--tests/integration/db/MessageMapperTest.php26
-rw-r--r--tests/integration/db/PresenceMapperTest.php16
-rw-r--r--tests/integration/db/PresenceTest.php42
-rw-r--r--tests/integration/db/StanzaMapperTest.php30
6 files changed, 85 insertions, 53 deletions
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',
- '<message to="thomas@localhost" from="john@localhost" type="test" xmlns="jabber:client" id="4-msg">Test Message</message>'
+ // save stanza without host or resource
+ '<message to="thomas" from="john" type="test" xmlns="jabber:client" id="4-msg">Test Message</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('<message to="john@localhost.com@localhost/internal" from="jan@localhost.com@localhost/internal" type="test" xmlns="jabber:client" id="4-msg">Messageabc</message>', $result[0]->getStanza());
+ $this->assertEquals('<message to="john_ojsxc_esc_at_localhost.com@localhost/internal" from="jan_ojsxc_esc_at_localhost.com@localhost/internal" type="test" xmlns="jabber:client" id="4-msg">Messageabc</message>', $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 to="jan@localhost.com" from="thomas@localhost.com" type="test2" xmlns="jabber:client" id="4-msg">Message</message>', $result[0]->getStanza());
+ $this->assertEquals('<message to="jan_ojsxc_esc_at_localhost.com" from="thomas_ojsxc_esc_at_localhost.com" type="test2" xmlns="jabber:client" id="4-msg">Message</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', '<body xmlns="http://jabber.org/protocol/httpbind"><presence from="derp@own.dev" to="admin@own.dev" xmlns="jabber:client"><show>chat</show></presence></body>'),
- $this->generateSerializeData('admin@own.dev', 'derp@own.dev', 'online', '<body xmlns="http://jabber.org/protocol/httpbind"><presence from="derp@own.dev" to="admin@own.dev" xmlns="jabber:client" /></body>'),
- $this->generateSerializeData('admin@own.dev', 'derp@own.dev', 'away', '<body xmlns="http://jabber.org/protocol/httpbind"><presence from="derp@own.dev" to="admin@own.dev" xmlns="jabber:client"><show>away</show></presence></body>'),
- $this->generateSerializeData('admin@own.dev', 'derp@own.dev', 'unavailable', '<body xmlns="http://jabber.org/protocol/httpbind"><presence from="derp@own.dev" to="admin@own.dev" xmlns="jabber:client" type="unavailable"/></body>'),
- $this->generateSerializeData('admin@own.dev', 'derp@own.dev', 'ea', '<body xmlns="http://jabber.org/protocol/httpbind"><presence from="derp@own.dev" to="admin@own.dev" xmlns="jabber:client"><show>ea</show></presence></body>'),
- $this->generateSerializeData('admin@own.dev', 'derp@own.dev', 'dnd', '<body xmlns="http://jabber.org/protocol/httpbind"><presence from="derp@own.dev" to="admin@own.dev" xmlns="jabber:client"><show>dnd</show></presence></body>'),
+ $this->generateSerializeData(
+ 'admin',
+ 'derp',
+ 'chat',
+ '<body xmlns="http://jabber.org/protocol/httpbind"><presence from="derp" to="admin" xmlns="jabber:client"><show>chat</show></presence></body>'
+ ),
+ $this->generateSerializeData(
+ 'admin',
+ 'derp',
+ 'online',
+ '<body xmlns="http://jabber.org/protocol/httpbind"><presence from="derp" to="admin" xmlns="jabber:client" /></body>'
+ ),
+ $this->generateSerializeData(
+ 'admin',
+ 'derp',
+ 'away',
+ '<body xmlns="http://jabber.org/protocol/httpbind"><presence from="derp" to="admin" xmlns="jabber:client"><show>away</show></presence></body>'
+ ),
+ $this->generateSerializeData(
+ 'admin',
+ 'derp',
+ 'unavailable',
+ '<body xmlns="http://jabber.org/protocol/httpbind"><presence from="derp" to="admin" xmlns="jabber:client" type="unavailable"/></body>'
+ ),
+ $this->generateSerializeData(
+ 'admin',
+ 'derp',
+ 'ea',
+ '<body xmlns="http://jabber.org/protocol/httpbind"><presence from="derp" to="admin" xmlns="jabber:client"><show>ea</show></presence></body>'
+ ),
+ $this->generateSerializeData(
+ 'admin',
+ 'derp',
+ 'dnd',
+ '<body xmlns="http://jabber.org/protocol/httpbind"><presence from="derp" to="admin" xmlns="jabber:client"><show>dnd</show></presence></body>'
+ ),
];
}
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']);
}
}