1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace SimpleSAML\Test\Module\webauthn\Controller; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use SimpleSAML\Auth\State; |
9
|
|
|
use SimpleSAML\Configuration; |
10
|
|
|
use SimpleSAML\Logger; |
11
|
|
|
use SimpleSAML\Module\webauthn\Controller; |
12
|
|
|
use SimpleSAML\Session; |
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Set of tests for the controllers in the "webauthn" module. |
17
|
|
|
* |
18
|
|
|
* @package SimpleSAML\Test |
19
|
|
|
*/ |
20
|
|
|
class WebAuthnTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
/** @var \SimpleSAML\Configuration */ |
23
|
|
|
protected Configuration $config; |
24
|
|
|
|
25
|
|
|
/** @var \SimpleSAML\Configuration */ |
26
|
|
|
protected $module_config; |
27
|
|
|
|
28
|
|
|
/** @var \SimpleSAML\Logger */ |
29
|
|
|
protected Logger $logger; |
30
|
|
|
|
31
|
|
|
/** @var \SimpleSAML\Session */ |
32
|
|
|
protected Session $session; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Set up for each test. |
37
|
|
|
*/ |
38
|
|
|
protected function setUp(): void |
39
|
|
|
{ |
40
|
|
|
parent::setUp(); |
41
|
|
|
|
42
|
|
|
$this->config = Configuration::loadFromArray( |
43
|
|
|
[ |
44
|
|
|
'module.enable' => ['webauthn' => true], |
45
|
|
|
'secretsalt' => 'abc123', |
46
|
|
|
'enable.saml20-idp' => true, |
47
|
|
|
], |
48
|
|
|
'[ARRAY]', |
49
|
|
|
'simplesaml', |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
$this->module_config = Configuration::loadFromArray( |
53
|
|
|
[ |
54
|
|
|
'registration' => ['use_inflow_registration' => true], |
55
|
|
|
], |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
$this->session = Session::getSessionFromRequest(); |
59
|
|
|
|
60
|
|
|
$this->logger = new class () extends Logger |
61
|
|
|
{ |
62
|
|
|
public static function info(string $string): void |
63
|
|
|
{ |
64
|
|
|
// do nothing |
65
|
|
|
} |
66
|
|
|
}; |
67
|
|
|
|
68
|
|
|
Configuration::setPreLoadedConfig($this->config, 'config.php'); |
69
|
|
|
Configuration::setPreLoadedConfig($this->module_config, 'module_webauthn.php'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
*/ |
75
|
|
|
public function testWebAuthn(): void |
76
|
|
|
{ |
77
|
|
|
$_SERVER['REQUEST_URI'] = '/module.php/webauthn/webauthn'; |
78
|
|
|
$request = Request::create( |
79
|
|
|
'/webauthn?StateId=someStateId', |
80
|
|
|
'POST', |
81
|
|
|
[], |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
$c = new Controller\WebAuthn($this->config, $this->session); |
86
|
|
|
$c->setLogger($this->logger); |
87
|
|
|
$c->setAuthState(new class () extends State { |
88
|
|
|
public static function loadState(string $id, string $stage, bool $allowMissing = false): ?array |
89
|
|
|
{ |
90
|
|
|
return [ |
91
|
|
|
'UseInflowRegistration' => true, |
92
|
|
|
'FIDO2Displayname' => 'Donald Duck', |
93
|
|
|
'FIDO2Username' => 'dduck', |
94
|
|
|
'FIDO2Scope' => 'Ducktown', |
95
|
|
|
'FIDO2Tokens' => [0 => 'A1B2C3', 1 => 'D4E5F6'], |
96
|
|
|
'FIDO2SignupChallenge' => 'A1B2C3', |
97
|
|
|
'FIDO2WantsRegister' => false, |
98
|
|
|
'FIDO2PasswordlessAuthMode' => false, |
99
|
|
|
'FIDO2AuthSuccessful' => false, |
100
|
|
|
'requestTokenModel' => 'something', |
101
|
|
|
'Source' => 'There is no real auth source in this test.', |
102
|
|
|
]; |
103
|
|
|
} |
104
|
|
|
}); |
105
|
|
|
|
106
|
|
|
$response = $c->main($request); |
107
|
|
|
|
108
|
|
|
$this->assertTrue($response->isSuccessful()); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|