2022-02-28 07:01:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\OATHAuth\Tests\Key;
|
|
|
|
|
|
|
|
use MediaWiki\Extension\OATHAuth\Key\TOTPKey;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \MediaWiki\Extension\OATHAuth\Key\TOTPKey
|
|
|
|
*/
|
|
|
|
class TOTPKeyTest extends \MediaWikiIntegrationTestCase {
|
|
|
|
public function testDeserialization() {
|
|
|
|
$key = TOTPKey::newFromRandom();
|
2024-01-01 17:36:10 +00:00
|
|
|
$deserialized = TOTPKey::newFromArray( json_decode( json_encode( $key ), true ) );
|
2022-02-28 07:01:45 +00:00
|
|
|
$this->assertSame( $key->getSecret(), $deserialized->getSecret() );
|
|
|
|
$this->assertSame( $key->getScratchTokens(), $deserialized->getScratchTokens() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIsScratchToken() {
|
|
|
|
$key = TOTPKey::newFromArray( [
|
|
|
|
'secret' => '123456',
|
|
|
|
'scratch_tokens' => [ '64SZLJTTPRI5XBUE' ],
|
|
|
|
] );
|
|
|
|
$this->assertTrue( $key->isScratchToken( '64SZLJTTPRI5XBUE' ) );
|
|
|
|
// Whitespace is stripped
|
|
|
|
$this->assertTrue( $key->isScratchToken( ' 64SZLJTTPRI5XBUE ' ) );
|
|
|
|
// Wrong token
|
|
|
|
$this->assertFalse( $key->isScratchToken( 'WIQGC24UJUFXQDW4' ) );
|
|
|
|
}
|
|
|
|
}
|