-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
93 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,4 +50,4 @@ jobs: | |
run: composer show -D | ||
|
||
- name: Execute tests | ||
run: vendor/bin/pest --verbose | ||
run: vendor/bin/pest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
return [ | ||
'failed' => 'Turnstile verification failed. Refresh the page and try again.', | ||
'failed' => "We couldn't verify if you're human. Please refresh the page and try again.", | ||
'no_secret_key' => 'Secret key was not found. Please add the key to your services file.', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NjoguAmos\Turnstile\Rules; | ||
|
||
use Closure; | ||
use Illuminate\Contracts\Validation\ValidationRule; | ||
use NjoguAmos\Turnstile\Turnstile; | ||
|
||
class TurnstileRule implements ValidationRule | ||
{ | ||
public function validate(string $attribute, mixed $value, Closure $fail): void | ||
{ | ||
if (! (new Turnstile())->validate(token: $value)) { | ||
$fail(trans(key: 'turnstile::turnstile.failed')); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use NjoguAmos\Turnstile\Rules\TurnstileRule; | ||
|
||
beforeEach(closure: function () { | ||
$this->rule = new TurnstileRule(); | ||
}); | ||
|
||
it(description: 'passes with a valid token', closure: function () { | ||
// Set a key that always passes | ||
setSecretKey(type: 'valid'); | ||
|
||
expect(value:$this->rule)->toPassWith('DUMMY.TOKEN'); | ||
}); | ||
|
||
it(description: 'fails with an valid token', closure: function () { | ||
// Set a key that always passes | ||
setSecretKey(type: 'invalid'); | ||
|
||
expect(value:$this->rule)->not->toPassWith('DUMMY.TOKEN'); | ||
}); | ||
|
||
it(description: 'fails with a spent valid token', closure: function () { | ||
// Set a key that always passes | ||
setSecretKey(type: 'spent'); | ||
|
||
expect(value:$this->rule)->not->toPassWith('DUMMY.TOKEN'); | ||
}); |