1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\Test\Module\webauthn\Controller; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\Attributes\DataProvider; |
|
|
|
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use SimpleSAML\Configuration; |
10
|
|
|
use SimpleSAML\Error; |
11
|
|
|
use SimpleSAML\Logger; |
12
|
|
|
use SimpleSAML\Module\webauthn\Controller; |
13
|
|
|
use SimpleSAML\Session; |
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Set of tests for the controllers in the "webauthn" module. |
18
|
|
|
* |
19
|
|
|
* @package SimpleSAML\Test |
20
|
|
|
*/ |
21
|
|
|
class StateTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
/** @var \SimpleSAML\Configuration */ |
24
|
|
|
protected Configuration $config; |
25
|
|
|
|
26
|
|
|
/** @var \SimpleSAML\Logger */ |
27
|
|
|
protected Logger $logger; |
28
|
|
|
|
29
|
|
|
/** @var \SimpleSAML\Session */ |
30
|
|
|
protected Session $session; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Set up for each test. |
35
|
|
|
*/ |
36
|
|
|
protected function setUp(): void |
37
|
|
|
{ |
38
|
|
|
parent::setUp(); |
39
|
|
|
|
40
|
|
|
$this->config = Configuration::loadFromArray( |
41
|
|
|
[ |
42
|
|
|
'module.enable' => ['webauthn' => true], |
43
|
|
|
'secretsalt' => 'abc123', |
44
|
|
|
'enable.saml20-idp' => true, |
45
|
|
|
], |
46
|
|
|
'[ARRAY]', |
47
|
|
|
'simplesaml', |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$this->session = Session::getSessionFromRequest(); |
51
|
|
|
|
52
|
|
|
$this->logger = new class () extends Logger { |
53
|
|
|
public static function info(string $string): void |
54
|
|
|
{ |
55
|
|
|
// do nothing |
56
|
|
|
} |
57
|
|
|
}; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string $method The method to be used for the test |
63
|
|
|
* @param string $controllerEndpoint The name of the endpoint of the controller to test |
64
|
|
|
* @param string $controllerClass The name of the controller class to test |
65
|
|
|
* @param string $controllerMethod The name of the controller method to test |
66
|
|
|
*/ |
67
|
|
|
#[DataProvider('stateTestsProvider')] |
68
|
|
|
public function testMissingState( |
69
|
|
|
string $method, |
70
|
|
|
string $controllerEndpoint, |
71
|
|
|
string $controllerClass, |
72
|
|
|
string $controllerMethod, |
73
|
|
|
): void { |
74
|
|
|
$_SERVER['REQUEST_URI'] = '/module.php/webauthn/' . $controllerEndpoint; |
75
|
|
|
$request = Request::create( |
76
|
|
|
'/' . $controllerEndpoint, |
77
|
|
|
$method, |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
$c = new $controllerClass($this->config, $this->session); |
81
|
|
|
$c->setLogger($this->logger); |
82
|
|
|
|
83
|
|
|
$this->expectException(Error\BadRequest::class); |
84
|
|
|
$this->expectExceptionMessage('Missing required StateId query parameter.'); |
85
|
|
|
|
86
|
|
|
call_user_func([$c, $controllerMethod], $request); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $method The method to be used for the test |
92
|
|
|
* @param string $controllerEndpoint The name of the endpoint of the controller to test |
93
|
|
|
* @param string $controllerClass The name of the controller class to test |
94
|
|
|
* @param string $controllerMethod The name of the controller method to test |
95
|
|
|
*/ |
96
|
|
|
#[DataProvider('stateTestsProvider')] |
97
|
|
|
public function testNoState( |
98
|
|
|
string $method, |
99
|
|
|
string $controllerEndpoint, |
100
|
|
|
string $controllerClass, |
101
|
|
|
string $controllerMethod, |
102
|
|
|
): void { |
103
|
|
|
$_SERVER['REQUEST_URI'] = '/module.php/webauthn/' . $controllerEndpoint; |
104
|
|
|
$request = Request::create( |
105
|
|
|
'/' . $controllerEndpoint . '?StateId=someStateId', |
106
|
|
|
$method, |
107
|
|
|
[], |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$c = new $controllerClass($this->config, $this->session); |
111
|
|
|
$c->setLogger($this->logger); |
112
|
|
|
|
113
|
|
|
$this->expectException(Error\NoState::class); |
114
|
|
|
$this->expectExceptionMessage('NOSTATE'); |
115
|
|
|
|
116
|
|
|
call_user_func([$c, $controllerMethod], $request); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return array |
122
|
|
|
*/ |
123
|
|
|
public static function stateTestsProvider(): array |
124
|
|
|
{ |
125
|
|
|
return [ |
126
|
|
|
['POST', 'authprocess', Controller\AuthProcess::class, 'main'], |
127
|
|
|
['POST', 'managetoken', Controller\ManageToken::class, 'main'], |
128
|
|
|
['POST', 'regprocess', Controller\RegProcess::class, 'main'], |
129
|
|
|
['POST', 'webauthn', Controller\WebAuthn::class, 'main'], |
130
|
|
|
]; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths