Skip to content

Commit

Permalink
Fix failing container bindings (#11)
Browse files Browse the repository at this point in the history
Fixes failing container bindings due to setLogger calls returning void instead of the instance.
  • Loading branch information
eivee authored Mar 20, 2023
1 parent 83215a7 commit 02aadd1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 22 deletions.
54 changes: 32 additions & 22 deletions src/WebauthnServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ protected function registerWebauthnBindings(): void

$this->app->bind(
AttestationObjectLoader::class,
fn ($app) => (new AttestationObjectLoader(
$app[AttestationStatementSupportManager::class]
))->setLogger($app['log'])
function ($app) {
$attestationObjectLoader = new AttestationObjectLoader($app[AttestationStatementSupportManager::class]);
$attestationObjectLoader->setLogger($app['log']);

return $attestationObjectLoader;
}
);

$this->app->bind(
Expand All @@ -143,24 +146,31 @@ protected function registerWebauthnBindings(): void

$this->app->bind(
AuthenticatorAttestationResponseValidator::class,
fn ($app) => (new AuthenticatorAttestationResponseValidator(
$app[AttestationStatementSupportManager::class],
$app[PublicKeyCredentialSourceRepository::class],
$app[TokenBindingHandler::class],
$app[ExtensionOutputCheckerHandler::class],
))->setLogger($app['log'])
function ($app) {
$authenticatorAttestationResponseValidator = new AuthenticatorAttestationResponseValidator(
$app[AttestationStatementSupportManager::class],
$app[PublicKeyCredentialSourceRepository::class],
$app[TokenBindingHandler::class],
$app[ExtensionOutputCheckerHandler::class],
);
$authenticatorAttestationResponseValidator->setLogger($app['log']);

return $authenticatorAttestationResponseValidator;
}
);

$this->app->bind(
AuthenticatorAssertionResponseValidator::class,
fn ($app) => (new AuthenticatorAssertionResponseValidator(
$this->app->bind(AuthenticatorAssertionResponseValidator::class, function ($app) {
$authenticatorAssertionResponseValidator = new AuthenticatorAssertionResponseValidator(
$app[PublicKeyCredentialSourceRepository::class],
$app[TokenBindingHandler::class],
$app[ExtensionOutputCheckerHandler::class],
$app[CoseAlgorithmManager::class]
))->setCounterChecker($app[CounterChecker::class])
->setLogger($app['log'])
);
$app[CoseAlgorithmManager::class],
);
$authenticatorAssertionResponseValidator->setCounterChecker($app[CounterChecker::class]);
$authenticatorAssertionResponseValidator->setLogger($app['log']);

return $authenticatorAssertionResponseValidator;
});

$this->app->bind(
AuthenticatorSelectionCriteria::class,
Expand All @@ -183,12 +193,12 @@ protected function registerWebauthnBindings(): void
)
);

$this->app->bind(
PublicKeyCredentialLoader::class,
fn ($app) => (new PublicKeyCredentialLoader(
$app[AttestationObjectLoader::class]
))->setLogger($app['log'])
);
$this->app->bind(PublicKeyCredentialLoader::class, function ($app) {
$publicKeyCredentialLoader = new PublicKeyCredentialLoader($app[AttestationObjectLoader::class]);
$publicKeyCredentialLoader->setLogger($app['log']);

return $publicKeyCredentialLoader;
});

$this->app->bind(
CoseAlgorithmManager::class,
Expand Down
27 changes: 27 additions & 0 deletions tests/Services/WebauthnTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
<?php

use Cose\Algorithm\Manager as CoseAlgorithmManager;
use Cose\Algorithm\ManagerFactory as CoseAlgorithmManagerFactory;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Rawilk\Webauthn\Models\WebauthnKey;
use Rawilk\Webauthn\Services\Webauthn;
use Symfony\Component\Uid\NilUlid;
use Webauthn\AttestationStatement\AttestationObjectLoader;
use Webauthn\AttestationStatement\AttestationStatementSupportManager;
use Webauthn\AttestationStatement\PackedAttestationStatementSupport;
use Webauthn\AuthenticatorAssertionResponseValidator;
use Webauthn\AuthenticatorAttestationResponseValidator;
use Webauthn\AuthenticatorSelectionCriteria;
use Webauthn\Counter\CounterChecker;
use Webauthn\PublicKeyCredentialLoader;
use Webauthn\PublicKeyCredentialRpEntity;
use Webauthn\PublicKeyCredentialSource;
use Webauthn\TrustPath\EmptyTrustPath;

Expand Down Expand Up @@ -61,3 +72,19 @@

expect($webauthnKey)->toBeInstanceOf(WebauthnKey::class);
});

it('registers container bindings via closure', function (string $expectedBinding) {
expect($this->app[$expectedBinding])->not->toBeNull($expectedBinding);
})->with([
PackedAttestationStatementSupport::class,
AttestationStatementSupportManager::class,
AttestationObjectLoader::class,
CounterChecker::class,
AuthenticatorAttestationResponseValidator::class,
AuthenticatorAssertionResponseValidator::class,
AuthenticatorSelectionCriteria::class,
PublicKeyCredentialRpEntity::class,
PublicKeyCredentialLoader::class,
CoseAlgorithmManager::class,
CoseAlgorithmManagerFactory::class,
]);

0 comments on commit 02aadd1

Please sign in to comment.