Skip to content

Commit

Permalink
fix: Verify method could throw an exception if no actions parameters …
Browse files Browse the repository at this point in the history
…were saved (merged from 1.1.1)
  • Loading branch information
juban committed May 13, 2022
1 parent 249db2d commit 029d7dc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Google Recaptcha Changelog

## 2.0.2 - 2022-05-13
### Fixed
- Fix an exception that could occur in verify method if no actions parameters were saved (merged from 1.1.1)

## 2.0.1 - 2022-05-09

### Fixed
Expand All @@ -10,6 +14,10 @@
### Added
- Added Craft 4 compatibility.

## 1.1.1 - 2022-05-13
### Fixed
- Fix an exception that could occur in verify method if no actions parameters were saved.

## 1.1.0 - 2022-03-07
### Added
- (v3 API) Default action name and score threshold can be configured
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "simplonprod/craft-google-recaptcha",
"description": "Google reCAPTCHA for Craft CMS",
"type": "craft-plugin",
"version": "2.0.1",
"version": "2.0.2",
"keywords": [
"craft",
"cms",
Expand Down
5 changes: 4 additions & 1 deletion src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ public function validateActions()
*/
public function getScoreThresholdPerAction(): array
{
return ArrayHelper::map($this->actions, 'name', 'scoreThreshold');
if (is_array($this->actions)) {
return ArrayHelper::map($this->actions, 'name', 'scoreThreshold');
}
return [];
}

/**
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/ServicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,29 @@ public function testVerifyWithInvalidResponseException(): void
$this->expectException(ForbiddenHttpException::class);
GoogleRecaptcha::$plugin->recaptcha->verify();
}

public function testVerifyWithEmptyActionsSettings(): void
{
GoogleRecaptcha::$plugin->setSettings([
'version' => 3,
'actions' => '',
]);
$response = $this->make(
Response::class,
[
'getStatusCode' => 200,
'getBody' => Utils::streamFor(
Json::encode([
'success' => true,
'action' => 'homepage',
'score' => 0.5,
])
),
]
);
$googleRecaptchaService = $this->make(Recaptcha::class, [
'getRecaptchaClient' => $this->_getClientMock($response),
]);
$this->assertTrue($googleRecaptchaService->verify());
}
}

0 comments on commit 029d7dc

Please sign in to comment.