|
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; |
|
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 RegistrationTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var \SimpleSAML\Configuration */ |
|
23
|
|
|
protected Configuration $config; |
|
24
|
|
|
|
|
25
|
|
|
/** @var \SimpleSAML\Logger */ |
|
26
|
|
|
protected Logger $logger; |
|
27
|
|
|
|
|
28
|
|
|
/** @var \SimpleSAML\Session */ |
|
29
|
|
|
protected Session $session; |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Set up for each test. |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function setUp(): void |
|
36
|
|
|
{ |
|
37
|
|
|
parent::setUp(); |
|
38
|
|
|
|
|
39
|
|
|
$this->config = Configuration::loadFromArray( |
|
40
|
|
|
[ |
|
41
|
|
|
'module.enable' => ['webauthn' => true], |
|
42
|
|
|
'secretsalt' => 'abc123', |
|
43
|
|
|
'enable.saml20-idp' => true, |
|
44
|
|
|
], |
|
45
|
|
|
'[ARRAY]', |
|
46
|
|
|
'simplesaml', |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
|
|
Configuration::setPreLoadedConfig( |
|
50
|
|
|
Configuration::loadFromArray( |
|
51
|
|
|
[ |
|
52
|
|
|
'identifyingAttribute' => 'uid', |
|
53
|
|
|
'attrib_displayname' => 'displayName', |
|
54
|
|
|
'store' => [ |
|
55
|
|
|
'webauthn:Database', |
|
56
|
|
|
'database.dsn' => 'mysql:host=db.example.org;dbname=fido2', |
|
57
|
|
|
'database.username' => 'simplesaml', |
|
58
|
|
|
'database.password' => 'sdfsdf', |
|
59
|
|
|
], |
|
60
|
|
|
], |
|
61
|
|
|
'[ARRAY]', |
|
62
|
|
|
'simplesaml', |
|
63
|
|
|
), |
|
64
|
|
|
'module_webauthn.php', |
|
65
|
|
|
'simplesaml', |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
$this->session = Session::getSessionFromRequest(); |
|
69
|
|
|
|
|
70
|
|
|
$this->logger = new class () extends Logger { |
|
71
|
|
|
public static function info(string $string): void |
|
72
|
|
|
{ |
|
73
|
|
|
// do nothing |
|
74
|
|
|
} |
|
75
|
|
|
}; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
*/ |
|
81
|
|
|
public function testRegistration(): void |
|
82
|
|
|
{ |
|
83
|
|
|
$this->markTestSkipped('Breaks testsuite'); |
|
84
|
|
|
|
|
85
|
|
|
/** @phpstan-ignore deadCode.unreachable */ |
|
86
|
|
|
$_SERVER['REQUEST_URI'] = '/module.php/webauthn/registration'; |
|
87
|
|
|
$request = Request::create( |
|
88
|
|
|
'/registration', |
|
89
|
|
|
'GET', |
|
90
|
|
|
['StateId' => 'someStateId'], |
|
91
|
|
|
); |
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
$c = new Controller\Registration($this->config, $this->session); |
|
95
|
|
|
$c->setLogger($this->logger); |
|
96
|
|
|
|
|
97
|
|
|
$c->setAuthSimple(new class ('default-sp') extends Auth\Simple { |
|
98
|
|
|
public function requireAuth(array $params = []): void |
|
99
|
|
|
{ |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
public function getAttributes(): array |
|
104
|
|
|
{ |
|
105
|
|
|
return ['uid' => ['dduck'], 'displayName' => ['Donald Duck']]; |
|
106
|
|
|
} |
|
107
|
|
|
}); |
|
108
|
|
|
|
|
109
|
|
|
$c->setAuthState(new class () extends Auth\State { |
|
110
|
|
|
public static function loadState(string $id, string $stage, bool $allowMissing = false): ?array |
|
111
|
|
|
{ |
|
112
|
|
|
return [ |
|
113
|
|
|
]; |
|
114
|
|
|
} |
|
115
|
|
|
}); |
|
116
|
|
|
|
|
117
|
|
|
$response = $c->main($request); |
|
118
|
|
|
|
|
119
|
|
|
$this->assertTrue($response->isSuccessful()); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|