Skip to content

Commit

Permalink
Fix startRegistration bug (#276)
Browse files Browse the repository at this point in the history
* Fix startRegistration bug
* Update integrate.yml
* Fix Rector
  • Loading branch information
Spomky authored Sep 4, 2022
1 parent f3d0187 commit c9ed53d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

name: "Integrate"

on: [ push, pull_request ]
on:
push:
branches:
- "*.x"
pull_request: null

jobs:
byte_level:
Expand Down
6 changes: 5 additions & 1 deletion src/stimulus/Resources/assets/dist/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ class default_1 extends Controller {
headers: optionsHeaders,
body: JSON.stringify(data),
});
const attResp = await startRegistration(await resp.json());
const respJson = await resp.json();
if (respJson.excludeCredentials === undefined) {
respJson.excludeCredentials = [];
}
const attResp = await startRegistration(respJson);
const responseHeaders = {
'Content-Type': 'application/json',
};
Expand Down
6 changes: 5 additions & 1 deletion src/stimulus/Resources/assets/src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ export default class extends Controller {
body: JSON.stringify(data),
});

const attResp = await startRegistration(await resp.json());
const respJson = await resp.json();
if (respJson.excludeCredentials === undefined) {
respJson.excludeCredentials = [];
}
const attResp = await startRegistration(respJson);
const responseHeaders = {
'Content-Type': 'application/json',
};
Expand Down
19 changes: 10 additions & 9 deletions tests/symfony/functional/Firewall/RegistrationAreaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Webauthn\Tests\Bundle\Functional\Firewall;

use Cose\Algorithms;
use const JSON_THROW_ON_ERROR;
use function Safe\base64_decode;
use function Safe\json_decode;
use function Safe\json_encode;
Expand Down Expand Up @@ -53,7 +54,7 @@ public function aRequestWithoutUsernameCannotBeProcessed(): void
'HTTP_HOST' => 'test.com',
], json_encode($content));
$response = $this->client->getResponse();
$data = json_decode($response->getContent(), true);
$data = json_decode($response->getContent(), true, 512, JSON_THROW_ON_ERROR);

static::assertArrayHasKey('status', $data);
static::assertSame('error', $data['status']);
Expand All @@ -75,7 +76,7 @@ public function aRequestWithoutDisplayNameCannotBeProcessed(): void
'HTTP_HOST' => 'test.com',
], json_encode($content));
$response = $this->client->getResponse();
$data = json_decode($response->getContent(), true);
$data = json_decode($response->getContent(), true, 512, JSON_THROW_ON_ERROR);

static::assertArrayHasKey('status', $data);
static::assertSame('error', $data['status']);
Expand Down Expand Up @@ -104,7 +105,7 @@ public function aValidRequestProcessed(): void
'HTTP_HOST' => 'test.com',
], json_encode($content));
$response = $this->client->getResponse();
$data = json_decode($response->getContent(), true);
$data = json_decode($response->getContent(), true, 512, JSON_THROW_ON_ERROR);

static::assertArrayHasKey('status', $data);
static::assertSame('ok', $data['status']);
Expand Down Expand Up @@ -141,7 +142,7 @@ public function aValidRequestProcessedOnOtherHost(): void
'HTTP_HOST' => 'foo.com',
], json_encode($content));
$response = $this->client->getResponse();
$data = json_decode($response->getContent(), true);
$data = json_decode($response->getContent(), true, 512, JSON_THROW_ON_ERROR);

static::assertArrayHasKey('status', $data);
static::assertSame('ok', $data['status']);
Expand Down Expand Up @@ -183,7 +184,7 @@ public function aValidRequestProcessedWithExtensions(): void
'HTTP_HOST' => 'test.com',
], json_encode($content));
$response = $this->client->getResponse();
$data = json_decode($response->getContent(), true);
$data = json_decode($response->getContent(), true, 512, JSON_THROW_ON_ERROR);

static::assertArrayHasKey('status', $data);
static::assertSame('ok', $data['status']);
Expand Down Expand Up @@ -222,7 +223,7 @@ public function aRegistrationOptionsRequestCanBeAcceptedForExistingUsers(): void
'HTTP_HOST' => 'test.com',
], json_encode($content));
$response = $this->client->getResponse();
$data = json_decode($response->getContent(), true);
$data = json_decode($response->getContent(), true, 512, JSON_THROW_ON_ERROR);

static::assertArrayHasKey('status', $data);
static::assertSame('ok', $data['status']);
Expand All @@ -241,11 +242,11 @@ public function aRegistrationResultRequestCannotBeAcceptedIfNoOptionsAreAvailabl
'HTTP_HOST' => 'test.com',
], $content);
$response = $this->client->getResponse();
$data = json_decode($response->getContent(), true);
$data = json_decode($response->getContent(), true, 512, JSON_THROW_ON_ERROR);

static::assertArrayHasKey('status', $data);
static::assertSame('error', $data['status']);
static::assertSame(401, $this->client->getResponse()->getStatusCode());
self::assertResponseStatusCodeSame(401);
static::assertArrayHasKey('errorMessage', $data);
static::assertSame('No public key credential options available for this session.', $data['errorMessage']);
}
Expand Down Expand Up @@ -282,7 +283,7 @@ public function aValidRegistrationResultRequestIsCorrectlyManaged(): void
'HTTP_HOST' => 'localhost',
], $content);
$response = $this->client->getResponse();
$data = json_decode($response->getContent(), true);
$data = json_decode($response->getContent(), true, 512, JSON_THROW_ON_ERROR);

static::assertArrayHasKey('status', $data);
static::assertSame('ok', $data['status']);
Expand Down
2 changes: 1 addition & 1 deletion tests/symfony/functional/Firewall/SecuredAreaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function aUserCannotBeBeAuthenticatedInAbsenceOfOptions(): void
'HTTP_HOST' => 'test.com',
], $assertion);

static::assertSame(Response::HTTP_UNAUTHORIZED, $this->client->getResponse()->getStatusCode());
self::assertResponseStatusCodeSame(Response::HTTP_UNAUTHORIZED);
static::assertSame(
'{"status":"error","errorMessage":"No public key credential options available for this session.","errorCode":15}',
$this->client->getResponse()
Expand Down

0 comments on commit c9ed53d

Please sign in to comment.