Skip to content

Commit

Permalink
[FEATURE] Provide ways to work with automated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
georgringer committed Jun 17, 2024
1 parent 3fb706e commit 9effca0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
19 changes: 16 additions & 3 deletions Classes/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

namespace StudioMitte\FriendlyCaptcha;

use Psr\Http\Message\RequestInterface;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Site\Entity\NullSite;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;

class Configuration
{
Expand All @@ -25,7 +27,7 @@ public function __construct(Site $site = null)
if ($site === null) {
$site = $GLOBALS['TYPO3_REQUEST']->getAttribute('site');
}
if ($site === null || $site instanceof NullSite) {
if ($site === null) {
return;
}
$siteConfiguration = $site->getConfiguration();
Expand All @@ -39,7 +41,7 @@ public function __construct(Site $site = null)

public function isEnabled(): bool
{
return $this->siteKey !== '' && $this->siteSecretKey !== '' && $this->puzzleUrl !== '' && $this->verifyUrl !== '';
return $this->siteKey !== '' && $this->siteSecretKey !== '' && $this->puzzleUrl !== '' && $this->verifyUrl !== '' && !$this->hasSkipHeaderValidation();
}

public function getSiteKey(): string
Expand Down Expand Up @@ -77,4 +79,15 @@ public function hasSkipDevValidation(): bool
{
return Environment::getContext()->isDevelopment() && $this->skipDevValidation;
}

public function hasSkipHeaderValidation(): bool
{
/** @var ServerRequest $request */
$request = $GLOBALS['TYPO3_REQUEST'];
$validationName = (string)($_ENV['FRIENDLYCAPTCHA_SKIP_HEADER_VALIDATION'] ?? '');
if (strlen($validationName) < 30) {
return false;
}
return $request && $request->hasHeader('X-FriendlyCaptcha-Skip-Validation') && in_array($validationName, $request->getHeader('X-FriendlyCaptcha-Skip-Validation'), truex);

This comment has been minimized.

Copy link
@OlivierSC

OlivierSC Jun 18, 2024

Hello, I think it "true" and not "truex" for the last parameter of in_array

}
}
8 changes: 8 additions & 0 deletions Documentation/Configuration/Integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ A new tab **Friendly Captcha** is available which includes all configuration opt
After finishing the configuration, you are ready to use Friendly Captcha on your site.

This is described in the :ref:`using` section!


Working with automated tests
============================
If you are using automated tests you might want to skip the captcha.
This can be achieved by setting the folloowing ENV variable `FRIENDLYCAPTCHA_SKIP_HEADER_VALIDATION` to a string with minimum length of 30.

Now provide the same string with with the request header `X-FriendlyCaptcha-Skip-Validation`.

0 comments on commit 9effca0

Please sign in to comment.