Add SMB tests and execute files_external tests

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
pull/2789/head
Lukas Reschke 8 years ago
parent d7b3402643
commit 1c80307537
No known key found for this signature in database
GPG Key ID: B9F6980CF6E759B1

@ -104,6 +104,22 @@ pipeline:
when:
matrix:
TESTS: carddavtester
sqlite-php7.0-samba-native:
image: nextcloudci/samba-native-php7.0:samba-native-php7.0-1
commands:
- smbd -D -FS &
- NOCOVERAGE=true ./autotest-external.sh sqlite smb-linux
when:
matrix:
TESTS: sqlite-php7.0-samba-native
sqlite-php7.0-samba-non-native:
image: nextcloudci/samba-non-native-php7.0:samba-non-native-php7.0-2
commands:
- smbd -D -FS &
- NOCOVERAGE=true ./autotest-external.sh sqlite smb-linux
when:
matrix:
TESTS: sqlite-php7.0-samba-non-native
nodb-php5.6:
image: nextcloudci/php5.6:php5.6-7
commands:
@ -381,7 +397,7 @@ matrix:
- TESTS: signed-off-check
- TESTS: htaccess-checker
- TESTS: nodb-codecov
- TESTS: db-codecov
- TESTS: db-codecov
- TESTS: integration-capabilities_features
- TESTS: integration-federation_features
- TESTS: integration-auth
@ -412,6 +428,8 @@ matrix:
- TESTS: litmus-v2
- TESTS: caldavtester
- TESTS: carddavtester
- TESTS: sqlite-php7.0-samba-native
- TESTS: sqlite-php7.0-samba-non-native
- DB: NODB
PHP: 5.6
- DB: NODB

@ -1,146 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Joas Schilling <coding@schilljs.com>
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin McCorkell <robin@mccorkell.me.uk>
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\Files_External\Tests;
use OCA\Files_External\Lib\Storage\AmazonS3;
/**
* Class AmazonS3Migration
*
* @group DB
*
* @package OCA\Files_External\Tests
*/
class AmazonS3MigrationTest extends \Test\TestCase {
/**
* @var \OC\Files\Storage\Storage instance
*/
protected $instance;
/** @var array */
protected $params;
/** @var string */
protected $oldId;
/** @var string */
protected $newId;
protected function setUp() {
parent::setUp();
$uuid = $this->getUniqueID();
$this->params['key'] = 'key'.$uuid;
$this->params['secret'] = 'secret'.$uuid;
$this->params['bucket'] = 'bucket'.$uuid;
$this->oldId = 'amazon::' . $this->params['key'] . md5($this->params['secret']);
$this->newId = 'amazon::' . $this->params['bucket'];
}
protected function tearDown() {
$this->deleteStorage($this->oldId);
$this->deleteStorage($this->newId);
parent::tearDown();
}
public function testUpdateLegacyOnlyId () {
// add storage ids
$oldCache = new \OC\Files\Cache\Cache($this->oldId);
// add file to old cache
$fileId = $oldCache->put('foobar', array('size' => 0, 'mtime' => time(), 'mimetype' => 'httpd/directory'));
try {
$this->instance = new AmazonS3($this->params);
} catch (\Exception $e) {
//ignore
}
$storages = $this->getStorages();
$this->assertTrue(isset($storages[$this->newId]));
$this->assertFalse(isset($storages[$this->oldId]));
$this->assertSame((int)$oldCache->getNumericStorageId(), (int)$storages[$this->newId]);
list($storageId, $path) = \OC\Files\Cache\Cache::getById($fileId);
$this->assertSame($this->newId, $storageId);
$this->assertSame('foobar', $path);
}
public function testUpdateLegacyAndNewId () {
// add storage ids
$oldCache = new \OC\Files\Cache\Cache($this->oldId);
new \OC\Files\Cache\Cache($this->newId);
// add file to old cache
$fileId = $oldCache->put('/', array('size' => 0, 'mtime' => time(), 'mimetype' => 'httpd/directory'));
try {
$this->instance = new AmazonS3($this->params);
} catch (\Exception $e) {
//ignore
}
$storages = $this->getStorages();
$this->assertTrue(isset($storages[$this->newId]));
$this->assertFalse(isset($storages[$this->oldId]));
$this->assertNull(\OC\Files\Cache\Cache::getById($fileId), 'old filecache has not been cleared');
}
/**
* @param $storages
* @return array
*/
public function getStorages() {
$storages = array();
$stmt = \OC::$server->getDatabaseConnection()->prepare(
'SELECT `numeric_id`, `id` FROM `*PREFIX*storages` WHERE `id` IN (?, ?)'
);
$stmt->execute(array($this->oldId, $this->newId));
while ($row = $stmt->fetch()) {
$storages[$row['id']] = $row['numeric_id'];
}
return $storages;
}
/**
* @param string $id
*/
public function deleteStorage($id) {
$stmt = \OC::$server->getDatabaseConnection()->prepare(
'DELETE FROM `*PREFIX*storages` WHERE `id` = ?'
);
$stmt->execute(array($id));
}
}

