From d308d09bb1e3bbb5142cd736d7c42d1021eba0a1 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 23 Jan 2021 20:19:37 +0100 Subject: [PATCH 1/3] fixed test --- lam/tests/lib/webauthnTest.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lam/tests/lib/webauthnTest.php b/lam/tests/lib/webauthnTest.php index dbe691ec9..5e538ab14 100644 --- a/lam/tests/lib/webauthnTest.php +++ b/lam/tests/lib/webauthnTest.php @@ -9,7 +9,7 @@ use \Webauthn\TrustPath\CertificateTrustPath; /* This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) - Copyright (C) 2019 - 2020 Roland Gruber + Copyright (C) 2019 - 2021 Roland Gruber 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 @@ -38,7 +38,7 @@ require_once __DIR__ . '/../../lib/webauthn.inc'; class WebauthnManagerTest extends TestCase { /** - * @var \PHPUnit_Framework_MockObject_MockObject|PublicKeyCredentialSourceRepositorySQLite + * @var \PHPUnit_Framework_MockObject_MockObject|PublicKeyCredentialSourceRepositorySQLiteNoSave */ private $database; /** @@ -48,12 +48,11 @@ class WebauthnManagerTest extends TestCase { protected function setup(): void { $this->database = $this - ->getMockBuilder(PublicKeyCredentialSourceRepositorySQLite::class) + ->getMockBuilder(PublicKeyCredentialSourceRepositorySQLiteNoSave::class) ->onlyMethods(array('findOneByCredentialId', 'findAllForUserEntity', 'saveCredentialSource')) ->getMock(); $this->database->method('findOneByCredentialId')->willReturn(null); $this->database->method('findAllForUserEntity')->willReturn(array()); - $this->database->method('saveCredentialSource')->willReturn(null); $this->manager = $this ->getMockBuilder(WebauthnManager::class) @@ -108,3 +107,20 @@ class WebauthnManagerTest extends TestCase { } } + +/** + * 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 { + } + +} From 39c3a06805a30aeb856a587751f3701193304acb Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 23 Jan 2021 21:08:04 +0100 Subject: [PATCH 2/3] fixed tests --- composer.json | 2 +- lam/tests/lib/LAMConfigTest.php | 4 +-- lam/tests/lib/webauthnTest.php | 48 +++++++++++++------------------ lam/tests/utils/configuration.inc | 6 ++-- 4 files changed, 26 insertions(+), 34 deletions(-) diff --git a/composer.json b/composer.json index 7c61b448f..b35cdbbeb 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "require-dev" : { - "phpunit/phpunit" : "8.5.2", + "phpunit/phpunit" : "9.5.1", "squizlabs/php_codesniffer" : "3.4.0" }, "require": { diff --git a/lam/tests/lib/LAMConfigTest.php b/lam/tests/lib/LAMConfigTest.php index 702c58b62..baf416bc6 100644 --- a/lam/tests/lib/LAMConfigTest.php +++ b/lam/tests/lib/LAMConfigTest.php @@ -3,7 +3,7 @@ use PHPUnit\Framework\TestCase; /* 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 it under the terms of the GNU General Public License as published by @@ -36,7 +36,7 @@ class LAMConfigTest extends TestCase { */ private $lAMConfig; - const FILE_NAME = 'LAMConfigTest'; + const FILE_NAME = 'd_LAMConfigTest'; /** * Prepares the environment before running a test. diff --git a/lam/tests/lib/webauthnTest.php b/lam/tests/lib/webauthnTest.php index 5e538ab14..c8d9a0c0e 100644 --- a/lam/tests/lib/webauthnTest.php +++ b/lam/tests/lib/webauthnTest.php @@ -1,6 +1,8 @@ database = $this - ->getMockBuilder(PublicKeyCredentialSourceRepositorySQLiteNoSave::class) - ->onlyMethods(array('findOneByCredentialId', 'findAllForUserEntity', 'saveCredentialSource')) + ->getMockBuilder(PublicKeyCredentialSourceRepositorySQLite::class) + ->onlyMethods(array('getPdoUrl', 'findOneByCredentialId', 'findAllForUserEntity')) ->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('findAllForUserEntity')->willReturn(array()); $this->manager = $this ->getMockBuilder(WebauthnManager::class) @@ -60,36 +64,40 @@ class WebauthnManagerTest extends TestCase { ->getMock(); $this->manager->method('getDatabase')->willReturn($this->database); - $cfgMain = new \LAMCfgMain(); + $cfgMain = new LAMCfgMain(); $cfgMain->passwordMinLength = 3; $logFile = tmpfile(); $logFilePath = stream_get_meta_data($logFile)['uri']; $cfgMain->logDestination = $logFilePath; $_SESSION['cfgMain'] = $cfgMain; - $file = tmpfile(); - $filePath = stream_get_meta_data($file)['uri']; - $config = new \LAMConfig($filePath); + $config = new LAMConfig('d_LAMConfigTest'); $config->setTwoFactorAuthenticationDomain('domain'); $_SESSION['config'] = $config; } public function test_getAuthenticationObject() { + $this->database->method('findAllForUserEntity')->willReturn(array()); + $authenticationObj = $this->manager->getAuthenticationObject('userDN', false); - $this->assertEquals(40, sizeof($authenticationObj->getChallenge())); + $this->assertEquals(32, strlen($authenticationObj->getChallenge())); $this->assertEquals('domain', $authenticationObj->getRpId()); } public function test_getRegistrationObject() { $registrationObject = $this->manager->getRegistrationObject('userDn', false); - $this->assertEquals(40, sizeof($registrationObject->getChallenge())); + $this->assertEquals(32, strlen($registrationObject->getChallenge())); $this->assertEquals('domain', $registrationObject->getRp()->getId()); } - public function test_isRegistered() { + public function test_isRegistered_notRegistered() { $this->database->method('findAllForUserEntity')->willReturn(array()); + $isRegistered = $this->manager->isRegistered('userDN'); $this->assertFalse($isRegistered); + } + + public function test_isRegistered_registered() { $this->database->method('findAllForUserEntity')->willReturn(array( new PublicKeyCredentialSource( "id1", @@ -102,25 +110,9 @@ class WebauthnManagerTest extends TestCase { "uh1", 1) )); + $isRegistered = $this->manager->isRegistered('userDN'); $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 { - } - -} diff --git a/lam/tests/utils/configuration.inc b/lam/tests/utils/configuration.inc index c440d0b26..766512f87 100644 --- a/lam/tests/utils/configuration.inc +++ b/lam/tests/utils/configuration.inc @@ -3,7 +3,7 @@ $Id$ 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 it under the terms of the GNU General Public License as published by @@ -30,12 +30,12 @@ function testCreateDefaultConfig() { $cfgMain = new LAMCfgMain(); $cfgMain->logDestination = 'NONE'; $_SESSION['cfgMain'] = $cfgMain; - $cfgPath = dirname(__FILE__) . '/../../config/phpunit.conf'; + $cfgPath = dirname(__FILE__) . '/../../config/d_LAMConfigTest.conf'; if (file_exists($cfgPath)) { unlink($cfgPath); } touch($cfgPath); - $config = new LAMConfig('phpunit'); + $config = new LAMConfig('d_LAMConfigTest'); $_SESSION['config'] = $config; $_SESSION['language'] = 'en_GB.utf8:UTF-8:English (Great Britain)'; } From 25c0a8f28bda03da3d88598dbda45b34d3e7d129 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 23 Jan 2021 21:10:30 +0100 Subject: [PATCH 3/3] fixed tests --- phpunit.xml | 62 +++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index d0286f1b2..33e0f61ea 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,31 +1,33 @@ - - - - lam/tests - - - - lam - - - - - - - - - lam/lib - - lam/tests - lam/lib/3rdParty - lam/templates/3rdParty - lam/lib/adminHeader.inc - lam/lib/adminFooter.inc - lam/lib/cron.inc - lam/lib/security.inc - lam/lib/checkEnvironment.inc - - - - \ No newline at end of file + + + + lam/lib + + + lam/tests + lam/lib/3rdParty + lam/templates/3rdParty + lam/lib/adminHeader.inc + lam/lib/adminFooter.inc + lam/lib/cron.inc + lam/lib/security.inc + lam/lib/checkEnvironment.inc + + + + + + + + + lam/tests + + + + lam + + + + +