/** * @test * @group sms */ public function when_the_proof_of_possession_command_fails_the_result_is_unsuccessful_and_without_second_factor_id() { $result = ProofOfPossessionResult::proofOfPossessionCommandFailed(); $this->assertFalse($result->isSuccessful()); $this->assertTrue($result->didProofOfPossessionFail()); $this->assertNull($result->getSecondFactorId()); $this->assertFalse($result->hasChallengeExpired()); $this->assertFalse($result->wasIncorrectChallengeResponseGiven()); }
/** * @param VerifySmsChallengeCommand $challengeCommand * @return ProofOfPossessionResult */ public function provePossession(VerifySmsChallengeCommand $challengeCommand) { $stepupCommand = new VerifyPossessionOfPhoneCommand(); $stepupCommand->challenge = $challengeCommand->challenge; $verification = $this->smsSecondFactorService->verifyPossession($stepupCommand); if ($verification->didOtpExpire()) { return ProofOfPossessionResult::challengeExpired(); } elseif ($verification->wasAttemptedTooManyTimes()) { return ProofOfPossessionResult::tooManyAttempts(); } elseif (!$verification->wasSuccessful()) { return ProofOfPossessionResult::incorrectChallenge(); } $command = new ProvePhonePossessionCommand(); $command->identityId = $challengeCommand->identity; $command->secondFactorId = Uuid::generate(); $command->phoneNumber = $verification->getPhoneNumber(); $result = $this->commandService->execute($command); if (!$result->isSuccessful()) { return ProofOfPossessionResult::proofOfPossessionCommandFailed(); } return ProofOfPossessionResult::secondFactorCreated($command->secondFactorId); }