RegistrationTest::testRegistration()
last analyzed

Size

Total Lines 37
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
nc 1
nop 0
dl 0
loc 37
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A RegistrationTest.php$2 ➔ loadState() 0 3 1
A RegistrationTest.php$1 ➔ requireAuth() 0 2 1
A RegistrationTest.php$1 ➔ getAttributes() 0 3 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;
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
            public function getAttributes(): array
102
            {
103
                return ['uid' => ['dduck'], 'displayName' => ['Donald Duck']];
104
            }
105
        });
106
107
        $c->setAuthState(new class () extends Auth\State {
108
            public static function loadState(string $id, string $stage, bool $allowMissing = false): ?array
109
            {
110
                return [
111
                ];
112
            }
113
        });
114
115
        $response = $c->main($request);
116
117
        $this->assertTrue($response->isSuccessful());
118
    }
119
}
120