-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor registration process to integrate reCAPTCHA
- Replaced hCaptcha implementation with reCAPTCHA in RegisterController and related test cases. - Updated validation rules to utilize g-recaptcha-response instead of h-captcha-response. - Modified RegisterForm component to support reCAPTCHA, including changes to the form data structure and component references. - Enhanced test cases to reflect the new reCAPTCHA integration, ensuring proper validation and response handling. These changes improve security and user experience during the registration process by adopting a more widely used captcha solution.
- Loading branch information
1 parent
6b0c671
commit c649d8c
Showing
3 changed files
with
25 additions
and
33 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
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,13 +1,13 @@ | ||
<?php | ||
|
||
use App\Models\User; | ||
use App\Rules\ValidHCaptcha; | ||
use App\Rules\ValidReCaptcha; | ||
use Illuminate\Support\Facades\Http; | ||
|
||
it('can register', function () { | ||
|
||
Http::fake([ | ||
ValidHCaptcha::H_CAPTCHA_VERIFY_URL => Http::response(['success' => true]) | ||
ValidReCaptcha::RECAPTCHA_VERIFY_URL => Http::response(['success' => true]) | ||
]); | ||
|
||
$this->postJson('/register', [ | ||
|
@@ -17,7 +17,7 @@ | |
'password' => 'secret', | ||
'password_confirmation' => 'secret', | ||
'agree_terms' => true, | ||
'h-captcha-response' => 'test-token', // Mock token for testing | ||
'g-recaptcha-response' => 'test-token', // Mock token for testing | ||
]) | ||
->assertSuccessful() | ||
->assertJsonStructure(['id', 'name', 'email']); | ||
|
@@ -36,15 +36,15 @@ | |
'email' => '[email protected]', | ||
'password' => 'secret', | ||
'password_confirmation' => 'secret', | ||
'h-captcha-response' => 'test-token', | ||
'g-recaptcha-response' => 'test-token', | ||
]) | ||
->assertStatus(422) | ||
->assertJsonValidationErrors(['email']); | ||
}); | ||
|
||
it('cannot register with disposable email', function () { | ||
Http::fake([ | ||
ValidHCaptcha::H_CAPTCHA_VERIFY_URL => Http::response(['success' => true]) | ||
ValidReCaptcha::RECAPTCHA_VERIFY_URL => Http::response(['success' => true]) | ||
]); | ||
|
||
// Select random email | ||
|
@@ -62,7 +62,7 @@ | |
'password' => 'secret', | ||
'password_confirmation' => 'secret', | ||
'agree_terms' => true, | ||
'h-captcha-response' => 'test-token', | ||
'g-recaptcha-response' => 'test-token', | ||
]) | ||
->assertStatus(422) | ||
->assertJsonValidationErrors(['email']) | ||
|
@@ -77,10 +77,10 @@ | |
}); | ||
|
||
it('requires hcaptcha token in production', function () { | ||
config(['services.h_captcha.secret_key' => 'test-key']); | ||
config(['services.recaptcha.secret_key' => 'test-key']); | ||
|
||
Http::fake([ | ||
ValidHCaptcha::H_CAPTCHA_VERIFY_URL => Http::response(['success' => true]) | ||
ValidReCaptcha::RECAPTCHA_VERIFY_URL => Http::response(['success' => true]) | ||
]); | ||
|
||
$this->postJson('/register', [ | ||
|
@@ -92,5 +92,5 @@ | |
'agree_terms' => true, | ||
]) | ||
->assertStatus(422) | ||
->assertJsonValidationErrors(['h-captcha-response']); | ||
->assertJsonValidationErrors(['g-recaptcha-response']); | ||
}); |
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