Completed
Push — master ( bab30e...5d9c47 )
by Stefan
18s queued 14s
created

RegistrationTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 2
eloc 40
c 4
b 1
f 0
dl 0
loc 99
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ info() 0 2 1
setUp() 0 38 ?
A hp$0 ➔ setUp() 0 38 1
A hp$1 ➔ getAttributes() 0 3 1
A hp$2 ➔ loadState() 0 3 1
testRegistration() 0 36 ?
A hp$1 ➔ requireAuth() 0 2 1
A hp$2 ➔ testRegistration() 0 36 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\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
     * @return void
39
     */
40
    protected function setUp(): void
41
    {
42
        parent::setUp();
43
44
        $this->config = Configuration::loadFromArray(
45
            [
46
                'module.enable' => ['webauthn' => true],
47
                'secretsalt' => 'abc123',
48
                'enable.saml20-idp' => true,
49
            ],
50
            '[ARRAY]',
51
            'simplesaml'
52
        );
53
54
        Configuration::setPreLoadedConfig(
55
            Configuration::loadFromArray(
56
                [
57
                    'attrib_username' => 'uid',
58
                    'attrib_displayname' => 'displayName',
59
                    'store' => [
60
                        'webauthn:Database',
61
                        'database.dsn' => 'mysql:host=db.example.org;dbname=fido2',
62
                        'database.username' => 'simplesaml',
63
                        'database.password' => 'sdfsdf',
64
                    ],
65
                ],
66
                '[ARRAY]',
67
                'simplesaml'
68
            ),
69
            'module_webauthn.php',
70
            'simplesaml'
71
        );
72
73
        $this->session = Session::getSessionFromRequest();
74
75
        $this->logger = new class () extends Logger {
76
            public static function info(string $str): void
77
            {
78
                // do nothing
79
            }
80
        };
81
    }
82
83
84
    /**
85
     * @return void
86
     */
87
    public function testRegistration(): void
88
    {
89
        $this->markTestSkipped('Breaks testsuite');
90
91
        $_SERVER['REQUEST_URI'] = '/module.php/webauthn/registration';
92
        $request = Request::create(
93
            '/registration',
94
            'GET',
95
            ['StateId' => 'someStateId']
96
        );
97
98
99
        $c = new Controller\Registration($this->config, $this->session);
100
        $c->setLogger($this->logger);
101
102
        $c->setAuthSimple(new class ('default-sp') extends Auth\Simple {
103
            public function requireAuth(array $params = []): void
104
            {
105
            }
106
            public function getAttributes(): array
107
            {
108
                return ['uid' => ['dduck'], 'displayName' => ['Donald Duck']];
109
            }
110
        });
111
112
        $c->setAuthState(new class () extends Auth\State {
113
            public static function loadState(string $id, string $stage, bool $allowMissing = false): ?array
114
            {
115
                return [
116
                ];
117
            }
118
        });
119
120
        $response = $c->main($request);
121
122
        $this->assertTrue($response->isSuccessful());
123
    }
124
}
125