Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ
2022-04-15 08:15:32 +02:00
parent 98768cfb57
commit 751dc7ea2a
15 changed files with 185 additions and 194 deletions

View File

@@ -8,11 +8,8 @@ use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Notification\IManager;
use OCP\User\Events;
class Application extends App implements IBootstrap { class Application extends App implements IBootstrap {
public function __construct() { public function __construct() {
parent::__construct('user_external'); parent::__construct('user_external');
} }
@@ -22,5 +19,4 @@ class Application extends App implements IBootstrap {
public function boot(IBootContext $context): void { public function boot(IBootContext $context): void {
} }
} }

View File

@@ -80,7 +80,6 @@ abstract class Base extends \OC\User\Backend{
* @return array with all displayNames (value) and the corresponding uids (key) * @return array with all displayNames (value) and the corresponding uids (key)
*/ */
public function getDisplayNames($search = '', $limit = null, $offset = null) { public function getDisplayNames($search = '', $limit = null, $offset = null) {
$connection = \OC::$server->getDatabaseConnection(); $connection = \OC::$server->getDatabaseConnection();
$query = $connection->getQueryBuilder(); $query = $connection->getQueryBuilder();
$query->select('uid', 'displayname') $query->select('uid', 'displayname')
@@ -231,5 +230,4 @@ abstract class Base extends \OC\User\Backend{
return $users > 0; return $users > 0;
} }
} }

View File

@@ -9,7 +9,6 @@
namespace OCA\UserExternal; namespace OCA\UserExternal;
class BasicAuth extends Base { class BasicAuth extends Base {
private $authUrl; private $authUrl;
public function __construct($authUrl) { public function __construct($authUrl) {

View File

@@ -9,7 +9,6 @@
*/ */
namespace OCA\UserExternal; namespace OCA\UserExternal;
/** /**
* User authentication against an IMAP mail server * User authentication against an IMAP mail server
* *

View File

@@ -19,8 +19,8 @@ namespace OCA\UserExternal;
class SMB extends Base { class SMB extends Base {
private $host; private $host;
const SMBCLIENT = 'smbclient -L'; public const SMBCLIENT = 'smbclient -L';
const LOGINERROR = 'NT_STATUS_LOGON_FAILURE'; public const LOGINERROR = 'NT_STATUS_LOGON_FAILURE';
/** /**
* Create new samba authentication provider * Create new samba authentication provider

View File

@@ -9,7 +9,6 @@
namespace OCA\UserExternal; namespace OCA\UserExternal;
class WebDavAuth extends Base { class WebDavAuth extends Base {
private $webDavAuthUrl; private $webDavAuthUrl;
public function __construct($webDavAuthUrl) { public function __construct($webDavAuthUrl) {
@@ -27,7 +26,7 @@ class WebDavAuth extends Base {
*/ */
public function checkPassword($uid, $password) { public function checkPassword($uid, $password) {
$arr = explode('://', $this->webDavAuthUrl, 2); $arr = explode('://', $this->webDavAuthUrl, 2);
if( ! isset($arr) OR count($arr) !== 2) { if (! isset($arr) or count($arr) !== 2) {
\OC::$server->getLogger()->error('ERROR: Invalid WebdavUrl: "'.$this->webDavAuthUrl.'" ', ['app' => 'user_external']); \OC::$server->getLogger()->error('ERROR: Invalid WebdavUrl: "'.$this->webDavAuthUrl.'" ', ['app' => 'user_external']);
return false; return false;
} }
@@ -37,7 +36,6 @@ class WebDavAuth extends Base {
if ($headers === false) { if ($headers === false) {
\OC::$server->getLogger()->error('ERROR: Not possible to connect to WebDAV Url: "'.$protocol.'://'.$path.'" ', ['app' => 'user_external']); \OC::$server->getLogger()->error('ERROR: Not possible to connect to WebDAV Url: "'.$protocol.'://'.$path.'" ', ['app' => 'user_external']);
return false; return false;
} }
$returnCode = substr($headers[0], 9, 3); $returnCode = substr($headers[0], 9, 3);

View File

@@ -16,7 +16,7 @@ class Test_User_BasicAuth extends \Test\TestCase {
return include(__DIR__.'/config.php'); return include(__DIR__.'/config.php');
} }
function skip() { public function skip() {
$config = $this->getConfig(); $config = $this->getConfig();
$this->skipUnless($config['basic_auth']['run']); $this->skipUnless($config['basic_auth']['run']);
} }
@@ -27,7 +27,7 @@ class Test_User_BasicAuth extends \Test\TestCase {
$this->instance = new OC_User_BasicAuth($config['basic_auth']['url']); $this->instance = new OC_User_BasicAuth($config['basic_auth']['url']);
} }
function testLogin() { public function testLogin() {
$config = $this->getConfig(); $config = $this->getConfig();
$this->assertEquals($config['basic_auth']['user'], $this->instance->checkPassword($config['basic_auth']['user'], $config['basic_auth']['password'])); $this->assertEquals($config['basic_auth']['user'], $this->instance->checkPassword($config['basic_auth']['user'], $config['basic_auth']['password']));
$this->assertFalse($this->instance->checkPassword($config['basic_auth']['user'], $config['basic_auth']['password'].'foo')); $this->assertFalse($this->instance->checkPassword($config['basic_auth']['user'], $config['basic_auth']['password'].'foo'));

View File

@@ -1,4 +1,5 @@
<?php <?php
if (!defined('PHPUNIT_RUN')) { if (!defined('PHPUNIT_RUN')) {
define('PHPUNIT_RUN', 1); define('PHPUNIT_RUN', 1);
} }

View File

@@ -16,7 +16,7 @@ class Test_User_FTP extends \Test\TestCase {
return include(__DIR__.'/config.php'); return include(__DIR__.'/config.php');
} }
function skip() { public function skip() {
$config = $this->getConfig(); $config = $this->getConfig();
$this->skipUnless($config['ftp']['run']); $this->skipUnless($config['ftp']['run']);
} }
@@ -27,7 +27,7 @@ class Test_User_FTP extends \Test\TestCase {
$this->instance = new OC_User_FTP($config['ftp']['host']); $this->instance = new OC_User_FTP($config['ftp']['host']);
} }
function testLogin() { public function testLogin() {
$config = $this->getConfig(); $config = $this->getConfig();
$this->assertEquals($config['ftp']['user'], $this->instance->checkPassword($config['ftp']['user'], $config['ftp']['password'])); $this->assertEquals($config['ftp']['user'], $this->instance->checkPassword($config['ftp']['user'], $config['ftp']['password']));
$this->assertFalse($this->instance->checkPassword($config['ftp']['user'], $config['ftp']['password'].'foo')); $this->assertFalse($this->instance->checkPassword($config['ftp']['user'], $config['ftp']['password'].'foo'));

View File

@@ -16,7 +16,7 @@ class Test_User_Imap extends \Test\TestCase {
return include(__DIR__.'/config.php'); return include(__DIR__.'/config.php');
} }
function skip() { public function skip() {
$config = $this->getConfig(); $config = $this->getConfig();
$this->skipUnless($config['imap']['run']); $this->skipUnless($config['imap']['run']);
} }
@@ -28,7 +28,7 @@ class Test_User_Imap extends \Test\TestCase {
$this->instance = new OC_User_IMAP($config['imap']['mailbox']); $this->instance = new OC_User_IMAP($config['imap']['mailbox']);
} }
function testLogin() { public function testLogin() {
$config = $this->getConfig(); $config = $this->getConfig();
$this->assertEquals($config['imap']['user'], $this->instance->checkPassword($config['imap']['user'], $config['imap']['password'])); $this->assertEquals($config['imap']['user'], $this->instance->checkPassword($config['imap']['user'], $config['imap']['password']));
$this->assertFalse($this->instance->checkPassword($config['imap']['user'], $config['imap']['password'].'foo')); $this->assertFalse($this->instance->checkPassword($config['imap']['user'], $config['imap']['password'].'foo'));

View File

@@ -16,7 +16,7 @@ class Test_User_SMB extends \Test\TestCase {
return include(__DIR__.'/config.php'); return include(__DIR__.'/config.php');
} }
function skip() { public function skip() {
$config = $this->getConfig(); $config = $this->getConfig();
$this->skipUnless($config['smb']['run']); $this->skipUnless($config['smb']['run']);
} }
@@ -28,7 +28,7 @@ class Test_User_SMB extends \Test\TestCase {
$this->instance = new OC_User_SMB($config['smb']['host']); $this->instance = new OC_User_SMB($config['smb']['host']);
} }
function testLogin() { public function testLogin() {
$config = $this->getConfig(); $config = $this->getConfig();
$this->assertEquals($config['smb']['user'], $this->instance->checkPassword($config['smb']['user'], $config['smb']['password'])); $this->assertEquals($config['smb']['user'], $this->instance->checkPassword($config['smb']['user'], $config['smb']['password']));
$this->assertFalse($this->instance->checkPassword($config['smb']['user'], $config['smb']['password'].'foo')); $this->assertFalse($this->instance->checkPassword($config['smb']['user'], $config['smb']['password'].'foo'));