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 RegProcessTest 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
|
|
|
$this->session = Session::getSessionFromRequest(); |
50
|
|
|
|
51
|
|
|
$this->logger = new class () extends Logger { |
52
|
|
|
public static function info(string $string): void |
53
|
|
|
{ |
54
|
|
|
// do nothing |
55
|
|
|
} |
56
|
|
|
}; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
*/ |
62
|
|
|
public function testRegProcess(): void |
63
|
|
|
{ |
64
|
|
|
$this->markTestSkipped('Breaks testsuite'); |
65
|
|
|
|
66
|
|
|
/** @phpstan-ignore deadCode.unreachable */ |
67
|
|
|
$_SERVER['REQUEST_URI'] = '/module.php/webauthn/regprocess'; |
68
|
|
|
$request = Request::create( |
69
|
|
|
'/regprocess', |
70
|
|
|
'POST', |
71
|
|
|
[ |
72
|
|
|
'StateId' => 'someStateId', |
73
|
|
|
'attestation_object' => 'some object', |
74
|
|
|
'type' => 'public-key', |
75
|
|
|
'response_id' => 'abc123', |
76
|
|
|
'attestation_client_data_json' => 'test', |
77
|
|
|
], |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
$c = new Controller\RegProcess($this->config, $this->session); |
82
|
|
|
$c->setLogger($this->logger); |
83
|
|
|
$c->setAuthState(new class () extends State { |
84
|
|
|
public static function loadState(string $id, string $stage, bool $allowMissing = false): ?array |
85
|
|
|
{ |
86
|
|
|
return [ |
87
|
|
|
'FIDO2Scope' => 'Ducktown', |
88
|
|
|
'FIDO2Tokens' => [0 => 'A1B2C3', 1 => 'D4E5F6'], |
89
|
|
|
'FIDO2SignupChallenge' => 'abc123', |
90
|
|
|
'FIDO2AuthSuccessful' => true, |
91
|
|
|
]; |
92
|
|
|
} |
93
|
|
|
}); |
94
|
|
|
|
95
|
|
|
$response = $c->main($request); |
96
|
|
|
|
97
|
|
|
$this->assertTrue($response->isSuccessful()); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|