Core Update 1.4.0
This commit is contained in:
@@ -140,4 +140,33 @@ class AesStreamTest extends PHPUnit\Framework\TestCase {
|
||||
$inputData = random_bytes($inputSize);
|
||||
$this->testEncryptDecrypt($key, $iv, $inputData);
|
||||
}
|
||||
|
||||
public function testEncryptDecryptPartial() {
|
||||
$key = random_bytes(32);
|
||||
$iv = hex2bin(str_repeat("00", 16));
|
||||
$chunkSize = 65536;
|
||||
|
||||
$ranges = [[500,100,200],[10*$chunkSize,100,5*$chunkSize+100],[10*$chunkSize,0,10*$chunkSize],[10*$chunkSize,$chunkSize-1,3*$chunkSize-1]];
|
||||
foreach ($ranges as $range) {
|
||||
list ($total, $offset, $length) = $range;
|
||||
$inputData = random_bytes($total);
|
||||
file_put_contents(AesStreamTest::$TEMP_FILE, $inputData);
|
||||
|
||||
$output = "";
|
||||
$aesStream = new AesStream($key, $iv);
|
||||
$aesStream->setRange($offset, $length);
|
||||
$aesStream->setInputFile(AesStreamTest::$TEMP_FILE);
|
||||
$aesStream->setOutput(function($chunk) use (&$output) { $this->getOutput($chunk, $output); });
|
||||
$aesStream->start();
|
||||
|
||||
$outputComplete = "";
|
||||
$aesStream = new AesStream($key, $iv);
|
||||
$aesStream->setInputFile(AesStreamTest::$TEMP_FILE);
|
||||
$aesStream->setOutput(function($chunk) use (&$outputComplete) { $this->getOutput($chunk, $outputComplete); });
|
||||
$aesStream->start();
|
||||
|
||||
$this->assertEquals($length, strlen($output), "total=$total offset=$offset length=$length");
|
||||
$this->assertEquals(substr($outputComplete, $offset, $length), $output, "total=$total offset=$offset length=$length");
|
||||
}
|
||||
}
|
||||
}
|
||||
43
test/TimeBasedTwoFactorToken.test.php
Normal file
43
test/TimeBasedTwoFactorToken.test.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Base32\Base32;
|
||||
use Configuration\Configuration;
|
||||
use Objects\TwoFactor\TimeBasedTwoFactorToken;
|
||||
use Objects\User;
|
||||
|
||||
class TimeBasedTwoFactorTokenTest extends PHPUnit\Framework\TestCase {
|
||||
|
||||
// https://tools.ietf.org/html/rfc6238
|
||||
public function testTOTP() {
|
||||
$secret = Base32::encode("12345678901234567890");
|
||||
$token = new TimeBasedTwoFactorToken($secret);
|
||||
|
||||
$totp_tests = [
|
||||
59 => '94287082',
|
||||
1111111109 => '07081804',
|
||||
1111111111 => '14050471',
|
||||
1234567890 => '89005924',
|
||||
2000000000 => '69279037',
|
||||
20000000000 => '65353130',
|
||||
];
|
||||
|
||||
$period = 30;
|
||||
$totp_length = 8;
|
||||
foreach ($totp_tests as $seed => $code) {
|
||||
$generated = $token->generate($seed, $totp_length, $period);
|
||||
$this->assertEquals($code, $generated, "$code != $generated, at=$seed");
|
||||
}
|
||||
}
|
||||
|
||||
public function testURL() {
|
||||
$secret = Base32::encode("12345678901234567890");
|
||||
$configuration = new Configuration();
|
||||
$user = new User($configuration);
|
||||
|
||||
$token = new TimeBasedTwoFactorToken($secret);
|
||||
$siteName = $configuration->getSettings()->getSiteName();
|
||||
$username = $user->getUsername();
|
||||
$url = $token->getUrl($user);
|
||||
$this->assertEquals("otpauth://totp/$username?secret=$secret&issuer=$siteName", $url);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user