delete(); } /** * @test */ public function test_webauthn_login_uses_login_and_returns_no_content() { $this->user = User::factory()->create(); $mock = $this->mock(AssertedRequest::class)->makePartial()->shouldIgnoreMissing(); $mock->shouldReceive([ 'has' => false, 'login' => $this->user, ]); $this->json('POST', '/webauthn/login') ->assertNoContent(); } /** * @test */ public function test_webauthn_invalid_login_returns_error() { $this->user = User::factory()->create(); $mock = $this->mock(AssertedRequest::class)->makePartial()->shouldIgnoreMissing(); $mock->shouldReceive([ 'has' => false, 'login' => null, ]); $this->json('POST', '/webauthn/login') ->assertNoContent(422); } /** * @test */ public function test_webauthn_login_with_missing_data_returns_validation_error() { $this->user = User::factory()->create(); $data = [ 'id' => '', 'rawId' => '', 'type' => '', 'response' => [ 'authenticatorData' => '', 'clientDataJSON' => '', 'signature' => '', 'userHandle' => null, ], ]; $response = $this->json('POST', '/webauthn/login', $data) ->assertStatus(422) ->assertJsonValidationErrors([ 'id', 'rawId', 'type', 'response.authenticatorData', 'response.clientDataJSON', 'response.signature', ]); } /** * @test */ public function test_get_options_returns_success() { $this->user = User::factory()->create(); DB::table('webauthn_credentials')->insert([ 'id' => self::CREDENTIAL_ID, 'authenticatable_type' => \App\Models\User::class, 'authenticatable_id' => $this->user->id, 'user_id' => self::USER_ID, 'counter' => 0, 'rp_id' => 'http://localhost', 'origin' => 'http://localhost', 'aaguid' => '00000000-0000-0000-0000-000000000000', 'attestation_format' => 'none', 'public_key' => self::PUBLIC_KEY, 'updated_at' => now(), 'created_at' => now(), ]); $response = $this->json('POST', '/webauthn/login/options') ->assertOk() ->assertJsonStructure([ 'challenge', 'userVerification', 'timeout', ]) ->assertJsonFragment([ 'allowCredentials' => [[ 'id' => self::CREDENTIAL_ID, 'type' => 'public-key', ]], ]); } /** * @test */ public function test_get_options_with_no_registred_user_returns_error() { $this->json('POST', '/webauthn/login/options') ->assertStatus(400) ->assertJsonStructure([ 'message', ]); } }