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

RegistrationTest.php$1 ➔ requireAuth()   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;
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 RegistrationTest 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
        Configuration::setPreLoadedConfig(
53
            Configuration::loadFromArray(
54
                [
55
                    'attrib_username' => 'uid',
56
                    'attrib_displayname' => 'displayName',
57
                    'store' => [
58
                        'webauthn:Database',
59
                        'database.dsn' => 'mysql:host=db.example.org;dbname=fido2',
60
                        'database.username' => 'simplesaml',
61
                        'database.password' => 'sdfsdf',
62
                    ],
63
                ],
64
                '[ARRAY]',
65
                'simplesaml'
66
            ),
67
            'module_webauthn.php',
68
            'simplesaml'
69
        );
70
71
        $this->session = Session::getSessionFromRequest();
72
73
        $this->logger = new class () extends Logger {
74
            public static function info(string $str): void
75
            {
76
                // do nothing
77
            }
78
        };
79
    }
80
81
82
    /**
83
     */
84
    public function testRegistration(): void
85
    {
86
        $this->markTestSkipped('Breaks testsuite');
87
88
        $_SERVER['REQUEST_URI'] = '/module.php/webauthn/registration';
89
        $request = Request::create(
90
            '/registration',
91
            'GET',
92
            ['StateId' => 'someStateId']
93
        );
94
95
96
        $c = new Controller\Registration($this->config, $this->session);
97
        $c->setLogger($this->logger);
98
99
        $c->setAuthSimple(new class ('default-sp') extends Auth\Simple {
100
            public function requireAuth(array $params = []): void
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