mirror of
https://github.com/LDAPAccountManager/lam.git
synced 2025-10-06 03:49:56 +02:00
Merge remote-tracking branch 'origin/develop' into feature/config-database
# Conflicts: # lam/tests/lib/webauthnTest.php
This commit is contained in:
commit
55f2c8ca1b
5 changed files with 58 additions and 64 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"require-dev" : {
|
||||
"phpunit/phpunit" : "8.5.2",
|
||||
"phpunit/phpunit" : "9.5.1",
|
||||
"squizlabs/php_codesniffer" : "3.4.0"
|
||||
},
|
||||
"require": {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?php
|
||||
namespace LAM\LOGIN\WEBAUTHN;
|
||||
|
||||
use LAMCfgMain;
|
||||
use LAMConfig;
|
||||
use \PHPUnit\Framework\TestCase;
|
||||
use \Webauthn\PublicKeyCredentialDescriptor;
|
||||
use \Webauthn\PublicKeyCredentialSource;
|
||||
|
@ -38,7 +40,7 @@ require_once __DIR__ . '/../../lib/webauthn.inc';
|
|||
class WebauthnManagerTest extends TestCase {
|
||||
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject|PublicKeyCredentialSourceRepositorySQLiteNoSave
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject|PublicKeyCredentialSourceRepositorySQLite
|
||||
*/
|
||||
private $database;
|
||||
/**
|
||||
|
@ -48,11 +50,13 @@ class WebauthnManagerTest extends TestCase {
|
|||
|
||||
protected function setup(): void {
|
||||
$this->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 {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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)';
|
||||
}
|
||||
|
|
38
phpunit.xml
38
phpunit.xml
|
@ -1,21 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit>
|
||||
<testsuites>
|
||||
<testsuite name="AllTests">
|
||||
<directory>lam/tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<php>
|
||||
<includePath>lam</includePath>
|
||||
</php>
|
||||
<logging>
|
||||
<log type="coverage-html" target="code-coverage/report.html"/>
|
||||
<log type="coverage-clover" target="code-coverage/clover.xml"/>
|
||||
<log type="junit" target="code-coverage/junit.xml"/>
|
||||
</logging>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".inc">lam/lib</directory>
|
||||
</include>
|
||||
<exclude>
|
||||
<directory>lam/tests</directory>
|
||||
<directory>lam/lib/3rdParty</directory>
|
||||
|
@ -26,6 +14,20 @@
|
|||
<file>lam/lib/security.inc</file>
|
||||
<file>lam/lib/checkEnvironment.inc</file>
|
||||
</exclude>
|
||||
</whitelist>
|
||||
</filter>
|
||||
<report>
|
||||
<clover outputFile="code-coverage/clover.xml"/>
|
||||
<html outputDirectory="code-coverage/report.html"/>
|
||||
</report>
|
||||
</coverage>
|
||||
<testsuites>
|
||||
<testsuite name="AllTests">
|
||||
<directory>lam/tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<php>
|
||||
<includePath>lam</includePath>
|
||||
</php>
|
||||
<logging>
|
||||
<junit outputFile="code-coverage/junit.xml"/>
|
||||
</logging>
|
||||
</phpunit>
|
Loading…
Add table
Add a link
Reference in a new issue