N°9597 - Switch environment to a build environment must not be available#925
N°9597 - Switch environment to a build environment must not be available#925Lenaick wants to merge 2 commits into
Conversation
|
| Filename | Overview |
|---|---|
| sources/Service/Startup/StartupService.php | Centralizes environment selection and adds the build-environment guard, but misses session-held build environments. |
| application/startup.inc.php | Delegates environment selection to the new service before starting MetaModel. |
Reviews (1): Last reviewed commit: "N°9597 - Switch environment to a build e..." | Re-trigger Greptile
| } elseif (Session::IsSet('itop_env')) { | ||
| $sEnv = Session::Get('itop_env'); |
There was a problem hiding this comment.
Validate session environment The new guard only checks the requested
switch_env, but setup writes the build environment into $_SESSION['itop_env'] during RunTimeEnvironment::InitDataModel(). On the next normal application request with no switch_env, this branch returns production-build from the session and startup.inc.php starts MetaModel from conf/production-build/config-itop.php, so the build environment remains selectable through existing session state.
| if (static::IsBuildEnvironment($sSwitchEnv)) { | ||
| $oException = new CoreException("Switching to environment '$sSwitchEnv' is not allowed since it is a build environment"); | ||
| IssueLog::Exception("Trying to switch to environment '$sSwitchEnv' is not allowed since it is a build environment", $oException); | ||
| throw $oException; | ||
| } | ||
|
|
||
| if ( | ||
| ($sSwitchEnv != null) | ||
| && file_exists(APPCONF.$sSwitchEnv.'/'.ITOP_CONFIG_FILE) | ||
| && (Session::Get('itop_env') !== $sSwitchEnv) | ||
| ) { |
There was a problem hiding this comment.
Check existence first This rejects every
*-build value before checking whether it is a real environment or whether a switch would occur. A request like ?switch_env=does-not-exist-build used to fall through to the current session/default environment because the config file did not exist; now it throws during startup and logs an exception for a value that would otherwise be ignored.
| if (static::IsBuildEnvironment($sSwitchEnv)) { | |
| $oException = new CoreException("Switching to environment '$sSwitchEnv' is not allowed since it is a build environment"); | |
| IssueLog::Exception("Trying to switch to environment '$sSwitchEnv' is not allowed since it is a build environment", $oException); | |
| throw $oException; | |
| } | |
| if ( | |
| ($sSwitchEnv != null) | |
| && file_exists(APPCONF.$sSwitchEnv.'/'.ITOP_CONFIG_FILE) | |
| && (Session::Get('itop_env') !== $sSwitchEnv) | |
| ) { | |
| if ( | |
| ($sSwitchEnv != null) | |
| && file_exists(APPCONF.$sSwitchEnv.'/'.ITOP_CONFIG_FILE) | |
| && (Session::Get('itop_env') !== $sSwitchEnv) | |
| ) { | |
| if (static::IsBuildEnvironment($sSwitchEnv)) { | |
| $oException = new CoreException("Switching to environment '$sSwitchEnv' is not allowed since it is a build environment"); | |
| IssueLog::Exception("Trying to switch to environment '$sSwitchEnv' is not allowed since it is a build environment", $oException); | |
| throw $oException; | |
| } |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| * @return string | ||
| * @throws CoreException | ||
| */ | ||
| public static function SetItopEnvironment(?string $sSwitchEnv, bool &$bAllowCache): string |
There was a problem hiding this comment.
what is the meaning of $bAllowCache? it seems not related to opcache/apccache.
maybe you could document what is its purpose.
There was a problem hiding this comment.
This is a boolean that determines whether the APC cache can be used or not, in conjunction with the apc_cache.enabled parameter
In the case of the environment switch, the cache must not be used
I've updated the documentation
There was a problem hiding this comment.
Maybe a small explanation in the php doc for both parameters would be handy?
| * @return string | ||
| * @throws CoreException | ||
| */ | ||
| public static function SetItopEnvironment(?string $sSwitchEnv, bool &$bAllowCache): string |
There was a problem hiding this comment.
maybe you could change all local method and remove staitc which is not so usefull. and not recommended by phpunit (no mock possible)
Base information
Symptom
When checking compatibility during setup, a build environment is created. It should not be possible to switch to this environment via the system
Proposed solution
Add an exception if the target environment of
switch_envends with*-buildChecklist before requesting a review