mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/OATHAuth
synced 2024-12-20 20:02:59 +00:00
370452d05b
Only used in tests. Change-Id: I4eb020eb507d5342e4e5ab8f92bf1ee22db0056b
30 lines
950 B
PHP
30 lines
950 B
PHP
<?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();
|
|
$deserialized = TOTPKey::newFromArray( json_decode( json_encode( $key ), true ) );
|
|
$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' ) );
|
|
}
|
|
}
|