Passed
Push — master ( 3900ea...e2f039 )
by Tim
08:09
created

WebAuthnTest.php$0 ➔ info()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
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\Error;
11
use SimpleSAML\HTTP\RunnableResponse;
12
use SimpleSAML\Logger;
13
use SimpleSAML\Module\webauthn\Controller;
14
use SimpleSAML\Session;
15
use SimpleSAML\XHTML\Template;
16
use Symfony\Component\HttpFoundation\Request;
17
18
/**
19
 * Set of tests for the controllers in the "webauthn" module.
20
 *
21
 * @package SimpleSAML\Test
22
 */
23
class WebAuthnTest extends TestCase
24
{
25
    /** @var \SimpleSAML\Configuration */
26
    protected $config;
27
28
    /** @var \SimpleSAML\Logger */
29
    protected $logger;
30
31
    /** @var \SimpleSAML\Session */
32
    protected $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->session = Session::getSessionFromRequest();
53
54
        $this->logger = new class () extends Logger {
55
            public static function info(string $str): void
56
            {
57
                // do nothing
58
            }
59
        };
60
    }
61
62
63
    /**
64
     */
65
    public function testWebAuthn(): void
66
    {
67
        $_SERVER['REQUEST_URI'] = '/module.php/webauthn/webauthn';
68
        $request = Request::create(
69
            '/webauthn',
70
            'POST',
71
            ['StateId' => 'someStateId']
72
        );
73
74
75
        $c = new Controller\WebAuthn($this->config, $this->session);
76
        $c->setLogger($this->logger);
77
        $c->setAuthState(new class () extends State {
78
            public static function loadState(string $id, string $stage, bool $allowMissing = false): ?array
79
            {
80
                return [
81
                    'FIDO2Displayname' => 'Donald Duck',
82
                    'FIDO2Username' => 'dduck',
83
                    'FIDO2Scope' => 'Ducktown',
84
                    'FIDO2Tokens' => [0 => 'A1B2C3', 1 => 'D4E5F6'],
85
                    'FIDO2SignupChallenge' => 'A1B2C3',
86
                    'FIDO2WantsRegister' => false,
87
                    'FIDO2AuthSuccessful' => false,
88
                    'requestTokenModel' => 'something',
89
                    'Source' => [
90
                        'entityid' => 'https://idp.example.com',
91
                    ],
92
                ];
93
            }
94
        });
95
96
        $response = $c->main($request);
97
98
        $this->assertTrue($response->isSuccessful());
99
    }
100
}
101