jenkins-bot has submitted this change and it was merged.
Change subject: Fix internal domain handling to ensure various cookies get
properly set
......................................................................
Fix internal domain handling to ensure various cookies get properly set
In the event that you are using accessing your instance with an IP
address on a non-standard port (eg 127.0.0.1:8080, like with
mw-vagrant), cookies were not properly being set right because we were
incorrectly identifying the 'base domain' (eg en.wikipedia.org ->
.wikipedia.org) by relying on the Host request header. Now we rely on
$wgServer and parse out the host name with wfParseUrl().
Change-Id: I0c58a9e5e19b917b791dacb958bda19c19049852
---
M includes/MobileContext.php
M tests/MobileContextTest.php
2 files changed, 23 insertions(+), 8 deletions(-)
Approvals:
JGonera: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/MobileContext.php b/includes/MobileContext.php
index b266941..6c3b5dd 100644
--- a/includes/MobileContext.php
+++ b/includes/MobileContext.php
@@ -487,9 +487,11 @@
* @return string
*/
public function getBaseDomain() {
+ global $wgServer;
wfProfileIn( __METHOD__ );
+ $parsedUrl = wfParseUrl( $wgServer );
+ $host = $parsedUrl['host'];
// Validates value as IP address
- $host = $this->getRequest()->getHeader( 'Host' );
if ( !IP::isValid( $host ) ) {
$domainParts = explode( '.', $host );
$domainParts = array_reverse( $domainParts );
diff --git a/tests/MobileContextTest.php b/tests/MobileContextTest.php
index 556d1ea..a3ab073 100644
--- a/tests/MobileContextTest.php
+++ b/tests/MobileContextTest.php
@@ -34,11 +34,24 @@
parent::tearDown();
}
- public function testGetBaseDomain() {
- MobileContext::singleton()->getRequest()->setHeader( 'Host',
'en.wikipedia.org' );
- $this->assertEquals( '.wikipedia.org',
MobileContext::singleton()->getBaseDomain() );
- MobileContext::singleton()->getRequest()->setHeader( 'Host',
'en.m.wikipedia.org' );
- $this->assertEquals( '.wikipedia.org',
MobileContext::singleton()->getBaseDomain() );
+ /**
+ * @dataProvider getBaseDomainProvider
+ */
+ public function testGetBaseDomain( $server, $baseDomain ) {
+ global $wgServer;
+ $wgServer = $server;
+ $this->assertEquals( $baseDomain,
MobileContext::singleton()->getBaseDomain() );
+
+ }
+
+ public function getBaseDomainProvider() {
+ return array(
+ array( 'https://en.wikipedia.org', '.wikipedia.org' ),
+ array( 'http://en.m.wikipedia.org', '.wikipedia.org' ),
+ array( '//en.m.wikipedia.org', '.wikipedia.org' ),
+ array( 'http://127.0.0.1', '127.0.0.1' ),
+ array( 'http://127.0.0.1:8080', '127.0.0.1' ),
+ );
}
public function testGetMobileUrl() {
@@ -329,10 +342,10 @@
}
public function testGetStopMobileRedirectCookieDomain(){
- global $wgMFStopRedirectCookieHost;
+ global $wgMFStopRedirectCookieHost, $wgServer;
$context = MobileContext::singleton();
$wgMFStopRedirectCookieHost = null;
- $context->getRequest()->setHeader( 'Host', 'en.wikipedia.org' );
+ $wgServer = 'http://en.wikipedia.org';
$this->assertEquals(
$context->getStopMobileRedirectCookieDomain(), '.wikipedia.org' );
$wgMFStopRedirectCookieHost = 'foo.bar.baz';
$this->assertEquals(
$context->getStopMobileRedirectCookieDomain(), 'foo.bar.baz' );
--
To view, visit https://gerrit.wikimedia.org/r/115844
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I0c58a9e5e19b917b791dacb958bda19c19049852
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Awjrichards <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits