Skip to content

Commit

Permalink
Added tests for RedirectController that simulates the situation of a …
Browse files Browse the repository at this point in the history
…reverse proxy and subdirectory
  • Loading branch information
jbtronics committed Jan 7, 2025
1 parent 4421917 commit 24137b3
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion tests/Controller/RedirectControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,62 @@ public function testAddLocale(?string $user_locale, string $input_path, string $

$this->client->followRedirects(false);
$this->client->request('GET', $input_path);
$this->assertResponseRedirects($redirect_path);
self::assertResponseRedirects($redirect_path);
}

/**
* Test if the user is redirected to the localized version of a page, based on his settings.
* We simulate the situation of a reverse proxy here, by adding a prefix to the path.
*
* @dataProvider urlAddLocaleDataProvider
* @group slow
*/
public function testAddLocaleReverseProxy(?string $user_locale, string $input_path, string $redirect_path): void
{
//Input path remains unchanged, as this is what the server receives from the proxy

//Redirect path must contain the proxy prefix
$redirect_path = 'http://localhost'. '/proxy' . $redirect_path;

/** @var User $user */
$user = $this->userRepo->findOneBy(['name' => 'user']);
//Set user locale
$user->setLanguage($user_locale);
$this->em->flush();

$this->client->followRedirects(false);
$this->client->request('GET', $input_path, [], [], ['HTTP_X_FORWARDED_PREFIX' => '/proxy']);
self::assertResponseRedirects($redirect_path);
}


/**
* Test if the user is redirected to the localized version of a page, based on his settings.
* We simulate the situation of serving Part-DB in a subfolder here.
*
* @dataProvider urlAddLocaleDataProvider
* @group slow
*/
public function testAddLocaleSubfolder(?string $user_locale, string $input_path, string $redirect_path): void
{
//Prefix our path with the proxy prefix
$input_path = '/folder'.$input_path;

//Redirect path is absolute
$redirect_path = 'http://localhost'. '/folder' . $redirect_path;

/** @var User $user */
$user = $this->userRepo->findOneBy(['name' => 'user']);
//Set user locale
$user->setLanguage($user_locale);
$this->em->flush();

$this->client->followRedirects(false);
$this->client->request('GET', $input_path, [], [], [
'SCRIPT_FILENAME' => '/var/www/html/folder/public/index.php',
'PHP_SELF' => '/folder/index.php',
]);
self::assertResponseRedirects($redirect_path);
}

}

0 comments on commit 24137b3

Please sign in to comment.