Passed
Push — master ( 6523ae...53286a )
by Stefan
07:26
created

AuthProcessTest.php$0 ➔ setUp()   A

Complexity

Conditions 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 19
rs 9.6333
cc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A AuthProcessTest.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 Exception;
8
use PHPUnit\Framework\TestCase;
9
use SimpleSAML\Auth\State;
10
use SimpleSAML\Configuration;
11
use SimpleSAML\Error;
12
use SimpleSAML\HTTP\RunnableResponse;
13
use SimpleSAML\Logger;
14
use SimpleSAML\Module\webauthn\Controller;
15
use SimpleSAML\Session;
16
use SimpleSAML\Utils;
17
use SimpleSAML\XHTML\Template;
18
use Symfony\Component\HttpFoundation\Request;
19
20
/**
21
 * Set of tests for the controllers in the "webauthn" module.
22
 *
23
 * @package SimpleSAML\Test
24
 */
25
class AuthProcessTest extends TestCase
26
{
27
    /** @var \SimpleSAML\Configuration */
28
    protected $config;
29
30
    /** @var \SimpleSAML\Logger */
31
    protected $logger;
32
33
    /** @var \SimpleSAML\Session */
34
    protected $session;
35
36
37
    /**
38
     * Set up for each test.
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
        $this->session = Session::getSessionFromRequest();
55
56
        $this->logger = new class () extends Logger {
57
            public static function info($str)
58
            {
59
                // do nothing
60
            }
61
        };
62
    }
63
64
65
    /**
66
     */
67
    public function testAuthProcessWithoutProperTokenRaisesException(): void
68
    {
69
        $_SERVER['REQUEST_URI'] = '/module.php/webauthn/authprocess?StateId=someStateId';
70
        $request = Request::create(
71
            '/authprocess?StateId=someStateId',
72
            'POST',
73
            ['response_id' => 'abc123']
74
        );
75
76
77
        $c = new Controller\AuthProcess($this->config, $this->session);
78
        $c->setLogger($this->logger);
79
        $c->setAuthState(new class () extends State {
80
            public static function loadState($id, $stage, $allowMissing = false)
81
            {
82
                return [
83
                    'FIDO2Displayname' => 'Donald Duck',
84
                    'FIDO2Username' => 'dduck',
85
                    'FIDO2Scope' => 'Ducktown',
86
                    'FIDO2Tokens' => [],
87
                    'FIDO2SignupChallenge' => 'abc123',
88
                    'FIDO2AuthSuccessful' => true,
89
                    'requestTokenModel' => 'something',
90
                    'Source' => [
91
                        'entityid' => 'https://idp.example.com',
92
                    ],
93
                ];
94
            }
95
        });
96
97
        $this->expectException(Exception::class);
98
        $this->expectExceptionMessage(
99
            "User attempted to authenticate with an unknown credential ID. This should already have been prevented by the browser!"
100
        );
101
        $c->main($request);
102
    }
103
}
104