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

nTest.php$1   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
dl 0
loc 7
rs 10
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\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 RegistrationTest 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
        Configuration::setPreLoadedConfig(
54
            Configuration::loadFromArray(
55
                [
56
                    'attrib_username' => 'uid',
57
                    'attrib_displayname' => 'displayName',
58
                    'store' => [
59
                        'webauthn:Database',
60
                        'database.dsn' => 'mysql:host=db.example.org;dbname=fido2',
61
                        'database.username' => 'simplesaml',
62
                        'database.password' => 'sdfsdf',
63
                    ],
64
                ],
65
                '[ARRAY]',
66
                'simplesaml'
67
            ),
68
            'module_webauthn.php',
69
            'simplesaml'
70
        );
71
72
        $this->session = Session::getSessionFromRequest();
73
74
        $this->logger = new class () extends Logger {
75
            public static function info($str)
76
            {
77
                // do nothing
78
            }
79
        };
80
    }
81
82
83
    /**
84
     */
85
    public function testRegistration(): void
86
    {
87
        $this->markTestSkipped('Breaks testsuite');
88
89
        $_SERVER['REQUEST_URI'] = '/module.php/webauthn/registration';
90
        $request = Request::create(
91
            '/registration',
92
            'GET',
93
            ['StateId' => 'someStateId']
94
        );
95
96
97
        $c = new Controller\Registration($this->config, $this->session);
98
        $c->setLogger($this->logger);
99
100
        $c->setAuthSimple(new class ('default-sp') extends Auth\Simple {
101
            public function requireAuth(array $params = []): void
102
            {
103
            }
104
            public function getAttributes(): array
105
            {
106
                return ['uid' => ['dduck'], 'displayName' => ['Donald Duck']];
107
            }
108
        });
109
110
        $c->setAuthState(new class () extends Auth\State {
111
            public static function loadState($id, $stage, $allowMissing = false)
112
            {
113
                return [
114
                ];
115
            }
116
        });
117
118
        $response = $c->main($request);
119
120
        $this->assertTrue($response->isSuccessful());
121
    }
122
}
123