Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
Rewrite to use $_REQUEST instead of checking $_GET and $_POST individ…
Browse files Browse the repository at this point in the history
…ually
  • Loading branch information
thomas-alrek committed Jun 12, 2019
1 parent 7e152bb commit ceedd46
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions src/Netflex/Site/Support/CaptchaV2.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@ public static function checkBox()
*/
public static function isValid()
{
if (array_key_exists('g-recaptcha-response', $_GET))
$response = $_GET['g-recaptcha-response'];
if (array_key_exists('g-recaptcha-response', $_POST))
$response = $_POST['g-recaptcha-response'];;
if (!isset($response))
$response = null;

if (array_key_exists('g-recaptcha-response', $_REQUEST)) {
$response = $_REQUEST['g-recaptcha-response'];
}

if (is_null($response)) {
throw new ResponseMissingException('g-recaptcha-response is missing from $_GET and $_POST');
}

$response = json_decode(NF::$capi->post('https://www.google.com/recaptcha/api/siteverify', [
'form_params' => [
Expand Down
6 changes: 3 additions & 3 deletions tests/TestSuites/CaptchaV2/CaptchaV2.isValid.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testThrowsExceptionWhenParametersMissing (): void {
}

public function testHandlesRequestException (): void {
$_GET['g-recaptcha-response'] = 'test';
$_REQUEST['g-recaptcha-response'] = 'test';
NF::$capi->mockResponse(new Response(500));
NF::$site->mockVariable('captcha_site_key', 'aabbccddeeff');
NF::$site->mockVariable('captcha_site_secret', '112233445566');
Expand All @@ -33,7 +33,7 @@ public function testHandlesRequestException (): void {
}

public function testHandlesValidCase (): void {
$_GET['g-recaptcha-response'] = 'test';
$_REQUEST['g-recaptcha-response'] = 'test';
NF::$site->mockVariable('captcha_site_key', 'aabbccddeeff');
NF::$site->mockVariable('captcha_site_secret', '112233445566');
NF::$capi->mockResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode([
Expand All @@ -48,7 +48,7 @@ public function testHandlesValidCase (): void {
}

public function testHandlesInvalidCase (): void {
$_GET['g-recaptcha-response'] = 'test';
$_REQUEST['g-recaptcha-response'] = 'test';
NF::$site->mockVariable('captcha_site_key', 'aabbccddeeff');
NF::$site->mockVariable('captcha_site_secret', '112233445566');
NF::$capi->mockResponse(new Response(200, ['Content-Type' => 'application/json'], json_encode([
Expand Down

0 comments on commit ceedd46

Please sign in to comment.