- add tests for stable8, stable8.1, stable8.2 and master
 - fix some unit tests so they don't produce errors
 - add extra bootstrap files for both integratoin and unit tests
 - disable incomplete tests which causes errors
 - Support ownCloud 8.0
   - disable MemLock in version 8.0 since the API isn't very usable
   - use own getServerHost when the method doesn't exists
   - add namespace declartion in infox.ml
   - remove unused OCP\ISession in HttpBindController
   - use IDbConnection in tests
   - use prepareQuery() when using OCP\IDb
This commit is contained in:
LEDfan 2016-01-29 12:33:22 +01:00
Родитель 589453df3a
Коммит d2bf3d7bf4
21 изменённых файлов: 220 добавлений и 98 удалений

Просмотреть файл

@ -1,10 +1,10 @@
sudo: required
language: php
php:
- 5.4
- 5.5
- 5.6
- 7
- hhvm
services:
- redis-server
@ -16,65 +16,24 @@ env:
- DB=mysql
matrix:
allow_failures:
- php: hhvm
include:
- php: 5.4
env: DB=sqlite
- php: 5.4
env: DB=pgsql
- php: 5.6
env: DB=mysql BRANCH=stable8
- php: 5.6
env: DB=mysql BRANCH=stable8.1
- php: 5.6
env: DB=mysql BRANCH=stable8.2
install:
# install ocdev
- sudo apt-get update
- sudo apt-get -y install python3-jinja2 python3-setuptools
- sudo easy_install3 requests
- sudo easy_install3 ocdev
# set up postgresql
- createuser -U travis -s oc_autotest
# set up mysql
- mysql -e 'create database oc_autotest;'
- mysql -u root -e "CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY '';"
- mysql -u root -e "grant all on oc_autotest.* to 'oc_autotest'@'localhost';"
# install owncloud
- cd ..
- ocdev setup core --dir owncloud --branch $BRANCH --no-history
- mv jsxc.chat owncloud/apps/ojsxc
- |
if [[ $TRAVIS_PHP_VERSION = "hhv"* ]]; then
echo "PHP7"
else
phpenv config-add owncloud/apps/ojsxc/tests/travis/php.ini
fi
- cd owncloud
- ./occ maintenance:install --database-name oc_autotest --database-user oc_autotest --database-pass --admin-user admin --admin-pass admin --database $DB
- ./occ app:enable ojsxc
- pear config-set preferred_state beta
- yes '' | pecl install apcu-4.0.10
before_script:
- cd apps/ojsxc
- composer install
install: ./tests/travis/install-$BRANCH.sh
# Note the install script should make sure we are in the apps/ojsxc directory
script:
- cd ../../
- ./occ config:import apps/ojsxc/tests/travis/config-redis.json
- cd apps/ojsxc
- composer install
- phpunit -c phpunit.xml
- phpunit -c phpunit.integration.xml
- cd ../../
- ./occ config:system:delete 'memcache.local'
- ./occ config:system:delete 'redis'
- |
if [[ $TRAVIS_PHP_VERSION = "hhv"* ]]; then
echo "PHP7"
else
./occ config:import apps/ojsxc/tests/travis/config-apcu.json
cd apps/ojsxc
phpunit -c phpunit.xml
phpunit -c phpunit.integration.xml
cat ../../data/owncloud.log
fi
- cat ../../data/owncloud.log

Просмотреть файл

