|
| 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