diff --git a/VERSIONS_HOTLINE/61629 b/VERSIONS_HOTLINE/61629 new file mode 100644 index 0000000000000000000000000000000000000000..d525d313f2d48a09b99db0ffe84c37d432e46e4d --- /dev/null +++ b/VERSIONS_HOTLINE/61629 @@ -0,0 +1,2 @@ + - ticket #61629 : Impossibilité de forcer la variable HTTPS si le site n'est pas configuré en https + diff --git a/application/modules/admin/controllers/IndexController.php b/application/modules/admin/controllers/IndexController.php index a799de39ce64984240d0581edfd8952610466218..097e911876aa724308ad579c30e6cd7ea2830ad0 100644 --- a/application/modules/admin/controllers/IndexController.php +++ b/application/modules/admin/controllers/IndexController.php @@ -66,12 +66,21 @@ class Admin_IndexController extends ZendAfi_Controller_Action { } + public function getUrlWithHttpsIfNeeded($id) { + if (($id != 'FORCE_HTTPS') || + (Class_AdminVar::get('FORCE_HTTPS') == 1)) + return $this->view->url(); + + Class_AdminVar_ForceHTTPS::$FORCE_HTTPS = true; + return Class_Url::rootUrl().$this->view->url(); + } + + public function adminvareditAction() { $id = $this->_getParam('cle'); $var = Class_AdminVar::find($id); - $form = $var->getForm(); - $form->setAction($this->view->url()); + $form->setAction($this->getUrlWithHttpsIfNeeded($id)); $form->setAttrib('data-backurl', $this->view->url(['module' => 'admin', 'controller' => 'index', diff --git a/library/Class/AdminVar/ForceHTTPS.php b/library/Class/AdminVar/ForceHTTPS.php index 9d4889de3e70bc6b8404231948f56b3ab616be7b..3522ea6ff0ababdf8a5056305f23428125cb326c 100644 --- a/library/Class/AdminVar/ForceHTTPS.php +++ b/library/Class/AdminVar/ForceHTTPS.php @@ -21,8 +21,11 @@ class Class_AdminVar_ForceHTTPS { - public static function isEnabled() { - return '1' == Class_AdminVar::get('FORCE_HTTPS'); + public static $FORCE_HTTPS=false; + + public static function isEnabled( ) { + return ('1' == Class_AdminVar::get('FORCE_HTTPS') + || static::$FORCE_HTTPS); } } ?> \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/AdminIndexControllerTest.php b/tests/application/modules/admin/controllers/AdminIndexControllerTest.php index 30c078ec72b886186e807c713ff0ec570f467429..0e91fe63fde3330e61b587821da75279a5bfe752 100644 --- a/tests/application/modules/admin/controllers/AdminIndexControllerTest.php +++ b/tests/application/modules/admin/controllers/AdminIndexControllerTest.php @@ -898,3 +898,44 @@ class AdminIndexControllerAdminVarEditSearchAlsoInPostTest json_decode(Class_AdminVar::find('SEARCH_ALSO_IN')->getValeur())->site_url[0]); } } + + + +class AdminIndexControllerAdminVarEditHTTPSTest + extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + protected $oldServerName; + + + public function setUp() { + parent::setUp(); + $this->oldServerName = $_SERVER['SERVER_NAME']; + $_SERVER['SERVER_NAME'] = "MyWebsite"; + + } + + + public function tearDown() { + parent::tearDown(); + Class_AdminVar_ForceHTTPS::$FORCE_HTTPS = false; + $_SERVER['SERVER_NAME'] = $this->oldServerName; + } + + /** @test */ + public function editAdminVarShouldPostHTTPS() { + Class_AdminVar::set('FORCE_HTTPS', 0); + $this->dispatch('/admin/index/adminvaredit/cle/FORCE_HTTPS', true); + $this->assertXPath('//form[@action="https://MyWebsite/admin/index/adminvaredit/cle/FORCE_HTTPS"]',$this->_response->getBody()); + } + + + /** @test */ + public function editAdminVarShouldPostHTTPIfAlreadySetToHttps() { + Class_AdminVar_ForceHTTPS::$FORCE_HTTPS = true; + $this->dispatch('/admin/index/adminvaredit/cle/FORCE_HTTPS', true); + $this->assertXPath('//form[@action="https://MyWebsite/admin/index/adminvaredit/cle/FORCE_HTTPS"]',$this->_response->getBody()); + + } + + +}