Skip to content
Snippets Groups Projects
Commit 24778635 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

update codeception/codeception to 5.1.2 and codeception/module-asserts to...

update codeception/codeception to 5.1.2 and codeception/module-asserts to 3.0.0, fix test, fixes #4150

Closes #4150

Merge request studip/studip!2990
parent 4c0242f0
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
......@@ -15,22 +15,21 @@ class Authentication
// $user = $request->getAttribute(Authentication::USER_KEY);
const USER_KEY = 'studip-user';
// a callable accepting two arguments username and password and
// returning either null or a Stud.IP user object
/** @var callable */
private $authenticator;
/**
* Der Konstruktor.
*
* @param callable $authenticator ein Callable, das den Nutzernamen und
* @param \Closure $authenticator eine Closure, die den Nutzernamen und
* das Passwort als Argumente erhält und
* damit entweder einen Stud.IP-User-Objekt
* oder null zurückgibt
* @param array $excluded_strategies
*/
public function __construct($authenticator)
{
$this->authenticator = $authenticator;
public function __construct(
// a callable accepting two arguments username and password and
// returning either null or a Stud.IP user object
private readonly \Closure $authenticator,
private readonly array $excluded_strategies = []
) {
}
/**
......@@ -45,12 +44,7 @@ class Authentication
*/
public function __invoke(Request $request, RequestHandler $handler)
{
$guards = [
new Auth\SessionStrategy(),
new Auth\HttpBasicAuthStrategy($request, $this->authenticator),
new Auth\OAuth2Strategy($request, $this->authenticator),
new Auth\OAuth1Strategy($request, $this->authenticator),
];
$guards = $this->getGuards($request);
foreach ($guards as $guard) {
if ($guard->check()) {
......@@ -101,4 +95,25 @@ class Authentication
return $request->withAttribute(self::USER_KEY, $user);
}
/**
* @param Request $request
*
* @return array
*/
protected function getGuards(Request $request): array
{
$guards = [
'session' => new Auth\SessionStrategy(),
'basic' => new Auth\HttpBasicAuthStrategy($request, $this->authenticator),
'oauth2' => new Auth\OAuth2Strategy($request, $this->authenticator),
'oauth1' => new Auth\OAuth1Strategy($request, $this->authenticator),
];
foreach ($this->excluded_strategies as $strategy) {
unset($guards[$strategy]);
}
return $guards;
}
}
......@@ -148,7 +148,7 @@ class Jsonapi extends \Codeception\Module
return $handler->handle($request);
})
->add(new Authentication($authenticator));
->add(new Authentication($authenticator, ['session']));
}
return $app;
......
......@@ -5,7 +5,7 @@ namespace Helper;
use Codeception\Exception\ModuleConfigException;
use Codeception\Exception\ModuleException;
require_once('lib/classes/StudipPDO.class.php');
require_once 'lib/classes/StudipPDO.class.php';
class StudipDb extends \Codeception\Module
{
......@@ -14,18 +14,17 @@ class StudipDb extends \Codeception\Module
*
* @var
*/
public $dbh;
public ?\StudipPdo $dbh;
/**
* @var array
*/
protected $config = [
];
protected array $config = [];
/**
* @var array
*/
protected $requiredFields = ['dsn', 'user', 'password'];
protected array $requiredFields = ['dsn', 'user', 'password'];
/**
* @SuppressWarnings(PHPMD.CamelCaseMethodName)
......@@ -42,7 +41,7 @@ class StudipDb extends \Codeception\Module
private function checkConfig($configKey, $name)
{
if (strstr($this->config[$configKey], '%'.$name.'%')) {
if (str_contains($this->config[$configKey], '%' . $name . '%')) {
throw new ModuleConfigException(__CLASS__, 'You have to provide a '.$name.' either as ENV variable or in config_local.inc.php!');
}
}
......
<?php
return (function (string ...$filenames) {
$ABSOLUTE_URI_STUDIP = '';
$ASSETS_URL = '';
$STUDIP_BASE_PATH = '';
foreach ($filenames as $filename) {
if (file_exists($filename)) {
require_once $filename;
......
......@@ -52,7 +52,7 @@ class StructuralElementsShowTest extends \Codeception\Test\Unit
$childIDs = $structuralElement->children->pluck('id');
$this->assertCount(count($childIDs), $includedResources);
foreach ($includedResources as $included) {
$this->assertContains($included->id(), $childIDs);
$this->assertContainsEquals($included->id(), $childIDs);
}
}
......
......@@ -74,14 +74,12 @@ StudipAutoloader::addAutoloadPath($GLOBALS['STUDIP_BASE_PATH'].'/lib/classes/vis
StudipAutoloader::addAutoloadPath($GLOBALS['STUDIP_BASE_PATH'].'/vendor/oauth-php/library');
// Messy file names
StudipAutoloader::addClassLookups(
array(
StudipAutoloader::addClassLookups([
'StudipPlugin' => $GLOBALS['STUDIP_BASE_PATH'].'/lib/plugins/core/StudIPPlugin.class.php',
'messaging' => $GLOBALS['STUDIP_BASE_PATH'].'/lib/messaging.inc.php',
)
);
]);
$GLOBALS['_fullname_sql'] = array();
$GLOBALS['_fullname_sql'] = [];
$GLOBALS['_fullname_sql']['full'] = "TRIM(CONCAT(title_front,' ',Vorname,' ',Nachname,IF(title_rear!='',CONCAT(', ',title_rear),'')))";
$GLOBALS['_fullname_sql']['full_rev'] = "TRIM(CONCAT(Nachname,', ',Vorname,IF(title_front!='',CONCAT(', ',title_front),''),IF(title_rear!='',CONCAT(', ',title_rear),'')))";
$GLOBALS['_fullname_sql']['no_title'] = "CONCAT(Vorname ,' ', Nachname)";
......
......@@ -56,7 +56,7 @@ class StudipFileloaderTestCase extends \Codeception\Test\Unit
public function test_should_balk_upon_file_not_found()
{
$this->expectException(\PHPUnit\Framework\Exception::class);
$this->expectException(Exception::class);
StudipFileloader::load('var://pathto/not-there.php', $container);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment