Skip to content

Commit

Permalink
Add unit tests against string truncation
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Feb 5, 2018
1 parent 20130f4 commit 2afa0bb
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion tests/Base64UrlSafeTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
<?php
use \ParagonIE\ConstantTime\Base64UrlSafe;

use ParagonIE\ConstantTime\Base64UrlSafe;
use ParagonIE\ConstantTime\Binary;

/**
* Class Base64UrlSafeTest
*/
class Base64UrlSafeTest extends PHPUnit\Framework\TestCase
{
/**
* @covers Base64UrlSafe::encode()
* @covers Base64UrlSafe::decode()
*
* @throws Exception
* @throws TypeError
*/
public function testRandom()
{
Expand Down Expand Up @@ -34,5 +42,17 @@ public function testRandom()
);
}
}

$random = \random_bytes(1 << 20);
$enc = Base64UrlSafe::encode($random);
$this->assertTrue(Binary::safeStrlen($enc) > 65536);
$this->assertSame(
$random,
Base64UrlSafe::decode($enc)
);
$this->assertSame(
\strtr(\base64_encode($random), '+/', '-_'),
$enc
);
}
}

0 comments on commit 2afa0bb

Please sign in to comment.