Skip to content

Commit

Permalink
fix-external-url-handling (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
bumblecoder authored Oct 2, 2024
1 parent ca2048e commit c38ca88
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/DependencyInjection/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public function __construct(UrlGeneratorInterface $generator)
public function createProvider($class, array $options, ?string $redirectUri = null, array $redirectParams = [], array $collaborators = [])
{
if (null !== $redirectUri) {
$redirectUri = $this->generator
->generate($redirectUri, $redirectParams, UrlGeneratorInterface::ABSOLUTE_URL);
$redirectUri = filter_var($redirectUri, \FILTER_VALIDATE_URL)
? $redirectUri
: $this->generator->generate($redirectUri, $redirectParams, UrlGeneratorInterface::ABSOLUTE_URL);

$options['redirectUri'] = $redirectUri;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/DependencyInjection/ProviderFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ public function testShouldCreateProviderWithNullRedirectUrl()
$this->assertEquals([], $result->getCollaborators());
}

public function testShouldCreateProviderWithExternalRedirectUrl()
{
$mockGenerator = $this->getMockBuilder(UrlGeneratorInterface::class)
->disableOriginalConstructor()
->getMock();
$mockGenerator->expects($this->never())->method('generate');

$testProviderFactory = new ProviderFactory($mockGenerator);
$externalRedirectUri = 'https://external-site.com/callback';
$result = $testProviderFactory->createProvider(MockProvider::class, [], $externalRedirectUri);

$this->assertInstanceOf(MockProvider::class, $result);
$this->assertEquals(['redirectUri' => $externalRedirectUri], $result->getOptions());
}

private function getMockGenerator($generateReturn)
{
$mockGenerator = $this->getMockBuilder(UrlGeneratorInterface::class)->disableOriginalConstructor()->getMock();
Expand Down

0 comments on commit c38ca88

Please sign in to comment.