|
4 | 4 | use Gt\Cipher\EncryptedUri; |
5 | 5 | use Gt\Cipher\InitVector; |
6 | 6 | use Gt\Cipher\Key; |
7 | | -use Gt\Cipher\Message\DecryptionFailureException; |
8 | 7 | use Gt\Cipher\MissingQueryStringException; |
| 8 | +use Gt\Cipher\UriDecryptionFailureException; |
9 | 9 | use PHPUnit\Framework\TestCase; |
10 | 10 |
|
11 | 11 | class EncryptedUriTest extends TestCase { |
@@ -38,19 +38,38 @@ public function testConstruct_missingCipherValue():void { |
38 | 38 | } |
39 | 39 |
|
40 | 40 | public function testDecryptMessage_error():void { |
41 | | - $ivString = base64_encode(str_repeat("0", SODIUM_CRYPTO_SECRETBOX_NONCEBYTES)); |
| 41 | + $ivString = base64_encode( |
| 42 | + str_repeat("0", SODIUM_CRYPTO_SECRETBOX_NONCEBYTES) |
| 43 | + ); |
42 | 44 | $uri = "https://example.com/test/?cipher=0000&iv=$ivString"; |
43 | 45 | $sut = new EncryptedUri($uri); |
44 | 46 |
|
45 | 47 | $key = self::createMock(Key::class); |
46 | 48 | $key->method("getBytes") |
47 | 49 | ->willReturn(str_repeat("0", SODIUM_CRYPTO_SECRETBOX_KEYBYTES)); |
48 | | - self::expectException(DecryptionFailureException::class); |
| 50 | + self::expectException(UriDecryptionFailureException::class); |
| 51 | + $sut->decryptMessage($key); |
| 52 | + } |
| 53 | + |
| 54 | + public function testDecryptMessage_wrapsSodiumFailure():void { |
| 55 | + $ivString = base64_encode( |
| 56 | + str_repeat("0", SODIUM_CRYPTO_SECRETBOX_NONCEBYTES) |
| 57 | + ); |
| 58 | + $uri = "https://example.com/test/?cipher=0000&iv=$ivString"; |
| 59 | + $sut = new EncryptedUri($uri); |
| 60 | + |
| 61 | + $key = self::createMock(Key::class); |
| 62 | + $key->method("getBytes") |
| 63 | + ->willReturn("bad"); |
| 64 | + |
| 65 | + self::expectException(UriDecryptionFailureException::class); |
49 | 66 | $sut->decryptMessage($key); |
50 | 67 | } |
51 | 68 |
|
52 | 69 | public function testDecryptMessage():void { |
53 | | - $uri = "https://example.com/?cipher=lmEClve%2FuhmK32ghM0%2BA%2FI%2Btysm00AL37YD6eg%3D%3D&iv=UVunn3laPVnK4CfHZuS2AnvJ1KfsPM1r"; |
| 70 | + $uri = "https://example.com/" |
| 71 | + . "?cipher=lmEClve%2FuhmK32ghM0%2BA%2FI%2Btysm00AL37YD6eg%3D%3D" |
| 72 | + . "&iv=UVunn3laPVnK4CfHZuS2AnvJ1KfsPM1r"; |
54 | 73 | $sut = new EncryptedUri($uri); |
55 | 74 |
|
56 | 75 | $key = self::createMock(Key::class); |
|
0 commit comments