123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <?php
- namespace Tests\Unit;
- if (!defined('INSTALLDIR')) {
- define('INSTALLDIR', dirname(dirname(__DIR__)));
- }
- if (!defined('PUBLICDIR')) {
- define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
- }
- if (!defined('GNUSOCIAL')) {
- define('GNUSOCIAL', true);
- }
- if (!defined('STATUSNET')) {
- define('STATUSNET', true);
- }
- use PHPUnit\Framework\TestCase;
- use PluginList;
- use XmppPlugin;
- require_once INSTALLDIR . '/lib/util/common.php';
- require_once INSTALLDIR . '/plugins/Xmpp/XmppPlugin.php';
- final class XmppValidateTest extends TestCase
- {
- protected function setUp(): void
- {
- if (!PluginList::isPluginActive('Xmpp')) {
- static::markTestSkipped('XmppPlugin is not enabled.');
- }
- }
-
- public function testValidate($jid, $validFull, $validBase)
- {
- $xmpp = new TestXmppPlugin();
- static::assertSame($validFull || $validBase, $xmpp->validate($jid));
- static::assertSame($validFull, $xmpp->validateFullJid($jid), 'validating as full or base JID');
- static::assertSame($validBase, $xmpp->validateBaseJid($jid), 'validating as base JID only');
- }
-
- public function testNormalize($jid, $expected)
- {
- $xmpp = new XmppPlugin();
- static::assertSame($expected, $xmpp->normalize($jid));
- }
-
- public function testDomainCheck($domain, $expected, $note)
- {
- $xmpp = new TestXmppPlugin();
- static::assertSame($expected, $xmpp->checkDomain($domain), $note);
- }
- public static function validationCases()
- {
- $long1023 = 'long1023' . str_repeat('x', 1023 - 8);
- $long1024 = 'long1024' . str_repeat('x', 1024 - 8);
- return [
-
-
- ['user@example.com', true, true],
- ['user@example.com/resource', true, false],
- ['user with spaces@example.com', false, false],
- ['user.@example.com', true, true],
- ['example.com', true, true],
- ['example.com/resource', true, false],
- ['jabchat', true, true],
- ["{$long1023}@{$long1023}/{$long1023}", true, false],
- ["{$long1024}@{$long1023}/{$long1023}", false, false],
- ["{$long1023}@{$long1024}/{$long1023}", false, false],
- ["{$long1023}@{$long1023}/{$long1024}", false, false],
-
- ['gmail.com', true, true],
- ['gmail.com/Test', true, false],
- ['gmail.com/Test@', true, false],
- ['gmail.com/@', true, false],
- ['gmail.com/Test@alkjaweflkj', true, false],
- ['mark.doliner@gmail.com', true, true],
- ['mark.doliner@gmail.com/Test12345', true, false],
- ['mark.doliner@gmail.com/Test@12345', true, false],
- ['mark.doliner@gmail.com/Te/st@12@//345', true, false],
- ['わいど@conference.jabber.org', true, true],
- ['まりるーむ@conference.jabber.org', true, true],
- ['mark.doliner@gmail.com/まりるーむ', true, false],
- ['mark.doliner@gmail/stuff.org', true, false],
- ['stuart@nödåtXäYZ.se', true, true],
- ['stuart@nödåtXäYZ.se/まりるーむ', true, false],
- ['mark.doliner@わいど.org', true, true],
- ['nick@まつ.おおかみ.net', true, true],
- ['paul@10.0.42.230/s', true, false],
- ['paul@[::1]', true, true],
- ['paul@[2001:470:1f05:d58::2]', true, true],
- ['paul@[2001:470:1f05:d58::2]/foo', true, false],
- ['pa=ul@10.0.42.230', true, true],
- ['pa,ul@10.0.42.230', true, true],
- ['@gmail.com', false, false],
- ['@@gmail.com', false, false],
- ['mark.doliner@@gmail.com/Test12345', false, false],
- ['mark@doliner@gmail.com/Test12345', false, false],
- ['@gmail.com/Test@12345', false, false],
- ['/Test@12345', false, false],
- ['mark.doliner@', false, false],
- ['mark.doliner/', false, false],
- ['mark.doliner@gmail_stuff.org', false, false],
- ['mark.doliner@gmail[stuff.org', false, false],
- ['mark.doliner@gmail\\stuff.org', false, false],
- ['paul@[::1]124', false, false],
- ['paul@2[::1]124/as', false, false],
- ["paul@まつ.おおかみ/\x01", false, false],
-
-
-
-
- ];
- }
- public static function normalizationCases()
- {
- return [
-
- ['PaUL@DaRkRain42.org', 'paul@darkrain42.org'],
- ['PaUL@DaRkRain42.org/', 'paul@darkrain42.org'],
- ['PaUL@DaRkRain42.org/resource', 'paul@darkrain42.org'],
-
- ['Ф@darkrain42.org', 'ф@darkrain42.org'],
- ['paul@Өarkrain.org', 'paul@өarkrain.org'],
- ];
- }
- public static function domainCheckCases()
- {
- return [
- ['gmail.com', true, 'known SRV record'],
- ['jabber.org', true, 'known SRV record'],
- ['status.net', true, 'known SRV record'],
- ['status.leuksman.com', true, 'known no SRV record but valid domain'],
- ];
- }
- }
- class TestXmppPlugin extends XmppPlugin
- {
- public function checkDomain($domain)
- {
- return parent::checkDomain($domain);
- }
- public function validateBaseJid($jid, $check_domain = false)
- {
- return parent::validateBaseJid($jid, $check_domain);
- }
- public function validateFullJid($jid, $check_domain = false)
- {
- return parent::validateFullJid($jid, $check_domain);
- }
- }
|