Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH PHP 8.1 compatibility #89

Merged
merged 1 commit into from
Apr 26, 2022
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 .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ env:
- REQUIRE_FRAMEWORKTEST="^0.4.2"
- SS_MFA_SECRET_KEY=TEST123
# Used by behat-extension LoginContext which expects a screen to choose either totp or webauthn when not skipping mfa
- REQUIRE_EXTRA="silverstripe/webauthn-authenticator:^4"
- REQUIRE_EXTRA="silverstripe/webauthn-authenticator:4.x-dev"
4 changes: 2 additions & 2 deletions src/RegisterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function start(StoreInterface $store): array
protected function generateSecret(): string
{
$length = $this->config()->get('secret_length');
return substr(trim(Base32::encodeUpper(random_bytes(64)), '='), 0, $length);
return substr(trim(Base32::encodeUpper(random_bytes(64)) ?? '', '='), 0, $length);
}

/**
Expand All @@ -92,7 +92,7 @@ protected function generateSecret(): string
*/
public function register(HTTPRequest $request, StoreInterface $store): Result
{
$data = json_decode($request->getBody(), true);
$data = json_decode($request->getBody() ?? '', true);
$result = $this->getTotp($store)->verify($data['code'] ?? '');
if (!$result) {
return Result::create(false, _t(__CLASS__ . '.INVALID_CODE', 'Provided code was not valid'));
Expand Down
2 changes: 1 addition & 1 deletion src/VerifyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function start(StoreInterface $store, RegisteredMethod $method): array

public function verify(HTTPRequest $request, StoreInterface $store, RegisteredMethod $registeredMethod): Result
{
$data = json_decode($request->getBody(), true);
$data = json_decode($request->getBody() ?? '', true);
if (!$this->getTotp($store)->verify($data['code'] ?? '')) {
return Result::create(false, _t(__CLASS__ . '.INVALID_CODE', 'Invalid code'));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/behat/src/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function iPressTheBackupCodesButton($button)
*/
private function pressMfaButton($section, $button)
{
$section = str_replace("'", "\\'", $section);
$button = str_replace("'", "\\'", $button);
$section = str_replace("'", "\\'", $section ?? '');
$button = str_replace("'", "\\'", $button ?? '');
$js = <<<JS
document.querySelectorAll('.registered-method-list-item').forEach(el => {
if (!el.innerHTML.includes('{$section}')) {
Expand Down
4 changes: 2 additions & 2 deletions tests/php/RegisterHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public function testStart()

$this->assertTrue($result['enabled'], 'Method should be enabled');
$this->assertStringContainsString(
rawurlencode(SiteConfig::current_site_config()->Title),
rawurlencode(SiteConfig::current_site_config()->Title ?? ''),
$result['uri'],
'Site name should be stored in provisioning URI'
);
$this->assertStringContainsString(
rawurlencode($this->member->Email),
rawurlencode($this->member->Email ?? ''),
$result['uri'],
'Provisioning URI should contain user email'
);
Expand Down