@ -36,4 +36,4 @@ if(class_exists('\\OCP\\AppFramework\\Http\\EmptyContentSecurityPolicy')) {
require_once __DIR__ ."/../vendor/autoload.php";
?>
?>

Просмотреть файл

@ -33,7 +33,6 @@ class Application extends App {
$c->query('AppName'),
$c->query('Request'),
$c->query('UserId'),
$c->query('OCP\ISession'),
$c->query('StanzaMapper'),
$c->query('IQHandler'),
$c->query('MessageHandler'),
@ -85,7 +84,12 @@ class Application extends App {
* Config values
*/
$container->registerService('Host', function($c){
return $c->query('Request')->getServerHost();
$request = $c->query('Request');
if (method_exists($request, 'getServerHost')) {
return $c->query('Request')->getServerHost();
} else {
return $this->getServerHost();
}
});
}
@ -97,8 +101,10 @@ class Application extends App {
$c = $this->getContainer();
if (self::$config['use_memcache']['locking'] === true) {
$cache = $c->getServer()->getMemCacheFactory();
if ($cache->isAvailable()) {
$version = \OC::$server->getSession()->get('OC_Version');
if ($version[0] === 8 && $version[1] == 0){
$c->getServer()->getLogger()->warning('OJSXC is configured to use memcache as backend for locking, but ownCloud version 8 doesn\'t suppor this.');
} else if ($cache->isAvailable()) {
$memcache = $cache->create('ojsxc');
return new MemLock(
$c->query('UserId'),
@ -117,5 +123,47 @@ class Application extends App {
);
}
/**
* Helper function
* https://github.com/owncloud/core/blob/a977465af5834a76b1e98854a2c9bfbe413c218c/lib/private/appframework/http/request.php#L518
* @return string
*/
private function getServerHost() {
$host = 'localhost';
if (isset($this->server['HTTP_X_FORWARDED_HOST'])) {
if (strpos($this->server['HTTP_X_FORWARDED_HOST'], ',') !== false) {
$parts = explode(',', $this->server['HTTP_X_FORWARDED_HOST']);
$host = trim(current($parts));
} else {
$host = $this->server['HTTP_X_FORWARDED_HOST'];
}
} else {
if (isset($this->server['HTTP_HOST'])) {
$host = $this->server['HTTP_HOST'];
} else if (isset($this->server['SERVER_NAME'])) {
$host = $this->server['SERVER_NAME'];
}
}
if ($host !== null) {
return $host;
}
// get the host from the headers
$host = $this->getInsecureServerHost();
// Verify that the host is a trusted domain if the trusted domains
// are defined
// If no trusted domain is provided the first trusted domain is returned
$trustedDomainHelper = new TrustedDomainHelper($this->config);
if ($trustedDomainHelper->isTrustedDomain($host)) {
return $host;
} else {
$trustedList = $this->config->getSystemValue('trusted_domains', []);
if(!empty($trustedList)) {
return $trustedList[0];
} else {
return '';
}
}
}
}

Просмотреть файл

@ -11,4 +11,5 @@
<bugs>http://github.com/jsxc/jsxc/issues</bugs>
<repository type="git">http://github.com/jsxc/jsxc.owncloud.git</repository>
<ocsid>162257</ocsid>
<namespace>OJSXC</namespace>
</info>

Просмотреть файл

@ -12,23 +12,23 @@ use \OCA\OJSXC\AppInfo\Application;
$this->create('ojsxc_ajax_getsettings', 'ajax/getsettings.php')
->actionInclude('ojsxc/ajax/getsettings.php');
$this->create('ojsxc_ajax_getturncredentials', 'ajax/getturncredentials.php')
->actionInclude('ojsxc/ajax/getturncredentials.php');
$this->create('ojsxc_ajax_setsettings', 'ajax/setsettings.php')
->actionInclude('ojsxc/ajax/setsettings.php');
$this->create('ojsxc_ajax_setUserSettings', 'ajax/setUserSettings.php')
->actionInclude('ojsxc/ajax/setUserSettings.php');
$this->create('ojsxc_ajax_getUsers', 'ajax/getUsers.php')
->actionInclude('ojsxc/ajax/getUsers.php');
$application = new Application();
$application->registerRoutes($this, array(
'routes' => array(
array('name' => 'http_bind#index', 'url' => '/http-bind', 'verb' => array('GET', 'POST')),
array('name' => 'http_bind#index', 'url' => '/http-bind', 'verb' => 'POST'),
)
));
?>

Просмотреть файл

@ -113,7 +113,6 @@ class HttpBindController extends Controller {
public function __construct($appName,
IRequest $request,
$userId,
ISession $session,
StanzaMapper $stanzaMapper,
IQ $iqHandler,
Message $messageHandler,
@ -126,7 +125,6 @@ class HttpBindController extends Controller {
parent::__construct($appName, $request);
$this->userId = $userId;
$this->pollingId = time();
$this->session = $session;
$this->stanzaMapper = $stanzaMapper;
$this->host = $host;
$this->iqHandler = $iqHandler;
@ -147,7 +145,7 @@ class HttpBindController extends Controller {
$this->lock->setLock();
$input = $this->body;
$longpoll = true; // set to false when the response should directly be returned and no polling should be done
if (!empty($input)){
if (!empty($input)) {
// replace invalid XML by valid XML one
$input = str_replace("<vCard xmlns='vcard-temp'/>", "<vCard xmlns='jabber:vcard-temp'/>", $input);
$reader = new Reader();
@ -155,22 +153,24 @@ class HttpBindController extends Controller {
$reader->elementMap = [
'{jabber:client}message' => 'Sabre\Xml\Element\KeyValue',
];
$stanzas = null;
try {
$stanzas = $reader->parse();
} catch (LibXMLException $e){
} catch (LibXMLException $e) {
}
$stanzas = $stanzas['value'];
if (is_array($stanzas)) {
foreach ($stanzas as $stanza) {
$stanzaType = $this->getStanzaType($stanza);
if ($stanzaType === self::MESSAGE) {
$this->messageHandler->handle($stanza);
} else if ($stanzaType === self::IQ) {
$result = $this->iqHandler->handle($stanza);
if (!is_null($result)) {
$longpoll = false;
$this->response->write($result);
if (!is_null($stanzas)) {
$stanzas = $stanzas['value'];
if (is_array($stanzas)) {
foreach ($stanzas as $stanza) {
$stanzaType = $this->getStanzaType($stanza);
if ($stanzaType === self::MESSAGE) {
$this->messageHandler->handle($stanza);
} else if ($stanzaType === self::IQ) {
$result = $this->iqHandler->handle($stanza);
if (!is_null($result)) {
$longpoll = false;
$this->response->write($result);
}
}
}
}

Просмотреть файл

@ -6,6 +6,7 @@ use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\Mapper;
use OCP\IDb;
use OCP\IDBConnection;
use Sabre\Xml\Writer;
/**
@ -38,7 +39,7 @@ class StanzaMapper extends Mapper {
$writer->write($entity);
$xml = $writer->outputMemory();
$sql = "INSERT INTO `*PREFIX*ojsxc_stanzas` (`to`, `from`, `stanza`) VALUES(?,?,?)";
$q = $this->db->prepare($sql);
$q = $this->db->prepareQuery($sql);
$q->execute([$entity->getTo(), $entity->getFrom(), $xml]);
}
@ -52,7 +53,7 @@ class StanzaMapper extends Mapper {
$stmt = $this->execute("SELECT stanza, id FROM *PREFIX*ojsxc_stanzas WHERE `to`=?", [$to]);
$results = [];
while($row = $stmt->fetch()){
$row['stanza'] =preg_replace('/to="([a-zA-z]*)"/', "to=\"$1@" .$this->host ."\"", $row['stanza']);
$row['stanza'] = preg_replace('/to="([a-zA-z]*)"/', "to=\"$1@" .$this->host ."\"", $row['stanza']);
$row['stanza'] = preg_replace('/from="([a-zA-z]*)"/', "from=\"$1@" .$this->host ."\"", $row['stanza']);
$results[] = $this->mapRowToEntity($row);
}
@ -65,6 +66,7 @@ class StanzaMapper extends Mapper {
foreach($results as $result){
$this->delete($result);
}
return $results;
}

Просмотреть файл

@ -1,4 +1,4 @@
<phpunit bootstrap="tests/bootstrap.php"
<phpunit bootstrap="tests/bootstrap-integration.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"

Просмотреть файл

@ -1,4 +1,4 @@
<phpunit bootstrap="../../lib/base.php"
<phpunit bootstrap="tests/bootstrap-unit.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"

Просмотреть файл

@ -0,0 +1,8 @@
<?php
try {
require_once __DIR__ . '/../../../tests/bootstrap.php';
} catch (Exception $ex) {
require_once __DIR__ . '/../../../lib/base.php';
}
require_once __DIR__ . '/../vendor/autoload.php';

3
tests/bootstrap-unit.php Normal file
Просмотреть файл

@ -0,0 +1,3 @@
<?php
require_once __DIR__ . '/../../../lib/base.php';
require_once __DIR__ . '/../vendor/autoload.php';

Просмотреть файл

@ -1,3 +0,0 @@
<?php
require_once __DIR__ . '/../../../tests/bootstrap.php';
require_once __DIR__ . '/../vendor/autoload.php';

Просмотреть файл

@ -37,7 +37,7 @@ class DbLockTest extends TestCase {
parent::setUp();
$app = new Application();
$this->container = $app->getContainer();
$this->con = $this->container->getServer()->getDb();
$this->con = $this->container->getServer()->getDatabaseConnection();
$this->con->executeQuery("DELETE FROM `*PREFIX*preferences` WHERE `appid`='ojsxc' AND `configkey`='longpolling'");
}

Просмотреть файл

@ -41,6 +41,12 @@ class MemLockTest extends TestCase {
parent::setUp();
$app = new Application();
$this->container = $app->getContainer();
$version = \OC::$server->getSession()->get('OC_Version');
if ($version[0] === 8 && $version[1] == 0) {
$this->markTestSkipped();
}
}
/**

Просмотреть файл

@ -1,5 +0,0 @@
{
"system": {
"memcache.local" : "\\OC\\Memcache\\APCu"
}
}

24
tests/travis/install-master.sh Executable file
Просмотреть файл

@ -0,0 +1,24 @@
#!/bin/bash -x
# install ocdev
sudo apt-get update
sudo apt-get -y install python3-jinja2 python3-setuptools
sudo easy_install3 requests
sudo easy_install3 ocdev
# set up postgresql
createuser -U travis -s oc_autotest
# set up mysql
mysql -e 'create database oc_autotest;'
mysql -u root -e "CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY '';"
mysql -u root -e "grant all on oc_autotest.* to 'oc_autotest'@'localhost';"
# install owncloud
cd ..
ocdev setup core --dir owncloud --branch $BRANCH --no-history
mv jsxc.chat owncloud/apps/ojsxc
phpenv config-add owncloud/apps/ojsxc/tests/travis/php.ini
cd owncloud
./occ maintenance:install --database-name oc_autotest --database-user oc_autotest --database-pass --admin-user admin --admin-pass admin --database $DB
./occ app:enable ojsxc
# before_script:
./occ config:import apps/ojsxc/tests/travis/config-redis.json
cd apps/ojsxc

Просмотреть файл

@ -0,0 +1,21 @@
#!/bin/bash -x
# install ocdev
sudo apt-get update
sudo apt-get -y install python3-jinja2 python3-setuptools
sudo easy_install3 requests
sudo easy_install3 ocdev
# set up postgresql
createuser -U travis -s oc_autotest
# set up mysql
mysql -e 'create database oc_autotest;'
mysql -u root -e "CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY '';"
mysql -u root -e "grant all on oc_autotest.* to 'oc_autotest'@'localhost';"
# install owncloud
cd ..
ocdev setup core --dir owncloud --branch $BRANCH --no-history
mv jsxc.chat owncloud/apps/ojsxc
phpenv config-add owncloud/apps/ojsxc/tests/travis/php.ini
cd owncloud
./occ maintenance:install --database-name oc_autotest --database-user oc_autotest --database-pass --admin-user admin --admin-pass admin --database $DB
./occ app:enable ojsxc
cd apps/ojsxc

Просмотреть файл

@ -0,0 +1,21 @@
#!/bin/bash -x
# install ocdev
sudo apt-get update
sudo apt-get -y install python3-jinja2 python3-setuptools
sudo easy_install3 requests
sudo easy_install3 ocdev
# set up postgresql
reateuser -U travis -s oc_autotest
# set up mysql
mysql -e 'create database oc_autotest;'
mysql -u root -e "CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY '';"
mysql -u root -e "grant all on oc_autotest.* to 'oc_autotest'@'localhost';"
# install owncloud
cd ..
ocdev setup core --dir owncloud --branch $BRANCH --no-history
mv jsxc.chat owncloud/apps/ojsxc
phpenv config-add owncloud/apps/ojsxc}/tests/travis/php.ini
cd owncloud
./occ maintenance:install --database-name oc_autotest --database-user oc_autotest --database-pass --admin-user admin --admin-pass admin --database $DB
./occ app:enable ojsxc
cd apps/ojsxc

23
tests/travis/install-stable8.sh Executable file
Просмотреть файл

@ -0,0 +1,23 @@
#!/bin/bash -x
# install ocdev
sudo apt-get update
sudo apt-get -y install python3-jinja2 python3-setuptools
sudo easy_install3 requests
sudo easy_install3 ocdev
# set up postgresql
createuser -U travis -s oc_autotest
# set up mysql
mysql -e 'create database oc_autotest;'
mysql -u root -e "CREATE USER 'oc_autotest'@'localhost';"
mysql -u root -e "grant all on oc_autotest.* to 'oc_autotest'@'localhost';"
# install owncloud
cd ..
ocdev setup core --dir owncloud --branch $BRANCH --no-history
cd owncloud
ocdev ci $DB
#enable ojsxc
mv ../jsxc.chat apps/ojsxc
php -f console.php app:enable ojsxc
cd apps/ojsxc

Просмотреть файл

@ -1,4 +1,3 @@
default_charset = "UTF-8"
always_populate_raw_post_data = -1
extension="redis.so"
extension="apc.so"

Просмотреть файл

@ -62,7 +62,6 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase {
*/
private function setUpController($requestBody) {
$request = $this->getMockBuilder('OCP\IRequest')->disableOriginalConstructor()->getMock();
$session = $this->getMockBuilder('OCP\ISession')->disableOriginalConstructor()->getMock();
$this->stanzaMapper = $this->getMockBuilder('OCA\OJSXC\Db\StanzaMapper')->disableOriginalConstructor()->getMock();
$this->iqHandler = $this->getMockBuilder('OCA\OJSXC\StanzaHandlers\IQ')->disableOriginalConstructor()->getMock();
@ -73,7 +72,6 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase {
'ojsxc',
$request,
$this->userId,
$session,
$this->stanzaMapper,
$this->iqHandler,
$this->messageHandler,
@ -87,6 +85,9 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase {
/**
* When invalid XML, just start long polling.
* Note: this test will cause some errors in the owncloud.log:
* {"reqId":"HmbEV6qTWF68ii1G\/kz1","remoteAddr":"","app":"PHP","message":"XMLReader::read(): An Error Occured while reading at \/var\/www\/owncloud\/apps\/ojsxc\/vendor\/sabre\/xml\/lib\/Reader.php#66","level":0,"time":"2016-01-30T14:52:44+00:00","method":"--","url":"--"}
* {"reqId":"HmbEV6qTWF68ii1G\/kz1","remoteAddr":"","app":"PHP","message":"XMLReader::read(): An Error Occured while reading at \/var\/www\/owncloud\/apps\/ojsxc\/vendor\/sabre\/xml\/lib\/Reader.php#145","level":0,"time":"2016-01-30T14:52:44+00:00","method":"--","url":"--"}
*/
public function testInvalidXML() {
$ex = new DoesNotExistException('');
@ -136,7 +137,7 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase {
* @dataProvider IQProvider
*/
public function testIQHandlerWhenNoDbResults($body, $result, $expected, $pollCount, $handlerCount) {
$ex = new DoesNotExistException();
$ex = new DoesNotExistException('');
$this->setUpController($body);
$this->mockLock();
$expResponse = new XMPPResponse();
@ -189,7 +190,7 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase {
public function testMessageNoDbHandler() {
$body = '<body rid=\'897878959\' xmlns=\'http://jabber.org/protocol/httpbind\' sid=\'7862\'><message to=\'derp@own.dev\' type=\'chat\' id=\'1452960296859-msg\' xmlns=\'jabber:client\'><body>abc</body><request xmlns=\'urn:xmpp:receipts\'/></message></body>';
$ex = new DoesNotExistException();
$ex = new DoesNotExistException('');
$this->setUpController($body);
$this->mockLock();
@ -217,7 +218,7 @@ class HttpBindControllerTest extends PHPUnit_Framework_TestCase {
<message to='derp@own.dev' type='chat' id='1452960296861-msg' xmlns='jabber:client'><body>abc3</body></message>
</body>
XML;
$ex = new DoesNotExistException();
$ex = new DoesNotExistException('');
$this->setUpController($body);
$this->mockLock();
@ -294,7 +295,12 @@ XML;
$this->assertEquals($expResponse->render(), $response->render());
}
/**
* @TODO implement tests
*/
public function testPresenceHandler() {
$this->markTestSkipped();
$this->markTestIncomplete();
$body = '<body rid=\'897878985\' xmlns=\'http://jabber.org/protocol/httpbind\' sid=\'7862\'><presence xmlns=\'jabber:client\'><c xmlns=\'http://jabber.org/protocol/caps\' hash=\'sha-1\' node=\'http://jsxc.org/\' ver=\'u2kAg/CbVmVZhsu+lZrkuLLdO+0=\'/><show>chat</show></presence></body>';
$this->setUpController($body);
$this->mockLock();
@ -303,11 +309,20 @@ XML;
}
public function testBodyHandler() {
$ex = new DoesNotExistException('');
$body = '<body rid=\'897878985\' xmlns=\'http://jabber.org/protocol/httpbind\' sid=\'7862\'/>';
$this->setUpController($body);
$this->mockLock();
$expResponse = new XMPPResponse();
$this->controller->index();
$this->stanzaMapper->expects($this->exactly(10))
->method('findByTo')
->with('john')
->will($this->throwException($ex));
$response = $this->controller->index();
$this->assertEquals($expResponse, $response);
$this->assertEquals($expResponse->render(), $response->render());
}
}