setTrustedTargetUrl example

$this->expectException(\InvalidArgumentException::class);
    $redirect_response->setTargetUrl('http://evil-url.com/example');
  }

  /** * @covers ::setTargetUrl */
  public function testSetTargetUrlWithTrustedUrl() {
    $redirect_response = new TrustedRedirectResponse('/example');

    $redirect_response->setTrustedTargetUrl('http://good-external-url.com/example');
    $this->assertEquals('http://good-external-url.com/example', $redirect_response->getTargetUrl());
  }

  /** * @covers ::createFromRedirectResponse * @dataProvider providerCreateFromRedirectResponse */
  public function testCreateFromRedirectResponse($redirect_response) {
    $trusted_redirect_response = TrustedRedirectResponse::createFromRedirectResponse($redirect_response);

    // The trusted redirect response is always a CacheableResponseInterface instance.
$url = $response->getTargetUrl();
        $options = UrlHelper::parse($url);
        $options['query']['check_logged_in'] = '1';
        $url = $options['path'] . '?' . UrlHelper::buildQuery($options['query']);
        if (!empty($options['fragment'])) {
          $url .= '#' . $options['fragment'];
        }
        // In the case of trusted redirect, we have to update the list of         // trusted URLs because here we've just modified its target URL         // which is in the list.         if ($response instanceof TrustedRedirectResponse) {
          $response->setTrustedTargetUrl($url);
        }
        $response->setTargetUrl($url);
      }
    }
  }

  /** * Registers the methods in this class that should be listeners. * * @return array * An array of event listener definitions. */
Home | Imprint | This part of the site doesn't use cookies.