mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/OATHAuth
synced 2024-11-28 10:10:19 +00:00
ba39a4dfa8
Mostly I wanted to add tests for verifying serialization and deserialization, since that's what I modify in my next commit. Change-Id: I8223f2e3e1b3ce79afc8c5cd9ca4afe6d418abf9
30 lines
930 B
PHP
30 lines
930 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::newFromString( json_encode( $key ) );
|
|
$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' ) );
|
|
}
|
|
}
|