Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2017-01-09 17:20:36 +01:00
Родитель 7a6f264a02
Коммит 290994a0cb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: CC42AC2A7F0E56D8
6 изменённых файлов: 73 добавлений и 151 удалений

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

@ -1,78 +0,0 @@
sudo: required
dist: trusty
language: php
php:
- 5.6
- 7
- 7.1
addons:
apt:
packages:
- mysql-server-5.6
- mysql-client-core-5.6
- mysql-client-5.6
services:
- postgresql
env:
global:
- CORE_BRANCH=master
- PHP_COVERAGE=FALSE
matrix:
- DB=sqlite
branches:
only:
- master
- "/^stable\\d+(\\.\\d+)?$/"
- /^v\d++(\.\d+)?+(\.\d+)?+(\.\d+)?$/
cache:
directories:
- "$HOME/.composer/cache/files"
- "$HOME/.npm"
- "$HOME/.cache/bower"
before_install:
<<<<<<< HEAD
- php --info
=======
- - php --info
>>>>>>> fix travis
# XDebug is only needed if we report coverage -> speeds up other builds
- if [[ "$PHP_COVERAGE" = "FALSE" ]]; then phpenv config-rm xdebug.ini; fi
# Set up DB
- if [[ "$DB" == 'pgsql' ]]; then createuser -U travis -s nc_autotest; fi
- if [[ "$DB" == 'mysql' ]]; then mysql -u root -e 'create database nc_autotest;'; fi
- if [[ "$DB" == 'mysql' ]]; then mysql -u root -e "CREATE USER 'nc_autotest'@'localhost' IDENTIFIED BY '';"; fi
- if [[ "$DB" == 'mysql' ]]; then mysql -u root -e "GRANT ALL ON nc_autotest.* TO 'nc_autotest'@'localhost';"; fi
- composer self-update
- composer install
- cd ..
- git clone https://github.com/nextcloud/server.git --recursive --depth 1 -b $CORE_BRANCH core
- mv twofactor_totp core/apps/
before_script:
# Set up core
- php -f core/occ maintenance:install --database-name nc_autotest --database-user nc_autotest --admin-user admin --admin-pass admin --database $DB --database-pass=''
# Set up app
- php -f core/occ app:enable twofactor_totp
- cd core/apps/twofactor_totp
script:
- find . -name \*.php -not -path './vendor/*' -exec php -l "{}" \;
- cd tests
- phpunit --configuration phpunit.xml
- if [[ "$PHP_COVERAGE" = "TRUE" ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [[ "$PHP_COVERAGE" = "TRUE" ]]; then php ocular.phar code-coverage:upload --format=php-clover clover.xml; fi
matrix:
include:
- php: 7
env: "DB=sqlite CORE_BRANCH=stable11"
- php: 7
env: "DB=pgsql PHP_COVERAGE=TRUE"
- php: 7
env: "DB=mysql"
fast_finish: true

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

@ -18,7 +18,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
use OCA\TwoFactorTOTP\AppInfo\Application;
include_once __DIR__ . '/../vendor/autoload.php';

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

@ -21,15 +21,17 @@
namespace OCA\TwoFactorTOTP\AppInfo;
use OCA\TwoFactorTOTP\Service\ITotp;
use OCA\TwoFactorTOTP\Service\Totp;
use OCP\AppFramework\App;
class Application extends App {
public function __construct($urlParams = []) {
parent::__construct('twofactor_totp', $urlParams);
public function __construct($urlParams = []) {
parent::__construct('twofactor_totp', $urlParams);
$container = $this->getContainer();
$container->registerAlias('\OCA\TwoFactorTOTP\Service\ITotp', '\OCA\TwoFactorTOTP\Service\Totp');
}
$container = $this->getContainer();
$container->registerAlias(ITotp::class, Totp::class);
}
}

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

@ -27,7 +27,6 @@ use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\Defaults;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
class SettingsController extends Controller {

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

@ -29,77 +29,77 @@ use OCP\Template;
class TotpProvider implements IProvider {
/** @var ITotp */
private $totp;
/** @var ITotp */
private $totp;
/** @var IL10N */
private $l10n;
/** @var IL10N */
private $l10n;
/**
* @param Totp $totp
* @param IL10N $l10n
*/
public function __construct(ITotp $totp, IL10N $l10n) {
$this->totp = $totp;
$this->l10n = $l10n;
}
/**
* @param ITotp $totp
* @param IL10N $l10n
*/
public function __construct(ITotp $totp, IL10N $l10n) {
$this->totp = $totp;
$this->l10n = $l10n;
}
/**
* Get unique identifier of this 2FA provider
*
* @return string
*/
public function getId() {
return 'totp';
}
/**
* Get unique identifier of this 2FA provider
*
* @return string
*/
public function getId() {
return 'totp';
}
/**
* Get the display name for selecting the 2FA provider
*
* @return string
*/
public function getDisplayName() {
return 'TOTP (Google Authenticator)';
}
/**
* Get the display name for selecting the 2FA provider
*
* @return string
*/
public function getDisplayName() {
return 'TOTP (Google Authenticator)';
}
/**
* Get the description for selecting the 2FA provider
*
* @return string
*/
public function getDescription() {
return $this->l10n->t('Authenticate with a TOTP app');
}
/**
* Get the description for selecting the 2FA provider
*
* @return string
*/
public function getDescription() {
return $this->l10n->t('Authenticate with a TOTP app');
}
/**
* Get the template for rending the 2FA provider view
*
* @param IUser $user
* @return Template
*/
public function getTemplate(IUser $user) {
$tmpl = new Template('twofactor_totp', 'challenge');
return $tmpl;
}
/**
* Get the template for rending the 2FA provider view
*
* @param IUser $user
* @return Template
*/
public function getTemplate(IUser $user) {
$tmpl = new Template('twofactor_totp', 'challenge');
return $tmpl;
}
/**
* Verify the given challenge
*
* @param IUser $user
* @param string $challenge
*/
public function verifyChallenge(IUser $user, $challenge) {
return $this->totp->validateSecret($user, $challenge);
}
/**
* Verify the given challenge
*
* @param IUser $user
* @param string $challenge
*/
public function verifyChallenge(IUser $user, $challenge) {
return $this->totp->validateSecret($user, $challenge);
}
/**
* Decides whether 2FA is enabled for the given user
*
* @param IUser $user
* @return boolean
*/
public function isTwoFactorAuthEnabledForUser(IUser $user) {
return $this->totp->hasSecret($user);
}
/**
* Decides whether 2FA is enabled for the given user
*
* @param IUser $user
* @return boolean
*/
public function isTwoFactorAuthEnabledForUser(IUser $user) {
return $this->totp->hasSecret($user);
}
}

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

@ -24,7 +24,7 @@ namespace OCA\TwoFactorTOTP\Unit\Controller;
use Endroid\QrCode\QrCode;
use OCA\TwoFactorTOTP\Controller\SettingsController;
use OCA\TwoFactorTOTP\Service\ITotp;
use OCA\TwoFactorTOTP\Service\Totp;
use OCP\Defaults;
use OCP\IRequest;
use OCP\IUser;
@ -46,7 +46,7 @@ class SettingsControllerTest extends TestCase {
$this->request = $this->createMock(IRequest::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->totp = $this->createMock(ITotp::class);
$this->totp = $this->createMock(Totp::class);
$this->defaults = new Defaults();
$this->controller = new SettingsController('twofactor_totp', $this->request, $this->userSession, $this->totp, $this->defaults);