<?php

namespace Buckhill\Yubico\tests\units\Modes\OATH;

require('vendor/autoload.php');

use Buckhill\Yubico\Modes\OATH\OTP;
use mageekguy\atoum;

class YubikeyOATH extends atoum
{

    public function testVerify()
    {
        $otp = 'ubnu05403411383104';

        $this
            ->given($yubikey = $this->getYubikeyOATH())
            ->and(
                $otp = new OTP($otp)
            )
            ->then
                ->object($yubikey)->isInstanceOf(\Buckhill\Yubico\Modes\OATH\YubikeyOATH::class)
                ->integer($yubikey->verify($otp))->isEqualTo(0)
                ->string($otp->getTokenIdentifier())->isEqualTo('ubnu05403411')
            ;
    }

    /**
     * @return \Buckhill\Yubico\Modes\OATH\YubikeyOATH
     */
    protected function getYubikeyOATH()
    {
        $identifier = 'ubnu05 40 34 11';
        $secret = '50 60 6e 0a 44 32 0e 90 70 d3 8f 3e 8b 7f 52 cf 82 3f b0 d5';

        return \Buckhill\Yubico\Modes\OATH\YubikeyOATH::fromArray([
                'identifier' => $identifier,
                'secret' => $secret
            ]
        );
    }
}