File: SignRequestTest.php

package info (click to toggle)
php-code-lts-u2f-php-server 1.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 208 kB
  • sloc: php: 979; xml: 51; makefile: 7
file content (47 lines) | stat: -rw-r--r-- 1,704 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

declare(strict_types = 1);

namespace CodeLts\U2F\U2FServer\Tests;

use CodeLts\U2F\U2FServer\SignRequest;
use PHPUnit\Framework\TestCase;

class SignRequestTest extends TestCase
{
    // Source: https://github.com/Yubico/php-u2flib-server/blob/55d813acf68212ad2cadecde07551600d6971939/tests/u2flib_test.php#L200
    // Data copyright: https://github.com/Yubico/php-u2flib-server/blob/55d813acf68212ad2cadecde07551600d6971939/tests/u2flib_test.php#L3
    private $keyHandle = 'CTUayZo8hCBeC-sGQJChC0wW-bBg99bmOlGCgw8XGq4dLsxO3yWh9mRYArZxocP5hBB1pEGB3bbJYiM-5acc5w';

    public function testGetters(): void
    {
        $sr = new SignRequest(
            [
            'challenge' => 'fEnc9oV79EaBgK5BoNERU5gPKM2XGYWrz4fUjgc0000',
            'keyHandle' => $this->keyHandle,
            'appId' => 'http://demo.example.com',
            ]
        );
        $this->assertSame('http://demo.example.com', $sr->appId());
        $this->assertSame('fEnc9oV79EaBgK5BoNERU5gPKM2XGYWrz4fUjgc0000', $sr->challenge());
        $this->assertSame('U2F_V2', $sr->version());
    }

    public function testToJson(): void
    {
        $sr = new SignRequest(
            [
            'challenge' => 'fEnc9oV79EaBgK5BoNERU5gPKM2XGYWrz4fUjgc0000',
            'keyHandle' => $this->keyHandle,
            'appId' => 'http://demo.example.com',
            ]
        );
        $this->assertSame(
            '{"version":"U2F_V2","challenge":"fEnc9oV79EaBgK5BoNERU5gPKM2XGYWrz4fUjgc0000",'
            . '"keyHandle":"CTUayZo8hCBeC-sGQJChC0wW-bBg99bmOlGCgw8XGq4dLsxO3yWh9mRYArZxocP5hBB1pEGB3bbJYiM-5acc5w",'
            . '"appId":"http:\/\/demo.example.com"}',
            json_encode($sr)
        );
    }

}