@ -29,6 +29,9 @@ use OCA\Files_External\Lib\Auth\Password\Password;
use OCA\Files_External\Lib\Auth\Password\SessionCredentials;
use OCA\Files_External\Lib\Backend\Local;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Service\GlobalStoragesService;
use OCA\Files_External\Service\UserStoragesService;
use OCP\IL10N;
use OCP\ISession;
use OCP\IUserManager;
use OCP\IUserSession;
@ -41,9 +44,9 @@ class ListCommandTest extends CommandTest {
*/
private function getInstance() {
/** @var \OCA\Files_External\Service\GlobalStoragesService|\PHPUnit_Framework_MockObject_MockObject $globalService */
$globalService = $this->getMock('\OCA\Files_External\Service\GlobalStoragesService', null, [], '', false);
$globalService = $this->createMock(GlobalStoragesService::class);
/** @var \OCA\Files_External\Service\UserStoragesService|\PHPUnit_Framework_MockObject_MockObject $userService */
$userService = $this->getMock('\OCA\Files_External\Service\UserStoragesService', null, [], '', false);
$userService = $this->createMock(UserStoragesService::class);
/** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject $userManager */
$userManager = $this->createMock(IUserManager::class);
/** @var \OCP\IUserSession|\PHPUnit_Framework_MockObject_MockObject $userSession */
@ -53,7 +56,7 @@ class ListCommandTest extends CommandTest {
}
public function testListAuthIdentifier() {
$l10n = $this->getMock('\OPC\IL10N', null, [], '', false);
$l10n = $this->createMock(IL10N::class);
$session = $this->createMock(ISession::class);
$crypto = $this->createMock(ICrypto::class);
$instance = $this->getInstance();

@ -34,21 +34,21 @@ use Test\TestCase;
class AdminTest extends TestCase {
/** @var Admin */
private $admin;
/** @var IManager */
/** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
private $encryptionManager;
/** @var GlobalStoragesService */
/** @var GlobalStoragesService|\PHPUnit_Framework_MockObject_MockObject */
private $globalStoragesService;
/** @var BackendService */
/** @var BackendService|\PHPUnit_Framework_MockObject_MockObject */
private $backendService;
/** @var GlobalAuth */
/** @var GlobalAuth|\PHPUnit_Framework_MockObject_MockObject */
private $globalAuth;
public function setUp() {
parent::setUp();
$this->encryptionManager = $this->getMockBuilder('\OCP\Encryption\IManager')->getMock();
$this->globalStoragesService = $this->getMockBuilder('\OCA\Files_External\Service\GlobalStoragesService')->disableOriginalConstructor()->getMock();
$this->backendService = $this->getMockBuilder('\OCA\Files_External\Service\BackendService')->disableOriginalConstructor()->getMock();
$this->globalAuth = $this->getMockBuilder('\OCA\Files_External\Lib\Auth\Password\GlobalAuth')->disableOriginalConstructor()->getMock();
$this->encryptionManager = $this->createMock(IManager::class);
$this->globalStoragesService = $this->createMock(GlobalStoragesService::class);
$this->backendService = $this->createMock(BackendService::class);
$this->globalAuth = $this->createMock(GlobalAuth::class);
$this->admin = new Admin(
$this->encryptionManager,
@ -79,6 +79,10 @@ class AdminTest extends TestCase {
->expects($this->once())
->method('isUserMountingAllowed')
->willReturn(true);
$this->backendService
->expects($this->exactly(2))
->method('getBackends')
->willReturn([]);
$this->globalAuth
->expects($this->once())
->method('getAuth')

@ -0,0 +1,42 @@
#!/usr/bin/env bash
#
# ownCloud
#
# This script start a docker container to test the files_external tests
# against. It will also change the files_external config to use the docker
# container as testing environment. This is reverted in the stop step.W
#
# Set environment variable DEBUG to print config file
#
# @author Morris Jobke
# @copyright 2015 Morris Jobke <hey@morrisjobke.de>
#
# retrieve current folder to place the config in the parent folder
thisFolder=`echo $0 | sed 's#env/start-smb-linux\.sh##'`
if [ -z "$thisFolder" ]; then
thisFolder="."
fi;
cat > $thisFolder/config.smb.php <<DELIM
<?php
return array(
'run'=>true,
'host'=>'127.0.0.1',
'user'=>'test',
'password'=>'test',
'root'=>'',
'share'=>'public',
);
DELIM
echo -n "Waiting for samba initialization"
if ! "$thisFolder"/env/wait-for-connection 127.0.0.1 445 60; then
echo "[ERROR] Waited 60 seconds, no response" >&2
exit 1
fi
sleep 1

@ -1,67 +0,0 @@
#!/usr/bin/env bash
#
# ownCloud
#
# This script start a docker container to test the files_external tests
# against. It will also change the files_external config to use the docker
# container as testing environment. This is reverted in the stop step.W
#
# Set environment variable DEBUG to print config file
#
# @author Morris Jobke
# @copyright 2015 Morris Jobke <hey@morrisjobke.de>
#
if ! command -v docker >/dev/null 2>&1; then
echo "No docker executable found - skipped docker setup"
exit 0;
fi
echo "Docker executable found - setup docker"
echo "Fetch recent silvershell/samba docker image"
docker pull silvershell/samba
# retrieve current folder to place the config in the parent folder
thisFolder=`echo $0 | sed 's#env/start-smb-silvershell\.sh##'`
if [ -z "$thisFolder" ]; then
thisFolder="."
fi;
container=`docker run -d -e SMB_USER=test -e SMB_PWD=test silvershell/samba`
host=`docker inspect --format="{{.NetworkSettings.IPAddress}}" $container`
cat > $thisFolder/config.smb.php <<DELIM
<?php
return array(
'run'=>true,
'host'=>'$host',
'user'=>'test',
'password'=>'test',
'root'=>'',
'share'=>'public',
);
DELIM
echo "samba container: $container"
# put container IDs into a file to drop them after the test run (keep in mind that multiple tests run in parallel on the same host)
echo $container >> $thisFolder/dockerContainerSilvershell.$EXECUTOR_NUMBER.smb
echo -n "Waiting for samba initialization"
if ! "$thisFolder"/env/wait-for-connection ${host} 445 60; then
echo "[ERROR] Waited 60 seconds, no response" >&2
exit 1
fi
sleep 1
if [ -n "$DEBUG" ]; then
cat $thisFolder/config.smb.php
cat $thisFolder/dockerContainerSilvershell.$EXECUTOR_NUMBER.smb
fi

@ -0,0 +1,21 @@
#!/usr/bin/env bash
#
# ownCloud
#
# This script stops the docker container the files_external tests were run
# against. It will also revert the config changes done in start step.
#
# @author Morris Jobke
# @copyright 2015 Morris Jobke <hey@morrisjobke.de>
#
# retrieve current folder to remove the config from the parent folder
thisFolder=`echo $0 | sed 's#env/stop-smb-linux\.sh##'`
if [ -z "$thisFolder" ]; then
thisFolder="."
fi;
# cleanup
rm $thisFolder/config.smb.php

@ -1,37 +0,0 @@
#!/usr/bin/env bash
#
# ownCloud
#
# This script stops the docker container the files_external tests were run
# against. It will also revert the config changes done in start step.
#
# @author Morris Jobke
# @copyright 2015 Morris Jobke <hey@morrisjobke.de>
#
if ! command -v docker >/dev/null 2>&1; then
echo "No docker executable found - skipped docker stop"
exit 0;
fi
echo "Docker executable found - stop and remove docker containers"
# retrieve current folder to remove the config from the parent folder
thisFolder=`echo $0 | sed 's#env/stop-smb-silvershell\.sh##'`
if [ -z "$thisFolder" ]; then
thisFolder="."
fi;
# stopping and removing docker containers
for container in `cat $thisFolder/dockerContainerSilvershell.$EXECUTOR_NUMBER.smb`; do
echo "Stopping and removing docker container $container"
# kills running container and removes it
docker stop $container
docker rm -f $container
done;
# cleanup
rm $thisFolder/config.smb.php
rm $thisFolder/dockerContainerSilvershell.$EXECUTOR_NUMBER.smb

@ -167,11 +167,14 @@ EOF
fi
if [ -z "$NOCOVERAGE" ]; then
"$PHPUNIT" --configuration phpunit-autotest-external.xml --log-junit "autotest-external-results-$1.xml" --coverage-clover "autotest-external-clover-$1.xml" --coverage-html "coverage-external-html-$1"
RESULT=$?
else
echo "No coverage"
"$PHPUNIT" --configuration phpunit-autotest-external.xml --log-junit "autotest-external-results-$1.xml"
RESULT=$?
fi
if [[ $? -ne 0 ]]; then
echo "Error during phpunit execution ... terminating"
exit 1
fi
if [ -n "$2" -a "$2" == "common-tests" ]; then

Loading…
Cancel
Save