Passed
Pull Request — master (#31)
by Tim
09:39
created

nTest.php$1   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
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\Session */
30
    protected $session;
31
32
33
    /**
34
     * Set up for each test.
35
     * @return void
36
     */
37
    protected function setUp(): void
38
    {
39
        parent::setUp();
40
41
        $this->config = Configuration::loadFromArray(
42
            [
43
                'module.enable' => ['webauthn' => true],
44
                'secretsalt' => 'abc123',
45
                'enable.saml20-idp' => true,
46
            ],
47
            '[ARRAY]',
48
            'simplesaml'
49
        );
50
51
        Configuration::setPreLoadedConfig(
52
            Configuration::loadFromArray(
53
                [
54
                    'attrib_username' => 'uid',
55
                    'attrib_displayname' => 'displayName',
56
                    'store' => [
57
                        'webauthn:Database',
58
                        'database.dsn' => 'mysql:host=db.example.org;dbname=fido2',
59
                        'database.username' => 'simplesaml',
60
                        'database.password' => 'sdfsdf',
61
                    ],
62
                ],
63
                '[ARRAY]',
64
                'simplesaml'
65
            ),
66
            'module_webauthn.php',
67
            'simplesaml'
68
        );
69
70
        $this->session = Session::getSessionFromRequest();
71
72
        $this->logger = new class () extends Logger {
73
            public static function info(string $str): void
74
            {
75
                // do nothing
76
            }
77
        };
78
    }
79
80
81
    /**
82
     * @return void
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->setAuthSimple(new class ('something') extends Auth\Simple {
98
            public function __construct(string $authSource, Configuration $config = null, Session $session = null) {
99
            }
100
            public function requireAuth(array $params = []): void {
101
            }
102
            public function getAttributes(): array {
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