added a TestCase for basic auth
Signed-off-by: Lutz Freitag <lutz@gottliebtfreitag.de>
This commit is contained in:
@@ -146,7 +146,7 @@ Add the following to your `config.php`:
|
|||||||
|
|
||||||
'user_backends' => array(
|
'user_backends' => array(
|
||||||
array(
|
array(
|
||||||
'class' => '\OCA\User_External\BasicAuth',
|
'class' => 'OC_User_BasicAuth',
|
||||||
'arguments' => array('https://example.com/basic_auth'),
|
'arguments' => array('https://example.com/basic_auth'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ class OC_User_BasicAuth extends \OCA\user_external\Base {
|
|||||||
);
|
);
|
||||||
$headers = get_headers($this->authUrl);
|
$headers = get_headers($this->authUrl);
|
||||||
|
|
||||||
if($headers === false) {
|
if(!$headers) {
|
||||||
OC::$server->getLogger()->error(
|
OC::$server->getLogger()->error(
|
||||||
'ERROR: Not possible to connect to BasicAuth Url: "'.$this->authUrl.'"',
|
'ERROR: Not possible to connect to BasicAuth Url: '.$this->authUrl,
|
||||||
['app' => 'user_external']
|
['app' => 'user_external']
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
35
tests/basic_auth.php
Normal file
35
tests/basic_auth.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2019 Lutz Freitag <lutz.freitag@gottliebtfreitag.de>
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
* See the COPYING-README file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Test_User_BasicAuth extends \Test\TestCase {
|
||||||
|
/**
|
||||||
|
* @var OC_User_BasicAuth $instance
|
||||||
|
*/
|
||||||
|
private $instance;
|
||||||
|
|
||||||
|
private function getConfig() {
|
||||||
|
return include(__DIR__.'/config.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
function skip() {
|
||||||
|
$config=$this->getConfig();
|
||||||
|
$this->skipUnless($config['basic_auth']['run']);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
$config=$this->getConfig();
|
||||||
|
$this->instance=new OC_User_BasicAuth($config['basic_auth']['url']);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testLogin() {
|
||||||
|
$config=$this->getConfig();
|
||||||
|
$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'));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,4 +26,10 @@ return array(
|
|||||||
'user'=>'test',//valid username/password combination
|
'user'=>'test',//valid username/password combination
|
||||||
'password'=>'test',
|
'password'=>'test',
|
||||||
),
|
),
|
||||||
|
'basic_auth'=>array(
|
||||||
|
'run'=>false,
|
||||||
|
'url'=>'localhost/basic_auth',
|
||||||
|
'user'=>'test',//valid username/password combination
|
||||||
|
'password'=>'test',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user