Passed
Push — master ( 6523ae...53286a )
by Stefan
07:26
created

WebAuthnTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 34
c 2
b 0
f 0
dl 0
loc 77
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ setUp() 0 19 1
setUp() 0 19 ?
A hp$0 ➔ info() 0 2 1
A hp$1 ➔ loadState() 0 14 1
testWebAuthn() 0 35 ?
A hp$1 ➔ testWebAuthn() 0 35 1
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\Utils;
16
use SimpleSAML\XHTML\Template;
17
use Symfony\Component\HttpFoundation\Request;
18
19
/**
20
 * Set of tests for the controllers in the "webauthn" module.
21
 *
22
 * @package SimpleSAML\Test
23
 */
24
class WebAuthnTest extends TestCase
25
{
26
    /** @var \SimpleSAML\Configuration */
27
    protected $config;
28
29
    /** @var \SimpleSAML\Logger */
30
    protected $logger;
31
32
    /** @var \SimpleSAML\Session */
33
    protected $session;
34
35
36
    /**
37
     * Set up for each test.
38
     */
39
    protected function setUp(): void
40
    {
41
        parent::setUp();
42
43
        $this->config = Configuration::loadFromArray(
44
            [
45
                'module.enable' => ['webauthn' => true],
46
                'secretsalt' => 'abc123',
47
                'enable.saml20-idp' => true,
48
            ],
49
            '[ARRAY]',
50
            'simplesaml'
51
        );
52
53
        $this->session = Session::getSessionFromRequest();
54
55
        $this->logger = new class () extends Logger {
56
            public static function info($str)
57
            {
58
                // do nothing
59
            }
60
        };
61
    }
62
63
64
    /**
65
     */
66
    public function testWebAuthn(): void
67
    {
68
        $_SERVER['REQUEST_URI'] = '/module.php/webauthn/webauthn';
69
        $request = Request::create(
70
            '/webauthn?StateId=someStateId',
71
            'POST',
72
            []
73
        );
74
75
76
        $c = new Controller\WebAuthn($this->config, $this->session);
77
        $c->setLogger($this->logger);
78
        $c->setAuthState(new class () extends State {
79
            public static function loadState($id, $stage, $allowMissing = false)
80
            {
81
                return [
82
                    'UseInflowRegistration' => true,
83
                    'FIDO2Displayname' => 'Donald Duck',
84
                    'FIDO2Username' => 'dduck',
85
                    'FIDO2Scope' => 'Ducktown',
86
                    'FIDO2Tokens' => [0 => 'A1B2C3', 1 => 'D4E5F6'],
87
                    'FIDO2SignupChallenge' => 'A1B2C3',
88
                    'FIDO2WantsRegister' => false,
89
                    'FIDO2AuthSuccessful' => false,
90
                    'requestTokenModel' => 'something',
91
                    'Source' => [
92
                        'entityid' => 'https://idp.example.com',
93
                    ],
94
                ];
95
            }
96
        });
97
98
        $response = $c->main($request);
99
100
        $this->assertTrue($response->isSuccessful());
101
    }
102
}
103