<?php

namespace Buckhill\U2F\tests\units\Authenticate;

require('vendor/autoload.php');

use Buckhill\U2F\U2FKey;
use mageekguy\atoum;
use Buckhill\U2F\U2FHelper;
use function \Buckhill\U2F\u2f;

class Request extends atoum
{
    public function testChallenge()
    {
        $this
            ->given($u2fkey = U2FKey::fromArray($this->getValidKSMKey()))
            ->then
                ->object($key = u2f()->authenticate()->response($this->getValidU2FAuthSignature(), $u2fkey))->isInstanceOf(U2FKey::class)
                ->integer($key->getCounter())->isEqualTo(27)
                ->string($key->toJSON())->isNotEmpty()->hasLength(212)
         ;
    }

    protected function getValidKSMKey()
    {
        return [
            'challenge'     => 'YnJHbzRiNXdQYW5YNnBhbUozOHBJaVpkZ0Jrb3pzSVU',
            'publicKey'     => 'BEfBekIF7AhKwgi4QpQg0mQUQmIIEq6fDCOEv8auCDNNfeNpdNLrRFfAB9KjlBxp/pxjl45v2CnSOuSH+nmHMuk=',
            'keyHandle'     => 'TBl7BtPWkiiB7GEdphPferDvTdnB1wSdjSYtHYg3BqNh19RKSNgv6-hPROB-pqeoq3rlel5NsnFqeLUAhF5Nbg',
            'appId'         => 'https://server.mfa.web',
            'version'       => U2FHelper::U2F_VERSION,
            'counter'       => 0
        ];
    }

    protected function getValidU2FAuthSignature()
    {
        return [
            'clientData'    => 'eyJ0eXAiOiJuYXZpZ2F0b3IuaWQuZ2V0QXNzZXJ0aW9uIiwiY2hhbGxlbmdlIjoiWW5KSGJ6UmlOWGRRWVc1WU5uQmhiVW96T0hCSmFWcGtaMEpyYjNwelNWVSIsIm9yaWdpbiI6Imh0dHBzOi8vc2VydmVyLm1mYS53ZWIiLCJjaWRfcHVia2V5IjoiIn0',
            'keyHandle'     => 'TBl7BtPWkiiB7GEdphPferDvTdnB1wSdjSYtHYg3BqNh19RKSNgv6-hPROB-pqeoq3rlel5NsnFqeLUAhF5Nbg',
            'signatureData' => 'AQAAABswRAIgZnfBV7O_O1j3keClYYtobXWFRbropjiYATy_RoVwp8oCIHFvZjRFP5tGDB1qY6vJZ250yAnw8J_ZLVMZ8RN3kOr5'
        ];
    }
}
