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

ntroller/RegProcessTest.php$0   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 3
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
wmc 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\State;
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 RegProcessTest 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
        $this->session = Session::getSessionFromRequest();
53
54
        $this->logger = new class () extends Logger {
55
            public static function info(string $str): void
56
            {
57
                // do nothing
58
            }
59
        };
60
    }
61
62
63
    /**
64
     */
65
    public function testRegProcess(): void
66
    {
67
        $this->markTestSkipped('Breaks testsuite');
68
69
        $_SERVER['REQUEST_URI'] = '/module.php/webauthn/regprocess';
70
        $request = Request::create(
71
            '/regprocess',
72
            'POST',
73
            [
74
                'StateId' => 'someStateId',
75
                'attestation_object' => 'some object',
76
                'type' => 'public-key',
77
                'response_id' => 'abc123',
78
                'attestation_client_data_json' => 'test',
79
            ]
80
        );
81
82
83
        $c = new Controller\RegProcess($this->config, $this->session);
84
        $c->setLogger($this->logger);
85
        $c->setAuthState(new class () extends State {
86
            public static function loadState(string $id, string $stage, bool $allowMissing = false): ?array
87
            {
88
                return [
89
                    'FIDO2Scope' => 'Ducktown',
90
                    'FIDO2Tokens' => [0 => 'A1B2C3', 1 => 'D4E5F6'],
91
                    'FIDO2SignupChallenge' => 'abc123',
92
                    'FIDO2AuthSuccessful' => true,
93
                    'IdPMetadata' => [
94
                        'entityid' => 'https://idp.example.com',
95
                    ],
96
                ];
97
            }
98
        });
99
100
        $response = $c->main($request);
101
102
        $this->assertTrue($response->isSuccessful());
103
    }
104
}
105