Skip to content

Commit 1cd9c27

Browse files
committed
tests: add new tests for SignRequest and RegistrationRequest
Trying to cover: Samyoul#10
1 parent dcdc4e9 commit 1cd9c27

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

test/RegistrationRequestTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace CodeLts\U2F\U2FServer\Tests;
4+
5+
use CodeLts\U2F\U2FServer\RegistrationRequest;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class RegistrationRequestTest extends TestCase
9+
{
10+
public function testGetters(): void
11+
{
12+
$rr = new RegistrationRequest('yKA0x075tjJ-GE7fKTfnzTOSaNUOWQxRd9TWz5aFOg8', 'http://demo.example.com');
13+
$this->assertSame('http://demo.example.com', $rr->appId());
14+
$this->assertSame('yKA0x075tjJ-GE7fKTfnzTOSaNUOWQxRd9TWz5aFOg8', $rr->challenge());
15+
$this->assertSame('U2F_V2', $rr->version());
16+
}
17+
18+
public function testToJson(): void
19+
{
20+
$rr = new RegistrationRequest('yKA0x075tjJ-GE7fKTfnzTOSaNUOWQxRd9TWz5aFOg8', 'http://demo.example.com');
21+
$this->assertSame(
22+
'{"version":"U2F_V2","challenge":"yKA0x075tjJ-GE7fKTfnzTOSaNUOWQxRd9TWz5aFOg8","appId":"http:\/\/demo.example.com"}',
23+
json_encode($rr)
24+
);
25+
}
26+
}

test/SignRequestTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace CodeLts\U2F\U2FServer\Tests;
4+
5+
use CodeLts\U2F\U2FServer\SignRequest;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class SignRequestTest extends TestCase
9+
{
10+
// Source: https://github.com/Yubico/php-u2flib-server/blob/55d813acf68212ad2cadecde07551600d6971939/tests/u2flib_test.php#L200
11+
// Data copyright: https://github.com/Yubico/php-u2flib-server/blob/55d813acf68212ad2cadecde07551600d6971939/tests/u2flib_test.php#L3
12+
private $keyHandle = 'CTUayZo8hCBeC-sGQJChC0wW-bBg99bmOlGCgw8XGq4dLsxO3yWh9mRYArZxocP5hBB1pEGB3bbJYiM-5acc5w';
13+
14+
public function testGetters(): void
15+
{
16+
$sr = new SignRequest([
17+
'challenge' => 'fEnc9oV79EaBgK5BoNERU5gPKM2XGYWrz4fUjgc0000',
18+
'keyHandle' => $this->keyHandle,
19+
'appId' => 'http://demo.example.com',
20+
]);
21+
$this->assertSame('http://demo.example.com', $sr->appId());
22+
$this->assertSame('fEnc9oV79EaBgK5BoNERU5gPKM2XGYWrz4fUjgc0000', $sr->challenge());
23+
$this->assertSame('U2F_V2', $sr->version());
24+
}
25+
26+
public function testToJson(): void
27+
{
28+
$sr = new SignRequest([
29+
'challenge' => 'fEnc9oV79EaBgK5BoNERU5gPKM2XGYWrz4fUjgc0000',
30+
'keyHandle' => $this->keyHandle,
31+
'appId' => 'http://demo.example.com',
32+
]);
33+
$this->assertSame(
34+
'{"version":"U2F_V2","challenge":"fEnc9oV79EaBgK5BoNERU5gPKM2XGYWrz4fUjgc0000",'
35+
. '"keyHandle":"CTUayZo8hCBeC-sGQJChC0wW-bBg99bmOlGCgw8XGq4dLsxO3yWh9mRYArZxocP5hBB1pEGB3bbJYiM-5acc5w",'
36+
. '"appId":"http:\/\/demo.example.com"}',
37+
json_encode($sr)
38+
);
39+
}
40+
}

0 commit comments

Comments
 (0)