File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33namespace App \Http \Controllers ;
44
55use App \Actions \RedirectToDestination ;
6+ use App \Helpers \Helper ;
67use App \Models \Url ;
78use Illuminate \Support \Facades \Gate ;
89
@@ -31,6 +32,11 @@ public function __invoke(Url $url)
3132 return to_route ('link.expired ' , $ url );
3233 }
3334
35+ // Check if the domain is in the blacklist
36+ if (Helper::isDomainBlacklisted ($ url ->destination )) {
37+ return abort (404 );
38+ }
39+
3440 return app (RedirectToDestination::class)->handle ($ url );
3541 }
3642}
Original file line number Diff line number Diff line change @@ -301,4 +301,26 @@ public function linkHasExpired_AccessLandingPage()
301301 $ response = $ this ->get (route ('link.expired ' , $ url ));
302302 $ response ->assertRedirect (route ('link_detail ' , $ url ->keyword ));
303303 }
304+
305+ /**
306+ * When a link has a blacklisted domain, it should be redirected
307+ * to the landing page.
308+ *
309+ * @see \App\Http\Controllers\RedirectController::__invoke()
310+ */
311+ #[PHPUnit \Test]
312+ public function linkHasBlacklistedDomain ()
313+ {
314+ // Test case 1: domain is not blacklisted
315+ $ url = Url::factory ()->create ([
316+ 'destination ' => 'https://laravel.com/docs ' ,
317+ ]);
318+ $ response = $ this ->get ($ url ->keyword );
319+ $ response ->assertStatus (config ('urlhub.redirection_status_code ' ));
320+
321+ // Test case 2: domain is blacklisted
322+ config (['urlhub.blacklist_domain ' => ['laravel.com ' ]]);
323+ $ response = $ this ->get ($ url ->keyword );
324+ $ response ->assertNotFound ();
325+ }
304326}
You can’t perform that action at this time.
0 commit comments