/** * @return Prophecy\Prophecy\ObjectProphecy */ private function getUser(array $values = []) { $values = $values + ['k' => false, 'i' => false, 'p' => false]; $type = Argument::type('Firehed\\Security\\Secret'); $user = $this->prophesize('Firehed\\Auth\\Authable'); $user->validateInherenceFactor($type)->willReturn($values['i']); $user->validateKnowledgeFactor($type)->willReturn($values['k']); $user->validatePossessionFactor($type)->willReturn($values['p']); $user->getID()->willReturn('user_id'); $user->getAuthFactorNotValidBeforeTime()->willReturn(new DateTime('@0')); // Unixtime 0 // Default user behavior is password-only $user->getRequiredAuthenticationFactors()->willReturn([Type::KNOWLEDGE()]); return $user; }
private function assertFactorTimestamps() : self { $data = [[FactorType::KNOWLEDGE(), $this->kfct, $this->kfet], [FactorType::POSSESSION(), $this->pfct, $this->pfet], [FactorType::INHERENCE(), $this->ifct, $this->ifet]]; foreach ($data as $types) { list($type, $create, $exp) = $types; $validation = $this->validateType($type, $create, $exp); switch ($validation) { case self::RET_OK: break; case self::RET_UNAUTH: throw new AE\AuthenticationRequiredException([]); case self::RET_EXP: throw new AE\FactorExpiredException([]); } } return $this; }
/** * @covers ::getPartiallyAuthenticatedUser */ public function testGetPartiallyAuthenticatedUserWorksWhenInPartialMode() { $a = new Auth(); $u = $this->getUser(); $u->getRequiredAuthenticationFactors()->willReturn([Factors\FactorType::KNOWLEDGE()]); $u = $u->reveal(); $a->setUser($u); $a->setRequiredLevel(Level::PARTIAL()); // Sanity checks $this->assertTrue($a->isMissingKnowledgeFactor()); $this->assertNull($a->getUser()); // Actual test $this->assertSame($u, $a->getPartiallyAuthenticatedUser(), 'getPartiallyAuthenticatedUser did not return the user'); }
/** * By default, assume knowledge factors (e.g. passwords) are exclusively * supported. Override this to support MFA. * @return array<Factors\FactorType> */ public function getRequiredAuthenticationFactors() : array { return [Factors\FactorType::KNOWLEDGE()]; }