Differential D8875 Diff 21076 src/applications/auth/factor/__tests__/PhabricatorAuthFactorTOTPTestCase.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/factor/__tests__/PhabricatorAuthFactorTOTPTestCase.php
- This file was added.
<?php | |||||
final class PhabricatorAuthFactorTOTPTestCase extends PhabricatorTestCase { | |||||
public function testTOTPCodeGeneration() { | |||||
$tests = array( | |||||
array( | |||||
'AAAABBBBCCCCDDDD', | |||||
46620383, | |||||
'724492', | |||||
), | |||||
array( | |||||
'AAAABBBBCCCCDDDD', | |||||
46620390, | |||||
'935803', | |||||
), | |||||
array( | |||||
'Z3RFWEFJN233R23P', | |||||
46620398, | |||||
'273030', | |||||
), | |||||
// This is testing the case where the code has leading zeroes. | |||||
array( | |||||
'Z3RFWEFJN233R23W', | |||||
46620399, | |||||
'072346', | |||||
), | |||||
); | |||||
foreach ($tests as $test) { | |||||
list($key, $time, $code) = $test; | |||||
$this->assertEqual( | |||||
$code, | |||||
PhabricatorAuthFactorTOTP::getTOTPCode( | |||||
new PhutilOpaqueEnvelope($key), | |||||
$time)); | |||||
} | |||||
} | |||||
} |