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

/AuthProcessTest.php$0   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 3
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
dl 0
loc 3
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\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\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 AuthProcessTest 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
        $this->session = Session::getSessionFromRequest();
52
53
        $this->logger = new class () extends Logger {
54
            public static function info(string $str): void
55
            {
56
                // do nothing
57
            }
58
        };
59
    }
60
61
62
    /**
63
     * @return void
64
     */
65
    public function testAuthProcess(): void
66
    {
67
        $_SERVER['REQUEST_URI'] = '/module.php/webauthn/authprocess';
68
        $request = Request::create(
69
            '/authprocess',
70
            'GET',
71
            ['StateId' => 'someStateId']
72
        );
73
74
75
        $c = new Controller\WebAuthn($this->config, $this->session);
76
        $c->setAuthState(new class () extends State {
77
            public static function loadState(string $id, string $stage, bool $allowMissing = false): ?array
78
            {
79
                return [
80
                    'FIDO2Displayname' => 'Donald Duck',
81
                    'FIDO2Username' => 'dduck',
82
                    'FIDO2Scope' => 'Ducktown',
83
                    'FIDO2Tokens' => [],
84
                    'FIDO2SignupChallenge' => 'abc123',
85
                    'FIDO2AuthSuccessful' => true,
86
                    'requestTokenModel' => 'something',
87
                    'Source' => [
88
                        'entityid' => 'https://idp.example.com',
89
                    ],
90
                ];
91
            }
92
        });
93
94
        $response = $c->main($request);
95
96
        $this->assertTrue($response->isSuccessful());
97
    }
98
}
99