Merge remote-tracking branch 'origin/develop' into feature/config-database

# Conflicts:
#	lam/tests/lib/webauthnTest.php
This commit is contained in:
Roland Gruber 2021-01-23 21:14:43 +01:00
commit 55f2c8ca1b
5 changed files with 58 additions and 64 deletions

View file

@ -1,6 +1,6 @@
{ {
"require-dev" : { "require-dev" : {
"phpunit/phpunit" : "8.5.2", "phpunit/phpunit" : "9.5.1",
"squizlabs/php_codesniffer" : "3.4.0" "squizlabs/php_codesniffer" : "3.4.0"
}, },
"require": { "require": {

View file

@ -3,7 +3,7 @@ use PHPUnit\Framework\TestCase;
/* /*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2016 - 2020 Roland Gruber Copyright (C) 2016 - 2021 Roland Gruber
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -36,7 +36,7 @@ class LAMConfigTest extends TestCase {
*/ */
private $lAMConfig; private $lAMConfig;
const FILE_NAME = 'LAMConfigTest'; const FILE_NAME = 'd_LAMConfigTest';
/** /**
* Prepares the environment before running a test. * Prepares the environment before running a test.

View file

@ -1,6 +1,8 @@
<?php <?php
namespace LAM\LOGIN\WEBAUTHN; namespace LAM\LOGIN\WEBAUTHN;
use LAMCfgMain;
use LAMConfig;
use \PHPUnit\Framework\TestCase; use \PHPUnit\Framework\TestCase;
use \Webauthn\PublicKeyCredentialDescriptor; use \Webauthn\PublicKeyCredentialDescriptor;
use \Webauthn\PublicKeyCredentialSource; use \Webauthn\PublicKeyCredentialSource;
@ -38,7 +40,7 @@ require_once __DIR__ . '/../../lib/webauthn.inc';
class WebauthnManagerTest extends TestCase { class WebauthnManagerTest extends TestCase {
/** /**
* @var \PHPUnit_Framework_MockObject_MockObject|PublicKeyCredentialSourceRepositorySQLiteNoSave * @var \PHPUnit_Framework_MockObject_MockObject|PublicKeyCredentialSourceRepositorySQLite
*/ */
private $database; private $database;
/** /**
@ -48,11 +50,13 @@ class WebauthnManagerTest extends TestCase {
protected function setup(): void { protected function setup(): void {
$this->database = $this $this->database = $this
->getMockBuilder(PublicKeyCredentialSourceRepositorySQLiteNoSave::class) ->getMockBuilder(PublicKeyCredentialSourceRepositorySQLite::class)
->onlyMethods(array('findOneByCredentialId', 'findAllForUserEntity', 'saveCredentialSource')) ->onlyMethods(array('getPdoUrl', 'findOneByCredentialId', 'findAllForUserEntity'))
->getMock(); ->getMock();
$file = tmpfile();
$filePath = stream_get_meta_data($file)['uri'];
$this->database->method('getPdoUrl')->willReturn('sqlite:' . $filePath);
$this->database->method('findOneByCredentialId')->willReturn(null); $this->database->method('findOneByCredentialId')->willReturn(null);
$this->database->method('findAllForUserEntity')->willReturn(array());
$this->manager = $this $this->manager = $this
->getMockBuilder(WebauthnManager::class) ->getMockBuilder(WebauthnManager::class)
@ -60,36 +64,40 @@ class WebauthnManagerTest extends TestCase {
->getMock(); ->getMock();
$this->manager->method('getDatabase')->willReturn($this->database); $this->manager->method('getDatabase')->willReturn($this->database);
$cfgMain = new \LAMCfgMain(); $cfgMain = new LAMCfgMain();
$cfgMain->passwordMinLength = 3; $cfgMain->passwordMinLength = 3;
$logFile = tmpfile(); $logFile = tmpfile();
$logFilePath = stream_get_meta_data($logFile)['uri']; $logFilePath = stream_get_meta_data($logFile)['uri'];
$cfgMain->logDestination = $logFilePath; $cfgMain->logDestination = $logFilePath;
$_SESSION['cfgMain'] = $cfgMain; $_SESSION['cfgMain'] = $cfgMain;
$file = tmpfile(); $config = new LAMConfig('d_LAMConfigTest');
$filePath = stream_get_meta_data($file)['uri'];
$config = new \LAMConfig($filePath);
$config->setTwoFactorAuthenticationDomain('domain'); $config->setTwoFactorAuthenticationDomain('domain');
$_SESSION['config'] = $config; $_SESSION['config'] = $config;
} }
public function test_getAuthenticationObject() { public function test_getAuthenticationObject() {
$this->database->method('findAllForUserEntity')->willReturn(array());
$authenticationObj = $this->manager->getAuthenticationObject('userDN', false); $authenticationObj = $this->manager->getAuthenticationObject('userDN', false);
$this->assertEquals(40, sizeof($authenticationObj->getChallenge())); $this->assertEquals(32, strlen($authenticationObj->getChallenge()));
$this->assertEquals('domain', $authenticationObj->getRpId()); $this->assertEquals('domain', $authenticationObj->getRpId());
} }
public function test_getRegistrationObject() { public function test_getRegistrationObject() {
$registrationObject = $this->manager->getRegistrationObject('userDn', false); $registrationObject = $this->manager->getRegistrationObject('userDn', false);
$this->assertEquals(40, sizeof($registrationObject->getChallenge())); $this->assertEquals(32, strlen($registrationObject->getChallenge()));
$this->assertEquals('domain', $registrationObject->getRp()->getId()); $this->assertEquals('domain', $registrationObject->getRp()->getId());
} }
public function test_isRegistered() { public function test_isRegistered_notRegistered() {
$this->database->method('findAllForUserEntity')->willReturn(array()); $this->database->method('findAllForUserEntity')->willReturn(array());
$isRegistered = $this->manager->isRegistered('userDN'); $isRegistered = $this->manager->isRegistered('userDN');
$this->assertFalse($isRegistered); $this->assertFalse($isRegistered);
}
public function test_isRegistered_registered() {
$this->database->method('findAllForUserEntity')->willReturn(array( $this->database->method('findAllForUserEntity')->willReturn(array(
new PublicKeyCredentialSource( new PublicKeyCredentialSource(
"id1", "id1",
@ -102,25 +110,9 @@ class WebauthnManagerTest extends TestCase {
"uh1", "uh1",
1) 1)
)); ));
$isRegistered = $this->manager->isRegistered('userDN'); $isRegistered = $this->manager->isRegistered('userDN');
$this->assertTrue($isRegistered); $this->assertTrue($isRegistered);
} }
} }
/**
* Test class to deactivate saving.
*
* @package LAM\LOGIN\WEBAUTHN
*/
class PublicKeyCredentialSourceRepositorySQLiteNoSave extends PublicKeyCredentialSourceRepositorySQLite {
/**
* No saving
*
* @param PublicKeyCredentialSource $publicKeyCredentialSource source
*/
public function saveCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource): void {
}
}

View file

@ -3,7 +3,7 @@
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2014 - 2016 Roland Gruber Copyright (C) 2014 - 2021 Roland Gruber
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -30,12 +30,12 @@ function testCreateDefaultConfig() {
$cfgMain = new LAMCfgMain(); $cfgMain = new LAMCfgMain();
$cfgMain->logDestination = 'NONE'; $cfgMain->logDestination = 'NONE';
$_SESSION['cfgMain'] = $cfgMain; $_SESSION['cfgMain'] = $cfgMain;
$cfgPath = dirname(__FILE__) . '/../../config/phpunit.conf'; $cfgPath = dirname(__FILE__) . '/../../config/d_LAMConfigTest.conf';
if (file_exists($cfgPath)) { if (file_exists($cfgPath)) {
unlink($cfgPath); unlink($cfgPath);
} }
touch($cfgPath); touch($cfgPath);
$config = new LAMConfig('phpunit'); $config = new LAMConfig('d_LAMConfigTest');
$_SESSION['config'] = $config; $_SESSION['config'] = $config;
$_SESSION['language'] = 'en_GB.utf8:UTF-8:English (Great Britain)'; $_SESSION['language'] = 'en_GB.utf8:UTF-8:English (Great Britain)';
} }

View file

@ -1,31 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<testsuites> <coverage processUncoveredFiles="true">
<testsuite name="AllTests"> <include>
<directory>lam/tests</directory> <directory suffix=".inc">lam/lib</directory>
</testsuite> </include>
</testsuites> <exclude>
<php> <directory>lam/tests</directory>
<includePath>lam</includePath> <directory>lam/lib/3rdParty</directory>
</php> <directory>lam/templates/3rdParty</directory>
<logging> <file>lam/lib/adminHeader.inc</file>
<log type="coverage-html" target="code-coverage/report.html"/> <file>lam/lib/adminFooter.inc</file>
<log type="coverage-clover" target="code-coverage/clover.xml"/> <file>lam/lib/cron.inc</file>
<log type="junit" target="code-coverage/junit.xml"/> <file>lam/lib/security.inc</file>
</logging> <file>lam/lib/checkEnvironment.inc</file>
<filter> </exclude>
<whitelist processUncoveredFilesFromWhitelist="true"> <report>
<directory suffix=".inc">lam/lib</directory> <clover outputFile="code-coverage/clover.xml"/>
<exclude> <html outputDirectory="code-coverage/report.html"/>
<directory>lam/tests</directory> </report>
<directory>lam/lib/3rdParty</directory> </coverage>
<directory>lam/templates/3rdParty</directory> <testsuites>
<file>lam/lib/adminHeader.inc</file> <testsuite name="AllTests">
<file>lam/lib/adminFooter.inc</file> <directory>lam/tests</directory>
<file>lam/lib/cron.inc</file> </testsuite>
<file>lam/lib/security.inc</file> </testsuites>
<file>lam/lib/checkEnvironment.inc</file> <php>
</exclude> <includePath>lam</includePath>
</whitelist> </php>
</filter> <logging>
</phpunit> <junit outputFile="code-coverage/junit.xml"/>
</logging>
</phpunit>