TrustedRedirectResponse example

$event = new ResponseEvent($kernel$request, HttpKernelInterface::SUB_REQUEST, $response);
    $this->expectError();
    $dispatcher->dispatch($event, KernelEvents::RESPONSE);
  }

  /** * @covers ::checkRedirectUrl */
  public function testRedirectWithOptInExternalUrl() {
    $dispatcher = new EventDispatcher(\Drupal::getContainer());
    $kernel = $this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface');
    $response = new TrustedRedirectResponse('http://external-url.com');
    $request = Request::create('');
    $request->headers->set('HOST', 'example.com');

    $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext);
    $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']);
    $event = new ResponseEvent($kernel$request, HttpKernelInterface::SUB_REQUEST, $response);
    $dispatcher->dispatch($event, KernelEvents::RESPONSE);

    $target_url = $event->getResponse()->getTargetUrl();
    $this->assertEquals('http://external-url.com', $target_url);
  }

  
$this->assertSame(1, $this->userAuth->authenticate($this->username, $this->password));
  }

  /** * Tests the auth that ends in a redirect from subdomain to TLD. */
  public function testAddCheckToUrlForTrustedRedirectResponse(): void {
    $site_domain = 'site.com';
    $frontend_url = "https://$site_domain";
    $backend_url = "https://api.$site_domain";
    $request = Request::create($backend_url);
    $response = new TrustedRedirectResponse($frontend_url);

    $request_context = $this->createMock(RequestContext::class);
    $request_context
      ->method('getCompleteBaseUrl')
      ->willReturn($backend_url);

    $container = new ContainerBuilder();
    $container->set('router.request_context', $request_context);
    \Drupal::setContainer($container);

    $session_mock = $this->createMock(SessionInterface::class);
    
/** * @coversDefaultClass \Drupal\Core\Routing\TrustedRedirectResponse * @group Routing */
class TrustedRedirectResponseTest extends UnitTestCase {

  /** * @covers ::setTargetUrl */
  public function testSetTargetUrlWithInternalUrl() {
    $redirect_response = new TrustedRedirectResponse('/example');
    $redirect_response->setTargetUrl('/example2');

    $this->assertEquals('/example2', $redirect_response->getTargetUrl());
  }

  /** * @covers ::setTargetUrl */
  public function testSetTargetUrlWithUntrustedUrl() {
    $request_context = new RequestContext();
    $request_context->setCompleteBaseUrl('https://www.drupal.org');
    
Home | Imprint | This part of the site doesn't use cookies.