librenms/tests/AuthHTTPTest.php
Tony Murray 32a7c50189
Use Laravel authentication (#8702)
* Use Laravel for authentication
Support legacy auth methods
Always create DB entry for users (segregate by auth method)

Port api auth to Laravel

restrict poller errors to devices the user has access to

Run checks on every page load.  But set a 5 minute (configurable) timer.
Only run some checks if the user is an admin

Move toastr down a few pixels so it isn't as annoying.

Fix menu not loaded on laravel pages when twofactor is enabled for the system, but disabled for the user.
Add two missing menu entries in the laravel menu

Rewrite 2FA code
Simplify some and verify code before applying

Get http-auth working
Handle legacy $_SESSION differently.  Allows Auth::once(), etc to work.

* Fix tests and mysqli extension check

* remove duplicate Toastr messages

* Fix new items

* Rename 266.sql to 267.sql
2018-09-11 07:51:35 -05:00

90 lines
2.9 KiB
PHP

<?php
/**
* AuthHTTP.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package LibreNMS
* @link https://librenms.org
* @copyright 2017 Adam Bishop
* @author Adam Bishop <adam@omega.org.uk>
*/
namespace LibreNMS\Tests;
use LibreNMS\Authentication\LegacyAuth;
use LibreNMS\Exceptions\AuthenticationException;
// Note that as this test set depends on mres(), it is a DBTestCase even though the database is unused
class AuthHTTPTest extends DBTestCase
{
// Document the modules current behaviour, so that changes trigger test failures
public function testCapabilityFunctions()
{
global $config;
$config['auth_mechanism'] = 'http-auth';
$a = LegacyAuth::reset();
$this->assertTrue($a->canUpdatePasswords() === 0);
$this->assertTrue($a->changePassword(null, null) === 0);
$this->assertTrue($a->canManageUsers() === 1);
$this->assertTrue($a->canUpdateUsers() === 1);
$this->assertTrue($a->authIsExternal() === 1);
}
public function testOldBehaviourAgainstCurrent()
{
global $config;
$old_username = null;
$new_username = null;
$config['auth_mechanism'] = 'http-auth';
$users = array('steve', ' steve', 'steve ', ' steve ', ' steve ', '', 'CAT');
$vars = array('REMOTE_USER', 'PHP_AUTH_USER');
$a = LegacyAuth::reset();
foreach ($vars as $v) {
foreach ($users as $u) {
$_SERVER[$v] = $u;
// Old Behaviour
if (isset($_SERVER['REMOTE_USER'])) {
$old_username = clean($_SERVER['REMOTE_USER']);
} elseif (isset($_SERVER['PHP_AUTH_USER']) && $config['auth_mechanism'] === 'http-auth') {
$old_username = clean($_SERVER['PHP_AUTH_USER']);
}
// Current Behaviour
if ($a->authIsExternal()) {
$new_username = $a->getExternalUsername();
}
$this->assertFalse($old_username === null);
$this->assertFalse($new_username === null);
$this->assertTrue($old_username === $new_username);
}
unset($_SERVER[$v]);
}
unset($config['auth_mechanism']);
}
}