Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/Unit/Auth/Adapters/JwtAuthAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function setUp(): void
'exp' => time() + 60,
]);

$this->jwtAuth = new JwtAuthAdapter($this->authService, $this->mailer, new Hasher(), $jwt);
$this->jwtAuth = new JwtAuthAdapter($this->authService, $this->mailer, (new Hasher())->setCost(4), $jwt);

$admin = $this->jwtAuth->signup($this->adminUser);

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Auth/Adapters/SessionAuthAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function setUp(): void

config()->set('auth.two_fa', false);

$this->sessionAuth = new SessionAuthAdapter($this->authService, $this->mailer, new Hasher());
$this->sessionAuth = new SessionAuthAdapter($this->authService, $this->mailer, (new Hasher())->setCost(4));

$admin = $this->sessionAuth->signup($this->adminUser);

Expand Down
11 changes: 7 additions & 4 deletions tests/Unit/Auth/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
class AuthTest extends AuthTestCase
{
private JwtToken $jwt;
private Hasher $hasher;

public function setUp(): void
{
parent::setUp();

$this->hasher = (new Hasher())->setCost(4);

$this->jwt = (new JwtToken())
->setLeeway(1)
->setClaims([
Expand All @@ -32,18 +35,18 @@ public function setUp(): void

public function testAuthGetAdapter(): void
{
$auth = new Auth(new SessionAuthAdapter($this->authService, $this->mailer, new Hasher()));
$auth = new Auth(new SessionAuthAdapter($this->authService, $this->mailer, $this->hasher));

$this->assertInstanceOf(AuthenticatableInterface::class, $auth->getAdapter());

$auth = new Auth(new JwtAuthAdapter($this->authService, $this->mailer, new Hasher(), $this->jwt));
$auth = new Auth(new JwtAuthAdapter($this->authService, $this->mailer, $this->hasher, $this->jwt));

$this->assertInstanceOf(AuthenticatableInterface::class, $auth->getAdapter());
}

public function testAuthCallingValidMethod(): void
{
$auth = new Auth(new JwtAuthAdapter($this->authService, $this->mailer, new Hasher(), $this->jwt));
$auth = new Auth(new JwtAuthAdapter($this->authService, $this->mailer, $this->hasher, $this->jwt));

$user = $auth->getAdapter()->signup($this->adminUser);

Expand All @@ -58,7 +61,7 @@ public function testAuthCallingValidMethod(): void

public function testAuthCallingInvalidMethod(): void
{
$auth = new Auth(new JwtAuthAdapter($this->authService, $this->mailer, new Hasher(), $this->jwt));
$auth = new Auth(new JwtAuthAdapter($this->authService, $this->mailer, $this->hasher, $this->jwt));

$this->expectException(AuthException::class);

Expand Down
10 changes: 7 additions & 3 deletions tests/Unit/Hasher/HasherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function testSetAndGetCost(): void

public function testHashAndCheck(): void
{
$this->hasher->setCost(4);

$hashed = $this->hasher->hash($this->password);

$this->assertTrue($this->hasher->check($this->password, $hashed));
Expand All @@ -47,23 +49,25 @@ public function testHashAndCheck(): void

public function testNeedsRehash(): void
{
$this->hasher->setCost(10);
$this->hasher->setCost(4);

$hashed = $this->hasher->hash($this->password);

$this->assertFalse($this->hasher->needsRehash($hashed));

$this->hasher->setCost(12);
$this->hasher->setCost(5);

$this->assertTrue($this->hasher->needsRehash($hashed));

$this->hasher->setAlgorithm(PASSWORD_DEFAULT)->setCost(11);
$this->hasher->setAlgorithm(PASSWORD_DEFAULT)->setCost(6);

$this->assertTrue($this->hasher->needsRehash($hashed));
}

public function testInfo(): void
{
$this->hasher->setCost(4);

$hashed = $this->hasher->hash($this->password);

$this->assertIsArray($this->hasher->info($hashed));
Expand Down
Loading