Skip to content

Commit

Permalink
In Twitter callback URL, replace localhost with 127.0.0.1 closes #1308
Browse files Browse the repository at this point in the history
  • Loading branch information
ginatrapani committed May 1, 2012
1 parent 050d334 commit ac12cbd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
12 changes: 12 additions & 0 deletions tests/TestOfUtils.php
Expand Up @@ -253,5 +253,17 @@ public function testGetApplicationURL() {
$utils_url = Utils::getApplicationURL();
$expected_url = 'http://mytestthinkup/my/path/to/thinkup/';
$this->assertEqual($utils_url, $expected_url);

//localhost
$_SERVER['HTTP_HOST'] = "localhost";
$utils_url = Utils::getApplicationURL();
$expected_url = 'http://localhost/my/path/to/thinkup/';
$this->assertEqual($utils_url, $expected_url);

//localhost - return IP
$_SERVER['HTTP_HOST'] = "localhost";
$utils_url = Utils::getApplicationURL(true);
$expected_url = 'http://127.0.0.1/my/path/to/thinkup/';
$this->assertEqual($utils_url, $expected_url);
}
}
6 changes: 5 additions & 1 deletion webapp/_lib/model/class.Utils.php
Expand Up @@ -295,10 +295,14 @@ public static function getSiteRootPathFromFileSystem() {

/**
* Get the application's full URL, i.e., https://example.com/thinkup/
* @param $replace_localhost_with_ip Default to false
* @return str
*/
public static function getApplicationURL() {
public static function getApplicationURL($replace_localhost_with_ip = false) {
$server = empty($_SERVER['SERVER_NAME']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
if ($replace_localhost_with_ip) {
$server = ($server == 'localhost')?'127.0.0.1':$server;
}
$site_root_path = Config::getInstance()->getValue('site_root_path');
$port = (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != "" && $_SERVER['SERVER_PORT'] != "80"
&& $_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT']:'';
Expand Down
Expand Up @@ -100,7 +100,7 @@ public function authControl() {
}

$this->addToView('twitter_app_name', "ThinkUp ". $_SERVER['SERVER_NAME']);
$this->addToView('thinkup_site_url', Utils::getApplicationURL());
$this->addToView('thinkup_site_url', Utils::getApplicationURL(true));

$plugin = new TwitterPlugin();
if ($plugin->isConfigured()) {
Expand Down
Expand Up @@ -123,7 +123,6 @@ public function testOutputNoParams() {
* Test user submission
*/
public function testAddTwitterUserNoTwitterAuth() {

// build some options data
$options_arry = $this->buildPluginOptions();
$this->simulateLogin('me@example.com');
Expand Down Expand Up @@ -203,6 +202,20 @@ public function testConfigOptionsIsAdminWithSSL() {
$this->assertNoPattern('/http:\/\/mytestthinkup/', $output);
}

public function testLocalhostConversionTo1270001() {
$_SERVER['HTTPS'] = null;
$_SERVER['SERVER_NAME'] = 'localhost';
// build some options data
$options_arry = $this->buildPluginOptions();
$this->simulateLogin('me@example.com', true);
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$owner = $owner_dao->getByEmail(Session::getLoggedInUser());
$controller = new TwitterPluginConfigurationController($owner, 'twitter');
$output = $controller->go();

$this->assertPattern('/http:\/\/127\.0\.0\.1/', $output);
}

/*
* Test required settings not set
*/
Expand Down

0 comments on commit ac12cbd

Please sign in to comment.