/**
  * @test
  * @group yubikey
  */
 public function when_the_second_factor_has_been_created_the_result_is_successful_with_second_factor_id()
 {
     // generated once using \Rhumsaa\Uuid\Uuid::uuid4()
     $uuidV4 = '2daf34c1-22fe-4399-8db9-42492f600cce';
     $result = ProofOfPossessionResult::secondFactorCreated($uuidV4);
     $this->assertTrue($result->isSuccessful());
     $this->assertEquals($uuidV4, $result->getSecondFactorId(), 'The given SecondFactorId should be returned upon request');
     $this->assertFalse($result->isOtpInvalid());
     $this->assertFalse($result->didOtpVerificationFail());
     $this->assertFalse($result->didProofOfPossessionCommandFail());
 }
 /**
  * @param VerifyYubikeyOtpCommand $command
  * @return ProofOfPossessionResult
  */
 public function provePossession(VerifyYubikeyOtpCommand $command)
 {
     $verificationResult = $this->yubikeyService->verify($command);
     if (!$verificationResult->isSuccessful()) {
         if ($verificationResult->isClientError()) {
             return ProofOfPossessionResult::invalidOtp();
         } elseif ($verificationResult->isServerError()) {
             return ProofOfPossessionResult::otpVerificationFailed();
         }
         throw new RuntimeException('Unexpected Verification result, result is not successful but has neither client nor server error');
     }
     $secondFactorId = Uuid::generate();
     $otp = YubikeyOtp::fromString($command->otp);
     $publicId = YubikeyPublicId::fromOtp($otp);
     $provePossessionCommand = new ProveYubikeyPossessionCommand();
     $provePossessionCommand->identityId = $command->identity;
     $provePossessionCommand->secondFactorId = $secondFactorId;
     $provePossessionCommand->yubikeyPublicId = $publicId->getYubikeyPublicId();
     $result = $this->commandService->execute($provePossessionCommand);
     if (!$result->isSuccessful()) {
         return ProofOfPossessionResult::proofOfPossessionCommandFailed();
     }
     return ProofOfPossessionResult::secondFactorCreated($secondFactorId);
 }