laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.71k stars 11.06k forks source link

Validation : active_url bug with homestead. #14846

Closed GuillaumeValadas closed 8 years ago

GuillaumeValadas commented 8 years ago

I think i found a bug with homestead and validation rule active url

Versions: "laravel/framework": "5.2.*" (and lumen).

This bug is about homestead (last version)

We didnt have this bug before we use homestead (new pc). So when we attempt to check an url we get an error with homestead. We didn't get this error without homestead.

I make a simple test.

tests/ExampleTest.php

 /** @test */
    public function validationActiveUrl()
    {
        $form = ['source' => 'https://laravel.com'];

        $response = $this->call('GET', '/test', $form);

        $this->assertEquals(200, $response->getStatusCode());
    } 

app/Http/routes.php Route::get('/test', 'Controller@test');

app/Http/Controllers/Controller.php

<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesResources;

class Controller extends BaseController
{
    use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests;

    public function test(Request $request)
    {
        $this->validate($request, [
            'source'        => 'required|active_url'
        ]);

        return response();
    }
}

Phpunit result

➜  test phpunit
PHPUnit 4.8.27 by Sebastian Bergmann and contributors.

.F

Time: 229 ms, Memory: 10.00MB

There was 1 failure:

1) ExampleTest::validationActiveUrl
Failed asserting that 500 matches expected 200.

/home/vagrant/Code/test/tests/ExampleTest.php:27

FAILURES!
Tests: 2, Assertions: 3, Failures: 1.

laravel.log

[2016-08-16 14:14:59] testing.ERROR: ErrorException: dns_get_record(): A temporary server error occurred. in /home/vagrant/Code/test/vendor/laravel/framework/src/Illuminate/Validation/Validator.php:1534
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'dns_get_record(...', '/home/vagrant/C...', 1534, Array)
#1 /home/vagrant/Code/test/vendor/laravel/framework/src/Illuminate/Validation/Validator.php(1534): dns_get_record('laravel.com', 134217729)
#2 /home/vagrant/Code/test/vendor/laravel/framework/src/Illuminate/Validation/Validator.php(485): Illuminate\Validation\Validator->validateActiveUrl('source', 'https://laravel...', Array, Object(Illuminate\Validation\Validator))
GrahamCampbell commented 8 years ago

Looks like there's an issue with your dns server, not us.

GuillaumeValadas commented 8 years ago

I havent this problem before using homestead. So if it was a dns problem i should get the same error... And not pass the test anyways.

I didn't find any solution on internet.

I juste followed the documentation to install homestead. I didn't read anything about setting something on homestead to use this validation.

Charkhan commented 8 years ago

@GrahamCampbell Tested on vanilla Homestead box too and could reproduce the same error.

Working fine when using local webserver.

ghost commented 8 years ago

You have to configure your Homestead dns, exemple: ssh homestead (my alias) sudo vi /etc/resolv.conf nameserver 8.8.8.8 (replace by) and that's work

Charkhan commented 8 years ago

Hey @vincentdenaes !

Thanks for the tip, but this file is automatically, so you'll have to do this each time you boot the VM.

I looked for a persistant solution, but didn't find one :/

damianlewis commented 8 years ago

I'm getting the same problem using the 'active_url' validation rule on an OctoberCMS site that's running on Homestead.

Did anyone find a solution?

Here's the error from the OctoberCMS system.log file:

[2016-11-28 18:48:52] local.ERROR: ErrorException: dns_get_record(): A temporary server error occurred. in /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Validation/Validator.php:1243
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'dns_get_record(...', '/home/vagrant/l...', 1243, Array)
#1 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Validation/Validator.php(1243): dns_get_record('www.facebook.co...', 134217729)
#2 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Validation/Validator.php(363): Illuminate\Validation\Validator->validateActiveUrl('facebook', 'http://www.face...', Array, Object(Illuminate\Validation\Validator))
#3 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Validation/Validator.php(315): Illuminate\Validation\Validator->validate('facebook', 'ActiveUrl')
#4 /home/vagrant/laurdan/vendor/october/rain/src/Database/Traits/Validation.php(248): Illuminate\Validation\Validator->passes()
#5 /home/vagrant/laurdan/vendor/october/rain/src/Database/Traits/Validation.php(68): Laurdan\Contact\Models\SocialMediaSettings->validate()
#6 [internal function]: Laurdan\Contact\Models\SocialMediaSettings::October\Rain\Database\Traits\{closure}(Array, Array)
#7 /home/vagrant/laurdan/vendor/october/rain/src/Support/Traits/Emitter.php(135): call_user_func_array(Object(Closure), Array)
#8 /home/vagrant/laurdan/vendor/october/rain/src/Database/Model.php(1094): October\Rain\Database\Model->fireEvent('model.saveInter...', Array, true)
#9 /home/vagrant/laurdan/vendor/october/rain/src/Database/Model.php(1146): October\Rain\Database\Model->saveInternal(Array)
#10 /home/vagrant/laurdan/modules/system/controllers/settings.php(98): October\Rain\Database\Model->save(NULL, 'tJvbUUvOdD9xz5J...')
#11 [internal function]: System\Controllers\Settings->update_onSave('laurdan', 'contact', 'socialmedia')
#12 /home/vagrant/laurdan/modules/backend/Classes/Controller.php(526): call_user_func_array(Array, Array)
#13 /home/vagrant/laurdan/modules/backend/Classes/Controller.php(417): Backend\Classes\Controller->runAjaxHandler('onSave')
#14 /home/vagrant/laurdan/modules/backend/Classes/Controller.php(227): Backend\Classes\Controller->execAjaxHandlers()
#15 /home/vagrant/laurdan/modules/backend/Classes/BackendController.php(89): Backend\Classes\Controller->run('update', Array)
#16 [internal function]: Backend\Classes\BackendController->run('system/settings...')
#17 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(256): call_user_func_array(Array, Array)
#18 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(164): Illuminate\Routing\Controller->callAction('run', Array)
#19 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(112): Illuminate\Routing\ControllerDispatcher->call(Object(Backend\Classes\BackendController), Object(Illuminate\Routing\Route), 'run')
#20 [internal function]: Illuminate\Routing\ControllerDispatcher->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#21 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#22 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#23 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#24 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(114): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#25 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(67): Illuminate\Routing\ControllerDispatcher->callWithinStack(Object(Backend\Classes\BackendController), Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'run')
#26 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Routing/Route.php(203): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), 'Backend\\Classes...', 'run')
#27 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Routing/Route.php(134): Illuminate\Routing\Route->runWithCustomDispatcher(Object(Illuminate\Http\Request))
#28 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Routing/Router.php(708): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#29 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#30 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#31 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#32 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#33 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Routing/Router.php(710): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#34 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Routing/Router.php(673): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#35 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Routing/Router.php(635): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#36 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(236): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#37 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#38 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#39 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#40 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#41 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#42 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(62): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#43 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#44 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#45 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#46 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#47 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#48 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#49 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#50 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#51 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(44): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#52 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#53 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#54 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#55 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#56 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(122): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#57 /home/vagrant/laurdan/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(87): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#58 /home/vagrant/laurdan/index.php(43): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#59 {main}
orediggerco commented 7 years ago

I think this has to do with IPv6 on homestead. Looking at the validation rule for active_url on this line: https://github.com/illuminate/validation/blob/master/Validator.php#L1643 it is querying both IPv4 and v6 at the same time. When calling the function this way within homestead, I'm reproducing the error above.

~$ php artisan tinker
Psy Shell v0.8.0 (PHP 7.1.0-2+deb.sury.org~xenial+1 — cli) by Justin Hileman
>>> dns_get_record('google.com', DNS_A+DNS_AAAA);
PHP warning:  dns_get_record(): A temporary server error occurred. on line 1
>>> dns_get_record('google.com', DNS_A);
=> [
     [
       "host" => "google.com",
       "class" => "IN",
       "ttl" => 3600,
       "type" => "A",
       "ip" => "216.58.217.46",
     ],
   ]
>>> dns_get_record('google.com', DNS_AAAA);
PHP warning:  dns_get_record(): A temporary server error occurred. on line 1

Ran these tests with nslookup both within and outside my homestead box:

Inside homestead:

(homestead)~$ nslookup -type=AAAA google.com
Server:         10.0.2.3
Address:        10.0.2.3#53

** server can't find google.com: NOTIMP

From my host machine:

(host)$ nslookup -type=AAAA google.com
Server:  cdns01.comcast.net
Address:  75.75.75.75

Non-authoritative answer:
Name:    google.com
Address:  2607:f8b0:400f:802::200e

So I think this has something to do with the network setup that Homestead is doing within Vagrant, not something with Laravel nor with anyone's DNS server/provider. Unfortunately my vagrant-fu is not as strong as I'd like it to be, so I haven't been able to track this down further yet.

orediggerco commented 7 years ago

Did some more research and moved this conversation to a new issue in laravel/homestead with my findings.

browner12 commented 7 years ago

reference to new issue

https://github.com/laravel/homestead/issues/409

Charkhan commented 7 years ago

Thanks for the dig up guys !