@@ -20,93 +20,93 @@ |
||
20 | 20 | */ |
21 | 21 | class ReCaptchaV3Test extends TestCase { |
22 | 22 | |
23 | - protected $recaptcha_v3 = null; |
|
24 | - |
|
25 | - /** |
|
26 | - * @test |
|
27 | - */ |
|
28 | - public function testGetApiVersion() { |
|
29 | - |
|
30 | - $this->assertEquals($this->recaptcha_v3->getVersion(), 'v3'); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @test |
|
35 | - */ |
|
36 | - public function testHtmlScriptTagJsApiV3GetHtmlScriptTag() { |
|
37 | - |
|
38 | - $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(); |
|
39 | - $this->assertRegexp('/csrfToken/', $r); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @test |
|
44 | - */ |
|
45 | - public function testAction() { |
|
46 | - |
|
47 | - $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['action' => 'someAction']); |
|
48 | - $this->assertRegexp('/someAction/', $r); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * @test |
|
53 | - */ |
|
54 | - public function testFetchCallbackFunction() { |
|
55 | - |
|
56 | - $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_then' => 'functionCallbackThen']); |
|
57 | - $this->assertRegexp('/functionCallbackThen\(response\)/', $r); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @test |
|
62 | - */ |
|
63 | - public function testcCatchCallbackFunction() { |
|
64 | - |
|
65 | - $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_catch' => 'functionCallbackCatch']); |
|
66 | - $this->assertRegexp('/functionCallbackCatch\(err\)/', $r); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * @test |
|
71 | - */ |
|
72 | - public function testCustomValidationFunction() { |
|
73 | - |
|
74 | - $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['custom_validation' => 'functionCustomValidation']); |
|
75 | - $this->assertRegexp('/functionCustomValidation\(token\)/', $r); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @test |
|
80 | - */ |
|
81 | - public function testValidateController() { |
|
82 | - |
|
83 | - $controller = App::make(ReCaptchaController::class); |
|
84 | - $return = $controller->validateV3(); |
|
85 | - |
|
86 | - $this->assertArrayHasKey("success", $return); |
|
87 | - $this->assertArrayHasKey("error-codes", $return); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Define environment setup. |
|
92 | - * |
|
93 | - * @param \Illuminate\Foundation\Application $app |
|
94 | - * |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - protected function getEnvironmentSetUp($app) { |
|
98 | - |
|
99 | - $app['config']->set('recaptcha.version', 'v3'); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Setup the test environment. |
|
104 | - */ |
|
105 | - protected function setUp(): void { |
|
106 | - |
|
107 | - parent::setUp(); // TODO: Change the autogenerated stub |
|
108 | - |
|
109 | - $this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key', 3); |
|
110 | - |
|
111 | - } |
|
23 | + protected $recaptcha_v3 = null; |
|
24 | + |
|
25 | + /** |
|
26 | + * @test |
|
27 | + */ |
|
28 | + public function testGetApiVersion() { |
|
29 | + |
|
30 | + $this->assertEquals($this->recaptcha_v3->getVersion(), 'v3'); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @test |
|
35 | + */ |
|
36 | + public function testHtmlScriptTagJsApiV3GetHtmlScriptTag() { |
|
37 | + |
|
38 | + $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(); |
|
39 | + $this->assertRegexp('/csrfToken/', $r); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @test |
|
44 | + */ |
|
45 | + public function testAction() { |
|
46 | + |
|
47 | + $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['action' => 'someAction']); |
|
48 | + $this->assertRegexp('/someAction/', $r); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * @test |
|
53 | + */ |
|
54 | + public function testFetchCallbackFunction() { |
|
55 | + |
|
56 | + $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_then' => 'functionCallbackThen']); |
|
57 | + $this->assertRegexp('/functionCallbackThen\(response\)/', $r); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @test |
|
62 | + */ |
|
63 | + public function testcCatchCallbackFunction() { |
|
64 | + |
|
65 | + $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['callback_catch' => 'functionCallbackCatch']); |
|
66 | + $this->assertRegexp('/functionCallbackCatch\(err\)/', $r); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * @test |
|
71 | + */ |
|
72 | + public function testCustomValidationFunction() { |
|
73 | + |
|
74 | + $r = $this->recaptcha_v3->htmlScriptTagJsApiV3(['custom_validation' => 'functionCustomValidation']); |
|
75 | + $this->assertRegexp('/functionCustomValidation\(token\)/', $r); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @test |
|
80 | + */ |
|
81 | + public function testValidateController() { |
|
82 | + |
|
83 | + $controller = App::make(ReCaptchaController::class); |
|
84 | + $return = $controller->validateV3(); |
|
85 | + |
|
86 | + $this->assertArrayHasKey("success", $return); |
|
87 | + $this->assertArrayHasKey("error-codes", $return); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Define environment setup. |
|
92 | + * |
|
93 | + * @param \Illuminate\Foundation\Application $app |
|
94 | + * |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + protected function getEnvironmentSetUp($app) { |
|
98 | + |
|
99 | + $app['config']->set('recaptcha.version', 'v3'); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Setup the test environment. |
|
104 | + */ |
|
105 | + protected function setUp(): void { |
|
106 | + |
|
107 | + parent::setUp(); // TODO: Change the autogenerated stub |
|
108 | + |
|
109 | + $this->recaptcha_v3 = new ReCaptchaBuilderV3('api_site_key', 'api_secret_key', 3); |
|
110 | + |
|
111 | + } |
|
112 | 112 | } |
113 | 113 | \ No newline at end of file |
@@ -16,16 +16,16 @@ |
||
16 | 16 | */ |
17 | 17 | class ReCaptchaBuilderV3 extends ReCaptchaBuilder { |
18 | 18 | |
19 | - /** |
|
20 | - * ReCaptchaBuilderV3 constructor. |
|
21 | - * |
|
22 | - * @param string $api_site_key |
|
23 | - * @param string $api_secret_key |
|
24 | - * @param int $curl_timeout |
|
25 | - */ |
|
26 | - public function __construct(string $api_site_key, string $api_secret_key, int $curl_timeout) { |
|
19 | + /** |
|
20 | + * ReCaptchaBuilderV3 constructor. |
|
21 | + * |
|
22 | + * @param string $api_site_key |
|
23 | + * @param string $api_secret_key |
|
24 | + * @param int $curl_timeout |
|
25 | + */ |
|
26 | + public function __construct(string $api_site_key, string $api_secret_key, int $curl_timeout) { |
|
27 | 27 | |
28 | - parent::__construct($api_site_key, $api_secret_key, 'v3', $curl_timeout); |
|
29 | - } |
|
28 | + parent::__construct($api_site_key, $api_secret_key, 'v3', $curl_timeout); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | } |
32 | 32 | \ No newline at end of file |
@@ -13,60 +13,60 @@ |
||
13 | 13 | */ |
14 | 14 | return [ |
15 | 15 | |
16 | - /** |
|
17 | - * |
|
18 | - * The site key |
|
19 | - * get site key @ www.google.com/recaptcha/admin |
|
20 | - * |
|
21 | - */ |
|
22 | - 'api_site_key' => env('RECAPTCHA_SITE_KEY', ''), |
|
16 | + /** |
|
17 | + * |
|
18 | + * The site key |
|
19 | + * get site key @ www.google.com/recaptcha/admin |
|
20 | + * |
|
21 | + */ |
|
22 | + 'api_site_key' => env('RECAPTCHA_SITE_KEY', ''), |
|
23 | 23 | |
24 | - /** |
|
25 | - * |
|
26 | - * The secret key |
|
27 | - * get secret key @ www.google.com/recaptcha/admin |
|
28 | - * |
|
29 | - */ |
|
30 | - 'api_secret_key' => env('RECAPTCHA_SECRET_KEY', ''), |
|
24 | + /** |
|
25 | + * |
|
26 | + * The secret key |
|
27 | + * get secret key @ www.google.com/recaptcha/admin |
|
28 | + * |
|
29 | + */ |
|
30 | + 'api_secret_key' => env('RECAPTCHA_SECRET_KEY', ''), |
|
31 | 31 | |
32 | - /** |
|
33 | - * |
|
34 | - * ReCATCHA version |
|
35 | - * Supported: "v2", "invisible", "v3", |
|
36 | - * |
|
37 | - * get more info @ https://developers.google.com/recaptcha/docs/versions |
|
38 | - * |
|
39 | - */ |
|
40 | - 'version' => env('RECAPTCHA_DEFAULT_VERSION', 'v2'), |
|
32 | + /** |
|
33 | + * |
|
34 | + * ReCATCHA version |
|
35 | + * Supported: "v2", "invisible", "v3", |
|
36 | + * |
|
37 | + * get more info @ https://developers.google.com/recaptcha/docs/versions |
|
38 | + * |
|
39 | + */ |
|
40 | + 'version' => env('RECAPTCHA_DEFAULT_VERSION', 'v2'), |
|
41 | 41 | |
42 | - /** |
|
43 | - * |
|
44 | - * The curl timout in seconds to validate a recaptcha token |
|
45 | - * @since v3.4.3 |
|
46 | - * |
|
47 | - */ |
|
48 | - 'curl_timeout' => env('RECAPTCHA_CURL_TIMEOUT', 10), |
|
42 | + /** |
|
43 | + * |
|
44 | + * The curl timout in seconds to validate a recaptcha token |
|
45 | + * @since v3.4.3 |
|
46 | + * |
|
47 | + */ |
|
48 | + 'curl_timeout' => env('RECAPTCHA_CURL_TIMEOUT', 10), |
|
49 | 49 | |
50 | - /** |
|
51 | - * |
|
52 | - * IP addresses for which validation will be skipped |
|
53 | - * |
|
54 | - */ |
|
55 | - 'skip_ip' => [], |
|
50 | + /** |
|
51 | + * |
|
52 | + * IP addresses for which validation will be skipped |
|
53 | + * |
|
54 | + */ |
|
55 | + 'skip_ip' => [], |
|
56 | 56 | |
57 | - /** |
|
58 | - * |
|
59 | - * Default route called to check the Google reCAPTCHA token |
|
60 | - * @since v3.2.0 |
|
61 | - * |
|
62 | - */ |
|
63 | - 'default_validation_route' => env('RECAPTCHA_DEFAULT_VALIDATION_ROUTE', 'biscolab-recaptcha/validate'), |
|
57 | + /** |
|
58 | + * |
|
59 | + * Default route called to check the Google reCAPTCHA token |
|
60 | + * @since v3.2.0 |
|
61 | + * |
|
62 | + */ |
|
63 | + 'default_validation_route' => env('RECAPTCHA_DEFAULT_VALIDATION_ROUTE', 'biscolab-recaptcha/validate'), |
|
64 | 64 | |
65 | - /** |
|
66 | - * |
|
67 | - * The name of the parameter used to send Google reCAPTCHA token to verify route |
|
68 | - * @since v3.2.0 |
|
69 | - * |
|
70 | - */ |
|
71 | - 'default_token_parameter_name' => env('RECAPTCHA_DEFAULT_TOKEN_PARAMETER_NAME', 'token') |
|
65 | + /** |
|
66 | + * |
|
67 | + * The name of the parameter used to send Google reCAPTCHA token to verify route |
|
68 | + * @since v3.2.0 |
|
69 | + * |
|
70 | + */ |
|
71 | + 'default_token_parameter_name' => env('RECAPTCHA_DEFAULT_TOKEN_PARAMETER_NAME', 'token') |
|
72 | 72 | ]; |