Passed
Pull Request — master (#31)
by Tim
02:05
created

RegistrationTest.php$0 ➔ setUp()   A

Complexity

Conditions 1

Size

Total Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 38
rs 9.312
cc 1

1 Method

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