TravisCI tests, refactoring for ownCloud/Nextcloud compatibility
This includes tests for: - PHP 5.6/7.0/7.1/7.2 - MySQL/SQLite/Postgres - ownCloud/Nextcloud
This commit is contained in:
parent
cbdb390283
commit
c8a59ee026
|
|
@ -0,0 +1,3 @@
|
||||||
|
# due to the different Travis-CI PHP versions we MUST NOT lock to specific versions
|
||||||
|
composer.lock
|
||||||
|
vendor
|
||||||
112
.travis.yml
112
.travis.yml
|
|
@ -1,15 +1,22 @@
|
||||||
sudo: required
|
sudo: false
|
||||||
language: php
|
language: php
|
||||||
php:
|
php:
|
||||||
- 5.6
|
- 5.6
|
||||||
- 7.0
|
- 7.0
|
||||||
|
- 7.1
|
||||||
|
- 7.2
|
||||||
|
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- $HOME/.composer/cache/files
|
||||||
|
|
||||||
|
services:
|
||||||
|
- mysql
|
||||||
|
- postgresql
|
||||||
|
|
||||||
addons:
|
addons:
|
||||||
apt:
|
apt:
|
||||||
packages:
|
packages:
|
||||||
- mysql-server-5.6
|
|
||||||
- mysql-client-core-5.6
|
|
||||||
- mysql-client-5.6
|
|
||||||
- php5-pgsql
|
- php5-pgsql
|
||||||
- libxml2-utils
|
- libxml2-utils
|
||||||
|
|
||||||
|
|
@ -17,71 +24,62 @@ env:
|
||||||
global:
|
global:
|
||||||
- PHP_COVERAGE=FALSE
|
- PHP_COVERAGE=FALSE
|
||||||
matrix:
|
matrix:
|
||||||
- CORE_FORK_BRANCH=nc_master DB=sqlite
|
- CORE_TYPE=nextcloud CORE_BRANCH=master DB=sqlite
|
||||||
- CORE_FORK_BRANCH=nc_stable11 DB=sqlite
|
- CORE_TYPE=nextcloud CORE_BRANCH=stable12 DB=sqlite
|
||||||
- CORE_FORK_BRANCH=nc_stable12 DB=sqlite
|
- CORE_TYPE=nextcloud CORE_BRANCH=stable11 DB=sqlite
|
||||||
- CORE_FORK_BRANCH=oc_master DB=sqlite
|
|
||||||
- CORE_FORK_BRANCH=oc_stable10 DB=sqlite
|
- CORE_TYPE=nextcloud CORE_BRANCH=master DB=mysql
|
||||||
- CORE_FORK_BRANCH=nc_master DB=mysql
|
- CORE_TYPE=nextcloud CORE_BRANCH=stable12 DB=mysql
|
||||||
- CORE_FORK_BRANCH=nc_stable11 DB=mysql
|
- CORE_TYPE=nextcloud CORE_BRANCH=stable11 DB=mysql
|
||||||
- CORE_FORK_BRANCH=nc_stable12 DB=mysql
|
|
||||||
- CORE_FORK_BRANCH=oc_master DB=mysql
|
- CORE_TYPE=nextcloud CORE_BRANCH=master DB=pgsql
|
||||||
- CORE_FORK_BRANCH=oc_stable10 DB=mysql
|
- CORE_TYPE=nextcloud CORE_BRANCH=stable12 DB=pgsql
|
||||||
|
- CORE_TYPE=nextcloud CORE_BRANCH=stable11 DB=pgsql
|
||||||
|
|
||||||
|
- CORE_TYPE=owncloud CORE_BRANCH=master DB=sqlite
|
||||||
|
- CORE_TYPE=owncloud CORE_BRANCH=stable10 DB=sqlite
|
||||||
|
|
||||||
|
- CORE_TYPE=owncloud CORE_BRANCH=master DB=mysql
|
||||||
|
- CORE_TYPE=owncloud CORE_BRANCH=stable10 DB=mysql
|
||||||
|
|
||||||
|
- CORE_TYPE=owncloud CORE_BRANCH=master DB=pgsql
|
||||||
|
- CORE_TYPE=owncloud CORE_BRANCH=stable10 DB=pgsql
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
allow_failures:
|
|
||||||
- php: 7.0
|
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
|
exclude:
|
||||||
branches:
|
# Nextcloud 11/12 are not compatible with PHP 7.2
|
||||||
only:
|
- php: 7.2
|
||||||
- master
|
env: CORE_TYPE=nextcloud CORE_BRANCH=stable11 DB=mysql
|
||||||
|
- php: 7.2
|
||||||
|
env: CORE_TYPE=nextcloud CORE_BRANCH=stable12 DB=mysql
|
||||||
|
- php: 7.2
|
||||||
|
env: CORE_TYPE=nextcloud CORE_BRANCH=stable11 DB=sqlite
|
||||||
|
- php: 7.2
|
||||||
|
env: CORE_TYPE=nextcloud CORE_BRANCH=stable12 DB=sqlite
|
||||||
|
- php: 7.2
|
||||||
|
env: CORE_TYPE=nextcloud CORE_BRANCH=stable11 DB=pgsql
|
||||||
|
- php: 7.2
|
||||||
|
env: CORE_TYPE=nextcloud CORE_BRANCH=stable12 DB=pgsql
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- php --info
|
|
||||||
|
|
||||||
# Set up DB
|
|
||||||
- if [[ "$DB" == 'pgsql' ]]; then createuser -U travis -s oc_autotest; fi
|
|
||||||
- if [[ "$DB" == 'mysql' ]]; then mysql -u root -e 'create database oc_autotest;'; fi
|
|
||||||
- if [[ "$DB" == 'mysql' ]]; then mysql -u root -e "CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY '';"; fi
|
|
||||||
- if [[ "$DB" == 'mysql' ]]; then mysql -u root -e "GRANT ALL ON oc_autotest.* TO 'oc_autotest'@'localhost';"; fi
|
|
||||||
|
|
||||||
- cd ..
|
|
||||||
- if [[ $(echo $CORE_FORK_BRANCH | awk -F '_' '{print $1}') == 'oc' ]]; then git clone https://github.com/owncloud/core.git --recursive --depth 1 -b $(echo $CORE_FORK_BRANCH | awk -F '_' '{print $2}') core; fi
|
|
||||||
- if [[ $(echo $CORE_FORK_BRANCH | awk -F '_' '{print $1}') == 'nc' ]]; then git clone https://github.com/nextcloud/server.git --recursive --depth 1 -b $(echo $CORE_FORK_BRANCH | awk -F '_' '{print $2}') core; fi
|
|
||||||
- mv registration core/apps/
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
# Set up core
|
|
||||||
- php -f core/occ maintenance:install --database-name oc_autotest --database-user oc_autotest --admin-user admin --admin-pass admin --database $DB --database-pass=''
|
|
||||||
|
|
||||||
# Set up app
|
|
||||||
- php -f core/occ app:enable registration
|
|
||||||
# Enable app twice to check occ errors of registered commands
|
|
||||||
- php -f core/occ app:enable registration
|
|
||||||
- cd core/apps/registration
|
|
||||||
|
|
||||||
# XDebug is only needed if we report coverage -> speeds up other builds
|
# XDebug is only needed if we report coverage -> speeds up other builds
|
||||||
- if [[ "$PHP_COVERAGE" = "FALSE" ]]; then phpenv config-rm xdebug.ini; fi
|
- if [[ "$PHP_COVERAGE" = "FALSE" ]]; then phpenv config-rm xdebug.ini; fi
|
||||||
|
|
||||||
|
install:
|
||||||
|
- . ./tests/scripts/core-download.sh
|
||||||
|
- . ${BUILD_APP_MODULE_DIR}/tests/scripts/core-database.sh
|
||||||
|
- . ${BUILD_APP_MODULE_DIR}/tests/scripts/core-setup.sh
|
||||||
|
|
||||||
script:
|
script:
|
||||||
# Check info.xml schema validity
|
# Check info.xml schema validity
|
||||||
- wget https://apps.nextcloud.com/schema/apps/info.xsd
|
- . ${BUILD_APP_MODULE_DIR}/tests/scripts/lint-appinfo.sh
|
||||||
- xmllint appinfo/info.xml --schema info.xsd --noout
|
|
||||||
- rm info.xsd
|
|
||||||
|
|
||||||
# Check PHP syntax errors
|
# Check PHP syntax errors
|
||||||
#- find . -name \*.php -not -path './vendor/*' -exec php -l "{}" \;
|
- . ${BUILD_APP_MODULE_DIR}/tests/scripts/lint-php.sh
|
||||||
|
|
||||||
# Run server's app code checker
|
|
||||||
# TODO: enable once table renames are possible
|
|
||||||
# - php ../../occ app:check-code mail
|
|
||||||
|
|
||||||
|
# Run app code checker but do not fail, as we have to use private API for now
|
||||||
|
- . ${BUILD_APP_MODULE_DIR}/tests/scripts/app-check-code.sh || true
|
||||||
|
|
||||||
# Run PHP tests
|
# Run PHP tests
|
||||||
- cd tests
|
- . ${BUILD_APP_MODULE_DIR}/tests/scripts/phpunit.sh
|
||||||
- phpunit -c phpunit.xml
|
|
||||||
|
|
||||||
# Test packaging
|
|
||||||
#- cd ..
|
|
||||||
#- if [[ "$PACKAGE" = "TRUE" ]]; then make appstore; fi
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
[](https://travis-ci.org/buffcode/registration)
|
||||||
|
|
||||||
# Registration
|
# Registration
|
||||||
This app allows users to register a new account.
|
This app allows users to register a new account.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,13 @@
|
||||||
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
|
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
|
||||||
<id>registration</id>
|
<id>registration</id>
|
||||||
<name>Registration</name>
|
<name>Registration</name>
|
||||||
|
<summary>This app allows users to self-register a new account using their e-mail address.</summary>
|
||||||
<description>User registration</description>
|
<description>User registration</description>
|
||||||
|
<version>0.3.1</version>
|
||||||
<licence>agpl</licence>
|
<licence>agpl</licence>
|
||||||
<author mail="pellaeon@cnmc.tw" homepage="https://nyllep.wordpress.com/about-2">Pellaeon Lin</author>
|
<author mail="pellaeon@cnmc.tw" homepage="https://nyllep.wordpress.com/about-2">Pellaeon Lin</author>
|
||||||
<version>0.3.1</version>
|
<category>security</category>
|
||||||
|
<category>tools</category>
|
||||||
<website>https://github.com/pellaeon/registration</website>
|
<website>https://github.com/pellaeon/registration</website>
|
||||||
<bugs>https://github.com/pellaeon/registration/issues</bugs>
|
<bugs>https://github.com/pellaeon/registration/issues</bugs>
|
||||||
<repository>https://github.com/pellaeon/registration</repository>
|
<repository>https://github.com/pellaeon/registration</repository>
|
||||||
|
|
@ -18,7 +21,4 @@
|
||||||
<owncloud min-version="9.0" max-version="11"/>
|
<owncloud min-version="9.0" max-version="11"/>
|
||||||
<nextcloud min-version="9" max-version="13" />
|
<nextcloud min-version="9" max-version="13" />
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<category>auth</category>
|
|
||||||
<category>tools</category>
|
|
||||||
<ocsid>170608</ocsid>
|
|
||||||
</info>
|
</info>
|
||||||
|
|
|
||||||
|
|
@ -48,4 +48,4 @@ class Capabilities implements IPublicCapability {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^5.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -27,12 +27,10 @@ use OCA\Registration\Db\Registration;
|
||||||
use OCA\Registration\Service\MailService;
|
use OCA\Registration\Service\MailService;
|
||||||
use OCA\Registration\Service\RegistrationException;
|
use OCA\Registration\Service\RegistrationException;
|
||||||
use OCA\Registration\Service\RegistrationService;
|
use OCA\Registration\Service\RegistrationService;
|
||||||
|
use OCA\Registration\Util\CoreBridge;
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
use OCP\AppFramework\Db\DoesNotExistException;
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
use OCP\AppFramework\OCS\OCSBadRequestException;
|
|
||||||
use OCP\AppFramework\OCS\OCSNotFoundException;
|
|
||||||
use OCP\AppFramework\OCSController;
|
use OCP\AppFramework\OCSController;
|
||||||
use OCP\AppFramework\OCS\OCSException;
|
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCP\Defaults;
|
use OCP\Defaults;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
|
|
@ -73,7 +71,7 @@ class ApiController extends OCSController {
|
||||||
* @param string $username
|
* @param string $username
|
||||||
* @param string $displayname
|
* @param string $displayname
|
||||||
* @param string $email
|
* @param string $email
|
||||||
* @throws OCSException
|
* @throws \Exception
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function validate($username, $displayname, $email) {
|
public function validate($username, $displayname, $email) {
|
||||||
|
|
@ -82,7 +80,7 @@ class ApiController extends OCSController {
|
||||||
$this->registrationService->validateDisplayname($displayname);
|
$this->registrationService->validateDisplayname($displayname);
|
||||||
$this->registrationService->validateUsername($username);
|
$this->registrationService->validateUsername($username);
|
||||||
} catch (RegistrationException $e) {
|
} catch (RegistrationException $e) {
|
||||||
throw new OCSBadRequestException($e->getMessage());
|
throw CoreBridge::createException('OCSBadRequestException', $e->getMessage());
|
||||||
}
|
}
|
||||||
$data = [
|
$data = [
|
||||||
'username' => $username,
|
'username' => $username,
|
||||||
|
|
@ -97,7 +95,7 @@ class ApiController extends OCSController {
|
||||||
* @AnonRateThrottle(limit=10, period=1)
|
* @AnonRateThrottle(limit=10, period=1)
|
||||||
*
|
*
|
||||||
* @param string $clientSecret
|
* @param string $clientSecret
|
||||||
* @throws OCSException
|
* @throws \Exception
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function status($clientSecret) {
|
public function status($clientSecret) {
|
||||||
|
|
@ -105,7 +103,7 @@ class ApiController extends OCSController {
|
||||||
/** @var Registration $registration */
|
/** @var Registration $registration */
|
||||||
$registration = $this->registrationService->getRegistrationForSecret($clientSecret);
|
$registration = $this->registrationService->getRegistrationForSecret($clientSecret);
|
||||||
} catch (DoesNotExistException $e) {
|
} catch (DoesNotExistException $e) {
|
||||||
throw new OCSNotFoundException('No pending registration.');
|
throw CoreBridge::createException('OCSNotFoundException', 'No pending registration.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$registration->getEmailConfirmed()) {
|
if (!$registration->getEmailConfirmed()) {
|
||||||
|
|
@ -142,7 +140,7 @@ class ApiController extends OCSController {
|
||||||
* @param string $displayname
|
* @param string $displayname
|
||||||
* @param string $email
|
* @param string $email
|
||||||
* @param string $password
|
* @param string $password
|
||||||
* @throws OCSException
|
* @throws \Exception
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function register($username, $displayname, $email, $password) {
|
public function register($username, $displayname, $email, $password) {
|
||||||
|
|
@ -175,8 +173,7 @@ class ApiController extends OCSController {
|
||||||
}
|
}
|
||||||
return new DataResponse($data, Http::STATUS_OK);
|
return new DataResponse($data, Http::STATUS_OK);
|
||||||
} catch (RegistrationException $exception) {
|
} catch (RegistrationException $exception) {
|
||||||
throw new OCSException($exception->getMessage(), $exception->getCode());
|
throw CoreBridge::createException('OCSException', $exception->getMessage(), $exception->getCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,6 @@ use \OCP\IGroupManager;
|
||||||
use \OCP\IL10N;
|
use \OCP\IL10N;
|
||||||
use \OCP\IConfig;
|
use \OCP\IConfig;
|
||||||
use \OCP\Security\ISecureRandom;
|
use \OCP\Security\ISecureRandom;
|
||||||
use \OC_User;
|
|
||||||
use \OC_Util;
|
|
||||||
|
|
||||||
class RegistrationService {
|
class RegistrationService {
|
||||||
|
|
||||||
|
|
@ -298,7 +296,7 @@ class RegistrationService {
|
||||||
|
|
||||||
// disable user if this is requested by config
|
// disable user if this is requested by config
|
||||||
$admin_approval_required = $this->config->getAppValue($this->appName, 'admin_approval_required', "no");
|
$admin_approval_required = $this->config->getAppValue($this->appName, 'admin_approval_required', "no");
|
||||||
if ($admin_approval_required == "yes") {
|
if ($admin_approval_required === "yes") {
|
||||||
$user->setEnabled(false);
|
$user->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -406,13 +404,13 @@ class RegistrationService {
|
||||||
$this->usersession->login($username, $password);
|
$this->usersession->login($username, $password);
|
||||||
$this->usersession->createSessionToken($this->request, $userId, $username, $password);
|
$this->usersession->createSessionToken($this->request, $userId, $username, $password);
|
||||||
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index'));
|
return new RedirectResponse($this->urlGenerator->linkToRoute('files.view.index'));
|
||||||
} elseif (OC_User::login($username, $password)) {
|
} elseif (\OC_User::login($username, $password)) {
|
||||||
$this->cleanupLoginTokens($userId);
|
$this->cleanupLoginTokens($userId);
|
||||||
// FIXME unsetMagicInCookie will fail from session already closed, so now we always remember
|
// FIXME unsetMagicInCookie will fail from session already closed, so now we always remember
|
||||||
$logintoken = $this->random->generate(32);
|
$logintoken = $this->random->generate(32);
|
||||||
$this->config->setUserValue($userId, 'login_token', $logintoken, time());
|
$this->config->setUserValue($userId, 'login_token', $logintoken, time());
|
||||||
OC_User::setMagicInCookie($userId, $logintoken);
|
\OC_User::setMagicInCookie($userId, $logintoken);
|
||||||
OC_Util::redirectToDefaultPage();
|
\OC_Util::redirectToDefaultPage();
|
||||||
}
|
}
|
||||||
// Render message in case redirect failed
|
// Render message in case redirect failed
|
||||||
return new TemplateResponse('registration', 'message',
|
return new TemplateResponse('registration', 'message',
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ foreach ( $_['groups'] as $group ) {
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<label for="admin_approval_required"><?php p($l->t('Require admin approval?')); ?>
|
<label for="admin_approval_required"><?php p($l->t('Require admin approval?')); ?>
|
||||||
<input type="checkbox" id="admin_approval_required" name="admin_approval_required" <?php if($_['approval_required'] == "yes" ) echo " checked"; ?>>
|
<input type="checkbox" id="admin_approval_required" name="admin_approval_required" <?php if($_['approval_required'] === "yes" ) echo " checked"; ?>>
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
echo "travis_fold:start:app.check-code"
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
php -f ${BUILD_CORE_DIR}/occ app:check-code registration
|
||||||
|
|
||||||
|
echo "travis_fold:end:app.check-code"
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
echo "travis_fold:start:core.database.setup"
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# MySQL
|
||||||
|
if [[ "${DB}" == 'mysql' ]]
|
||||||
|
then
|
||||||
|
mysql -u root -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';"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Postgres
|
||||||
|
if [[ "${DB}" == 'pgsql' ]]
|
||||||
|
then
|
||||||
|
psql -U postgres -c 'CREATE DATABASE oc_autotest;'
|
||||||
|
psql -U postgres -c "CREATE USER oc_autotest WITH PASSWORD '';"
|
||||||
|
psql -U postgres -c 'GRANT ALL PRIVILEGES ON DATABASE oc_autotest TO oc_autotest;'
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "travis_fold:end:core.database.setup"
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
echo "travis_fold:start:core.download"
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# export some generic paths
|
||||||
|
export BUILD_ROOT_DIR=$(dirname `pwd`)
|
||||||
|
export BUILD_CORE_DIR="${BUILD_ROOT_DIR}/core"
|
||||||
|
export BUILD_APPS_DIR="${BUILD_CORE_DIR}/apps"
|
||||||
|
export BUILD_APP_MODULE_DIR="${BUILD_APPS_DIR}/registration"
|
||||||
|
|
||||||
|
if [[ ${CORE_TYPE} == 'owncloud' ]]; then git clone https://github.com/owncloud/core.git --recursive --depth 1 -b ${CORE_BRANCH} ${BUILD_CORE_DIR}; fi
|
||||||
|
if [[ ${CORE_TYPE} == 'nextcloud' ]]; then git clone https://github.com/nextcloud/server.git --recursive --depth 1 -b ${CORE_BRANCH} ${BUILD_CORE_DIR}; fi
|
||||||
|
|
||||||
|
mv ${BUILD_ROOT_DIR}/registration ${BUILD_APPS_DIR}
|
||||||
|
|
||||||
|
echo "travis_fold:end:core.download"
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
echo "travis_fold:start:core.setup"
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd ${BUILD_CORE_DIR}
|
||||||
|
|
||||||
|
if [[ ${CORE_TYPE} == 'owncloud' ]]; then composer install -o --prefer-dist --no-suggest --no-interaction; fi
|
||||||
|
|
||||||
|
# Set up core
|
||||||
|
php -f occ maintenance:install --database-name oc_autotest --database-user oc_autotest --admin-user admin --admin-pass admin --database ${DB} --database-pass=''
|
||||||
|
|
||||||
|
# Set up app
|
||||||
|
php -f occ app:enable registration
|
||||||
|
|
||||||
|
# Enable app twice to check occ errors of registered commands
|
||||||
|
php -f occ app:enable registration
|
||||||
|
|
||||||
|
echo "travis_fold:end:core.setup"
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
echo "travis_fold:start:lint.appinfo"
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd ${BUILD_APP_MODULE_DIR}
|
||||||
|
|
||||||
|
wget -nv https://apps.nextcloud.com/schema/apps/info.xsd
|
||||||
|
xmllint appinfo/info.xml --schema info.xsd --noout
|
||||||
|
rm info.xsd
|
||||||
|
|
||||||
|
echo "travis_fold:end:lint.appinfo"
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
echo "travis_fold:start:lint.php"
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd ${BUILD_APP_MODULE_DIR}
|
||||||
|
|
||||||
|
find . -name '*.php' -type f -not -path './vendor/*' -print0 | xargs --no-run-if-empty -0 -n1 -P8 php -l -d display_errors -d display_startup_errors 1>/dev/null
|
||||||
|
|
||||||
|
echo "travis_fold:end:lint.php"
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
echo "travis_fold:start:phpunit"
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd ${BUILD_APP_MODULE_DIR}
|
||||||
|
|
||||||
|
composer install --prefer-dist --no-interaction -o
|
||||||
|
vendor/bin/phpunit -c tests/phpunit.xml
|
||||||
|
|
||||||
|
echo "travis_fold:end:phpunit"
|
||||||
|
|
@ -14,11 +14,9 @@ namespace OCA\Registration\Controller;
|
||||||
use OCA\Registration\Db\Registration;
|
use OCA\Registration\Db\Registration;
|
||||||
use OCA\Registration\Service\MailService;
|
use OCA\Registration\Service\MailService;
|
||||||
use OCA\Registration\Service\RegistrationService;
|
use OCA\Registration\Service\RegistrationService;
|
||||||
use OCP\AppFramework\Db\DoesNotExistException;
|
use OCA\Registration\Util\CoreBridge;
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCP\AppFramework\OCS\OCSException;
|
|
||||||
use OCP\AppFramework\OCS\OCSNotFoundException;
|
|
||||||
use OCP\Defaults;
|
use OCP\Defaults;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
|
|
@ -80,58 +78,58 @@ class ApiControllerTest extends TestCase {
|
||||||
$this->assertEquals($expected, $actual);
|
$this->assertEquals($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \OCP\AppFramework\OCS\OCSException
|
|
||||||
* @expectedExceptionCode 999
|
|
||||||
*/
|
|
||||||
public function testValidateFailEmail() {
|
public function testValidateFailEmail() {
|
||||||
|
$exception = CoreBridge::createException('OCSException', '', 999);
|
||||||
|
|
||||||
|
$this->expectException(get_class($exception));
|
||||||
|
|
||||||
$this->registrationService
|
$this->registrationService
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('validateEmail')
|
->method('validateEmail')
|
||||||
->willThrowException(new OCSException('', 999));
|
->willThrowException($exception);
|
||||||
|
|
||||||
$this->controller->validate('user1', 'user test', 'test@example.com');
|
$this->controller->validate('user1', 'user test', 'test@example.com');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \OCP\AppFramework\OCS\OCSException
|
|
||||||
* @expectedExceptionCode 999
|
|
||||||
*/
|
|
||||||
public function testValidateFailDisplayname() {
|
public function testValidateFailDisplayname() {
|
||||||
$this->registrationService
|
$exception = CoreBridge::createException('OCSException', '', 999);
|
||||||
|
|
||||||
|
$this->expectException(get_class($exception));
|
||||||
|
|
||||||
|
$this->registrationService
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('validateDisplayname')
|
->method('validateDisplayname')
|
||||||
->willThrowException(new OCSException('', 999));
|
->willThrowException($exception);
|
||||||
|
|
||||||
$this->controller->validate('user1', 'user test', 'test@example.com');
|
$this->controller->validate('user1', 'user test', 'test@example.com');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \OCP\AppFramework\OCS\OCSException
|
|
||||||
* @expectedExceptionCode 999
|
|
||||||
*/
|
|
||||||
public function testValidateFailUsername() {
|
public function testValidateFailUsername() {
|
||||||
$this->registrationService
|
$exception = CoreBridge::createException('OCSException', '', 999);
|
||||||
|
|
||||||
|
$this->expectException(get_class($exception));
|
||||||
|
|
||||||
|
$this->registrationService
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('validateUsername')
|
->method('validateUsername')
|
||||||
->willThrowException(new OCSException('', 999));
|
->willThrowException($exception);
|
||||||
|
|
||||||
$this->controller->validate('user1', 'user test', 'test@example.com');
|
$this->controller->validate('user1', 'user test', 'test@example.com');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \OCP\AppFramework\OCS\OCSNotFoundException
|
|
||||||
* @expectedExceptionCode 404
|
|
||||||
*/
|
|
||||||
public function testStatusNoRegistration() {
|
public function testStatusNoRegistration() {
|
||||||
|
$exception = CoreBridge::createException('OCSNotFoundException', '', 404);
|
||||||
|
|
||||||
|
$this->expectException(get_class($exception));
|
||||||
|
|
||||||
$this->registrationService
|
$this->registrationService
|
||||||
->method('getRegistrationForSecret')
|
->method('getRegistrationForSecret')
|
||||||
->with('L2qdLAtrJTx499ErjwkwnZqGmLdm3Acp')
|
->with('L2qdLAtrJTx499ErjwkwnZqGmLdm3Acp')
|
||||||
->willThrowException(new DoesNotExistException(''));
|
->willThrowException($exception);
|
||||||
|
|
||||||
$this->controller->status('L2qdLAtrJTx499ErjwkwnZqGmLdm3Acp');
|
$this->controller->status('L2qdLAtrJTx499ErjwkwnZqGmLdm3Acp');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \OCP\AppFramework\OCS\OCSException
|
|
||||||
* @expectedExceptionCode 403
|
|
||||||
*/
|
|
||||||
public function testStatusPendingRegistration() {
|
public function testStatusPendingRegistration() {
|
||||||
$registration = new Registration();
|
$registration = new Registration();
|
||||||
$registration->setEmailConfirmed(false);
|
$registration->setEmailConfirmed(false);
|
||||||
|
|
@ -139,7 +137,18 @@ class ApiControllerTest extends TestCase {
|
||||||
->method('getRegistrationForSecret')
|
->method('getRegistrationForSecret')
|
||||||
->with('L2qdLAtrJTx499ErjwkwnZqGmLdm3Acp')
|
->with('L2qdLAtrJTx499ErjwkwnZqGmLdm3Acp')
|
||||||
->willReturn($registration);
|
->willReturn($registration);
|
||||||
|
|
||||||
$actual = $this->controller->status('L2qdLAtrJTx499ErjwkwnZqGmLdm3Acp');
|
$actual = $this->controller->status('L2qdLAtrJTx499ErjwkwnZqGmLdm3Acp');
|
||||||
|
|
||||||
|
$expected = new DataResponse(
|
||||||
|
[
|
||||||
|
'registrationStatus' => 1,
|
||||||
|
'message' => $this->l10n->t('Your registration is pending. Please confirm your email address.'),
|
||||||
|
],
|
||||||
|
Http::STATUS_OK
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testStatusConfirmedRegistration() {
|
public function testStatusConfirmedRegistration() {
|
||||||
|
|
@ -163,12 +172,11 @@ class ApiControllerTest extends TestCase {
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('generateAppPassword');
|
->method('generateAppPassword');
|
||||||
$actual = $this->controller->status('mysecret');
|
$actual = $this->controller->status('mysecret');
|
||||||
$expected = new DataResponse([]);
|
$expected = new DataResponse([
|
||||||
|
'appPassword' => null,
|
||||||
|
'cloudUrl' => $this->defaults->getBaseUrl(),
|
||||||
|
'registrationStatus' => 0,
|
||||||
|
]);
|
||||||
$this->assertEquals($expected, $actual);
|
$this->assertEquals($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testStatusConfirmedRegistrationWithSecret() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,77 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace OCA\Registration\Util;
|
||||||
|
|
||||||
|
class CoreBridge
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param string $className
|
||||||
|
* @return string
|
||||||
|
* @throws \LogicException
|
||||||
|
*/
|
||||||
|
public static function exceptionClass($className)
|
||||||
|
{
|
||||||
|
static $classes = [
|
||||||
|
'OCSException' => [
|
||||||
|
'nextcloud' => 'OCP\AppFramework\OCS\OCSException',
|
||||||
|
'owncloud' => 'OC\OCS\Exception',
|
||||||
|
],
|
||||||
|
'OCSBadRequestException' => [
|
||||||
|
'nextcloud' => 'OCP\AppFramework\OCS\OCSBadRequestException',
|
||||||
|
'owncloud' => 'OC\OCS\Exception',
|
||||||
|
],
|
||||||
|
'OCSNotFoundException' => [
|
||||||
|
'nextcloud' => 'OCP\AppFramework\OCS\OCSNotFoundException',
|
||||||
|
'owncloud' => 'OC\OCS\Exception',
|
||||||
|
],
|
||||||
|
'DoesNotExistException' => [
|
||||||
|
'nextcloud' => 'OCP\AppFramework\Db\DoesNotExistException',
|
||||||
|
'owncloud' => 'OCP\AppFramework\Db\DoesNotExistException',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!array_key_exists($className, $classes)) {
|
||||||
|
throw new \LogicException('No valid exception class found');
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($classes[$className] as $class) {
|
||||||
|
if (class_exists($class)) {
|
||||||
|
return $class;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \LogicException('No valid exception class found');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $className
|
||||||
|
* @param null|string $message
|
||||||
|
* @param null|int $code
|
||||||
|
* @return \Exception
|
||||||
|
*/
|
||||||
|
public static function createException($className, $message = null, $code = null)
|
||||||
|
{
|
||||||
|
$exceptionClassName = self::exceptionClass($className);
|
||||||
|
|
||||||
|
$reflection = new \ReflectionClass($exceptionClassName);
|
||||||
|
$params = $reflection->getConstructor()->getParameters();
|
||||||
|
|
||||||
|
if ($params[0]->getClass() && $params[0]->getClass()->getName() === 'OC\OCS\Result') {
|
||||||
|
return new $exceptionClassName(new \OC\OCS\Result($message, $code));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($params) >= 2) {
|
||||||
|
if ($params[1]->getClass() && $params[1]->getClass()->getName() === 'Exception') {
|
||||||
|
return new $exceptionClassName($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new $exceptionClassName($message, $code);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($exceptionClassName === 'OCP\AppFramework\OCS\OCSNotFoundException') {
|
||||||
|
return new $exceptionClassName($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new $exceptionClassName();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue