diff --git a/lib/SimpleSAML/Utils/Config.php b/lib/SimpleSAML/Utils/Config.php index fd7762b6a0f9162755fcc9853870180e000573ab..bbdf0e30141e596004b52e5a51a4937e4d39f808 100644 --- a/lib/SimpleSAML/Utils/Config.php +++ b/lib/SimpleSAML/Utils/Config.php @@ -68,6 +68,11 @@ class Config { $configDir = dirname(dirname(dirname(__DIR__))) . '/config'; $configDirEnv = getenv('SIMPLESAMLPHP_CONFIG_DIR'); + + if($configDirEnv === false) { + $configDirEnv = getenv('REDIRECT_SIMPLESAMLPHP_CONFIG_DIR'); + } + if ($configDirEnv !== false) { if (!is_dir($configDirEnv)) { throw new \InvalidArgumentException( diff --git a/tests/lib/SimpleSAML/Utils/ConfigTest.php b/tests/lib/SimpleSAML/Utils/ConfigTest.php index 5dd0fa33b1ad2dca80bd5d43a530af385a7ca532..3fa74c952a399814bdd7e480f7725f4db299f4ab 100644 --- a/tests/lib/SimpleSAML/Utils/ConfigTest.php +++ b/tests/lib/SimpleSAML/Utils/ConfigTest.php @@ -34,6 +34,29 @@ class ConfigTest extends \PHPUnit_Framework_TestCase $this->assertEquals($configDir, __DIR__); } + /** + * Test valid dir specified by env redirect var overrides default config dir + */ + public function testEnvRedirectVariableConfigDir() + { + putenv('REDIRECT_SIMPLESAMLPHP_CONFIG_DIR=' . __DIR__); + $configDir = Config::getConfigDir(); + + $this->assertEquals($configDir, __DIR__); + } + + /** + * Test which directory takes precedence + */ + public function testEnvRedirectPriorityVariableConfigDir() + { + putenv('SIMPLESAMLPHP_CONFIG_DIR=' . dirname(__DIR__)); + putenv('REDIRECT_SIMPLESAMLPHP_CONFIG_DIR=' . __DIR__); + $configDir = Config::getConfigDir(); + + $this->assertEquals($configDir, dirname(__DIR__)); + } + /** * Test invalid dir specified by env var results in a thrown exception