diff --git a/app/Services/WebauthnService.php b/app/Services/WebauthnService.php new file mode 100644 index 0000000..a199023 --- /dev/null +++ b/app/Services/WebauthnService.php @@ -0,0 +1,23 @@ +deployment->domain() !== null && request()->isSecure(); + } + + /** The Relying-Party ID = the active domain (asserted present by available()). */ + public function rpId(): string + { + return (string) $this->deployment->domain(); + } +} diff --git a/tests/Feature/WebauthnAvailableTest.php b/tests/Feature/WebauthnAvailableTest.php new file mode 100644 index 0000000..44c2afc --- /dev/null +++ b/tests/Feature/WebauthnAvailableTest.php @@ -0,0 +1,36 @@ +mock(DeploymentService::class); + $deployment->shouldReceive('domain')->andReturn($domain); + + return app(WebauthnService::class); + } + + public function test_available_only_with_domain_and_https(): void + { + $this->app['request']->server->set('HTTPS', 'on'); + $this->assertTrue($this->service('panel.example.com')->available()); + } + + public function test_unavailable_without_domain(): void + { + $this->app['request']->server->set('HTTPS', 'on'); + $this->assertFalse($this->service(null)->available()); + } + + public function test_unavailable_without_https(): void + { + $this->app['request']->server->remove('HTTPS'); + $this->assertFalse($this->service('panel.example.com')->available()); + } +}