function testCallBack() { $args = []; $callBack = function ($user, $pass) use(&$args) { $args = [$user, $pass]; return true; }; $backend = new BasicCallBack($callBack); $request = Sapi::createFromServerArray(['HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('foo:bar')]); $response = new Response(); $this->assertEquals([true, 'principals/foo'], $backend->check($request, $response)); $this->assertEquals(['foo', 'bar'], $args); }
function testCallBack() { $args = array(); $callBack = function ($user, $pass) use(&$args) { $args = [$user, $pass]; return true; }; $backend = new BasicCallBack($callBack); $server = new Server(); $server->httpRequest = Sapi::createFromServerArray(['HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('foo:bar')]); $this->assertTrue($backend->authenticate($server, 'Realm')); $this->assertEquals(['foo', 'bar'], $args); }
require './class/CalDAVDolibarr.php'; $user = new User($db); if (isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_USER'] != '') { $user->fetch('', $_SERVER['PHP_AUTH_USER']); $user->getrights(); } $cdavLib = new CdavLib($user, $db, $langs); // Authentication $authBackend = new DAV\Auth\Backend\BasicCallBack(function ($username, $password) { global $user; if (!isset($user->login) || $user->login == '') { return false; } if ($user->societe_id != 0) { return false; } if ($user->login != $username) { return false; } if ($user->pass_indatabase_crypted == '' || dol_hash($password) != $user->pass_indatabase_crypted) { return false; } return true; }); $authBackend->setRealm('Dolibarr'); // The lock manager is reponsible for making sure users don't overwrite // each others changes. $lockBackend = new DAV\Locks\Backend\File($dolibarr_main_data_root . '/cdav/.locks'); // Principals Backend $principalBackend = new DAVACL\PrincipalBackend\Dolibarr($user, $db); // CardDav & CalDav Backend $carddavBackend = new Sabre\CardDAV\Backend\Dolibarr($user, $db, $langs);