From ccb6d8a5135ec97776f926a5f483d9f1f88d061b Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 13 May 2011 18:10:25 +0200 Subject: [PATCH 01/14] fix ssl client cert login process --- src/SemanticScuttle/Service/User.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php index 09a2cb1..0e437c2 100644 --- a/src/SemanticScuttle/Service/User.php +++ b/src/SemanticScuttle/Service/User.php @@ -426,8 +426,8 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService if ($ssls->hasValidCert()) { $id = $ssls->getUserIdFromCert(); if ($id !== false) { - $this->setCurrentUserId($id); - return (int)$_SESSION[$this->getSessionKey()]; + $this->setCurrentUserId($id, true); + return $this->currentuserId; } } return false; From 62afb014825e85c40df225358d608bef430a8949 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 13 May 2011 18:11:14 +0200 Subject: [PATCH 02/14] allow ssl client login with other authentication sources --- src/SemanticScuttle/Service/AuthUser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SemanticScuttle/Service/AuthUser.php b/src/SemanticScuttle/Service/AuthUser.php index 479b68a..9447ee4 100644 --- a/src/SemanticScuttle/Service/AuthUser.php +++ b/src/SemanticScuttle/Service/AuthUser.php @@ -130,7 +130,7 @@ class SemanticScuttle_Service_AuthUser extends SemanticScuttle_Service_User //FIXME: caching? $name = $this->auth->getUsername(); if (!$name) { - return false; + return parent::getCurrentUserId(); } return $this->getIdFromUser($name); } From d9e74639787ae02dc5b0165e40fc2c75a74d084e Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 13 May 2011 18:16:25 +0200 Subject: [PATCH 03/14] add note about SNI --- doc/ssl-client-certificates.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/ssl-client-certificates.rst b/doc/ssl-client-certificates.rst index e12b507..7abf17a 100644 --- a/doc/ssl-client-certificates.rst +++ b/doc/ssl-client-certificates.rst @@ -94,7 +94,14 @@ you use. Apache configuration -------------------- To make use of SSL client certificates, you need to deliver SemanticScuttle -via HTTPS. +via HTTPS. + +Note that you can equip several virtual hosts with SSL certificates +and keep them on the same, standard SSL port by using SNI - +`Server Name Indication`__. + +.. _SNI: http://wiki.apache.org/httpd/NameBasedSSLVHostsWithSNI +__ SNI_ A basic virtual host configuration with SSL looks like this: From e616b19304d63b59e943dbf8c90b2f131d465dea Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 14 May 2011 10:18:46 +0200 Subject: [PATCH 04/14] proper status code when gsearch is deactivated --- www/gsearch/index.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/www/gsearch/index.php b/www/gsearch/index.php index 70be05e..12e7233 100644 --- a/www/gsearch/index.php +++ b/www/gsearch/index.php @@ -1,8 +1,11 @@ From 81714ab878c275499b85981266208597cfbc315c Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 14 May 2011 10:26:38 +0200 Subject: [PATCH 05/14] make custom search more valid html --- www/gsearch/index.php | 57 +++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/www/gsearch/index.php b/www/gsearch/index.php index 12e7233..477aacb 100644 --- a/www/gsearch/index.php +++ b/www/gsearch/index.php @@ -1,4 +1,23 @@ - + * @author Christian Weiske + * @author Eric Dane + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + * @link http://www.google.com/cse/docs/cref.html + */ +require_once '../www-header.php'; if ($GLOBALS['enableGoogleCustomSearch'] == false) { header('HTTP/1.0 403 Forbidden'); @@ -9,12 +28,14 @@ if ($GLOBALS['enableGoogleCustomSearch'] == false) { } ?> - - -<?php echo $GLOBALS['sitename'] ?> - -
-
+ + + + + <?php echo htmlspecialchars($GLOBALS['sitename']); ?> + + +
@@ -30,21 +51,21 @@ if ($GLOBALS['enableGoogleCustomSearch'] == false) { ... -isLoggedOn() && $currentUser->isAdmin()){ - echo '

'; - echo T_('Admin tips: '); - echo T_('To refresh manually Google Custom Search Engine, goes to: '); - echo 'http://www.google.com/coop/cse/cref' . '
'; - echo T_('If no result appears, check that all the urls are valid in the admin section.'); - echo '

'; - -} + echo T_('If no result appears, check that all the urls are valid in the admin section.'); + echo '

'; + +} ?> -
- + + From 01f21995dd5d488fa13be54049610bec919ced95 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 14 May 2011 10:30:01 +0200 Subject: [PATCH 06/14] fix google custom search xml --- www/gsearch/context.php | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/www/gsearch/context.php b/www/gsearch/context.php index d714ec1..ea496de 100644 --- a/www/gsearch/context.php +++ b/www/gsearch/context.php @@ -1,16 +1,35 @@ + * @author Christian Weiske + * @author Eric Dane + * @license GPL http://www.gnu.org/licenses/gpl.html + * @link http://sourceforge.net/projects/semanticscuttle + * @link http://www.google.com/cse/docs/cref.html + */ require_once '../www-header.php'; -if($GLOBALS['enableGoogleCustomSearch'] == false) { - echo "Google Custom Search disabled. You can enable it into the config.php file."; - die; +if ($GLOBALS['enableGoogleCustomSearch'] == false) { + header('HTTP/1.0 403 Forbidden'); + header('Content-Type: text/plain; charset=utf-8'); + echo "Google Custom Search disabled." + . " You can enable it into the config.php file.\n"; + die(); } ?> - - + - <?php echo $GLOBALS['sitename'] ?> + <?php echo htmlspecialchars($GLOBALS['sitename']) ?> From 8d29eaf349d8e8767863aff889fe82905387ef16 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 14 May 2011 10:30:43 +0200 Subject: [PATCH 07/14] CS --- www/gsearch/context.php | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/www/gsearch/context.php b/www/gsearch/context.php index ea496de..fd10c4e 100644 --- a/www/gsearch/context.php +++ b/www/gsearch/context.php @@ -28,19 +28,16 @@ if ($GLOBALS['enableGoogleCustomSearch'] == false) { ?> - - <?php echo htmlspecialchars($GLOBALS['sitename']) ?> - - - - - - - - - - - - + + <?php echo htmlspecialchars($GLOBALS['sitename']) ?> + + + + + + + + + From e118a7d97b964a3146c35139da92d6514eb3b235 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sat, 14 May 2011 10:31:28 +0200 Subject: [PATCH 08/14] update changelog with google custom search changes --- doc/ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/ChangeLog b/doc/ChangeLog index a54e71e..3c4e939 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -14,6 +14,7 @@ ChangeLog for SemantiScuttle - Update php-gettext library to 1.0.10 - api/posts/add respects the "replace" parameter now - Fix privacy issue when fetching tags of several users +- Fix Google custom search XML - Only URLs with an allowed protocol may be added to the database - Support HTTPS connections when $root is not configured - SQL schema version table to ease future database upgrades From ef23f01ebab448f10cb3935af4a2723f0e362c38 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 19 May 2011 07:38:35 +0200 Subject: [PATCH 09/14] begin supporting a different database for unit tests --- src/SemanticScuttle/header-standalone.php | 2 +- src/SemanticScuttle/header.php | 17 ++++++++++++----- tests/TestBaseApi.php | 7 ++++--- tests/prepare.php | 4 ++-- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/SemanticScuttle/header-standalone.php b/src/SemanticScuttle/header-standalone.php index cc1b0bd..50732a6 100644 --- a/src/SemanticScuttle/header-standalone.php +++ b/src/SemanticScuttle/header-standalone.php @@ -14,7 +14,7 @@ * @link http://sourceforge.net/projects/semanticscuttle */ $_SERVER['HTTP_HOST'] = 'http://localhost/'; -define('UNIT_TEST_MODE', true); +//define('UNIT_TEST_MODE', true); require_once dirname(__FILE__) . '/header.php'; ?> \ No newline at end of file diff --git a/src/SemanticScuttle/header.php b/src/SemanticScuttle/header.php index b0705b0..098e5c3 100644 --- a/src/SemanticScuttle/header.php +++ b/src/SemanticScuttle/header.php @@ -46,14 +46,21 @@ if (isset($_GET['unittestMode']) && $_GET['unittestMode'] == 1 die("Unittestmode is not allowed\n"); } - $unittestConfigFile = $datadir . '/config.unittest.php'; - if (file_exists($unittestConfigFile)) { - require_once $unittestConfigFile; - } define('HTTP_UNIT_TEST_MODE', true); define('UNIT_TEST_MODE', true); } if (defined('UNIT_TEST_MODE')) { + //load configuration for unit tests + $testingConfigFile = $datadir . '/config.testing.php'; + if (file_exists($testingConfigFile)) { + require_once $testingConfigFile; + } + //test-specific configuration file + $unittestConfigFile = $datadir . '/config.testing-tmp.php'; + if (file_exists($unittestConfigFile)) { + require_once $unittestConfigFile; + } + //make local config vars global - needed for unit tests //run with phpunit foreach (get_defined_vars() as $var => $value) { @@ -107,7 +114,7 @@ T_bind_textdomain_codeset($domain, 'UTF-8'); T_textdomain($domain); // 4 // Session -if (!defined('UNIT_TEST_MODE') || defined('HTTP_UNIT_TEST_MODE')) { +if (isset($_SERVER['REMOTE_ADDR'])) { session_start(); if ($GLOBALS['enableVoting']) { if (isset($_SESSION['lastUrl'])) { diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index 2caa701..31797c9 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -50,8 +50,9 @@ class TestBaseApi extends TestBase $this->url = $GLOBALS['unittestUrl'] . $this->urlPart; //clean up before test - if (file_exists($GLOBALS['datadir'] . '/config.unittest.php')) { - unlink($GLOBALS['datadir'] . '/config.unittest.php'); + $configFile = $GLOBALS['datadir'] . '/config.testing-tmp.php'; + if (file_exists($configFile)) { + unlink($configFile); } $this->us = SemanticScuttle_Service_Factory::get('User'); @@ -230,7 +231,7 @@ class TestBaseApi extends TestBase $this->assertInternalType( 'integer', - file_put_contents($GLOBALS['datadir'] . '/config.unittest.php', $str), + file_put_contents($GLOBALS['datadir'] . '/config.testing-tmp.php', $str), 'Writing config.unittest.php failed' ); } diff --git a/tests/prepare.php b/tests/prepare.php index c80306e..ea4d77d 100644 --- a/tests/prepare.php +++ b/tests/prepare.php @@ -22,7 +22,7 @@ $_SERVER['HTTP_HOST'] = 'http://localhost/'; define('UNIT_TEST_MODE', true); if ('@data_dir@' == '@' . 'data_dir@') { - //non pear-install + //non pear-installation (i.e. git checkout) require_once dirname(__FILE__) . '/../src/SemanticScuttle/header.php'; } else { //pear installation; files are in include path @@ -35,7 +35,7 @@ if ($GLOBALS['debugMode'] == true && $GLOBALS['dbtype'] == 'mysql4' ) { echo "\n" - . '!!! The combination of debugMode and dbtype==mysql4' + . '!! The combination of debugMode and dbtype==mysql4' . ' will wreck some tests' . "\n\n"; } ?> \ No newline at end of file From b436b4273dfec8f376d15a0f934d5a4c153fc4d0 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Thu, 19 May 2011 07:39:42 +0200 Subject: [PATCH 10/14] ignore test configs --- .gitignore | 4 +++- data/.gitignore | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) delete mode 100644 data/.gitignore diff --git a/.gitignore b/.gitignore index e512e0c..7695176 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ dist/ build.properties package.xml semanticscuttle-dump.sql -data/config.unittest.php +data/config.php +data/config.testing.php +data/config.testing-tmp.php diff --git a/data/.gitignore b/data/.gitignore deleted file mode 100644 index 4f4773f..0000000 --- a/data/.gitignore +++ /dev/null @@ -1 +0,0 @@ -config.php From 675aa6291a39c0bc77636cca3453b7874e97b6c3 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 20 May 2011 06:58:28 +0200 Subject: [PATCH 11/14] automatically append unittestmode parameter to url --- tests/TestBaseApi.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index 31797c9..1f2e8ff 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -77,10 +77,14 @@ class TestBaseApi extends TestBase */ protected function getRequest($urlSuffix = null) { - $req = new HTTP_Request2( - $this->url . $urlSuffix, - HTTP_Request2::METHOD_GET - ); + $url = $this->url . $urlSuffix; + if (strpos($urlSuffix, '?') !== false) { + $url .= '&unittestMode=1'; + } else { + $url .= '?unittestMode=1'; + } + + $req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET); return $req; } From 191f08683edb9970c2ad6c061840292c2df14d61 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 20 May 2011 07:02:52 +0200 Subject: [PATCH 12/14] all but one test work now with a different unittest database --- tests/TestBaseApi.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tests/TestBaseApi.php b/tests/TestBaseApi.php index 1f2e8ff..20574f3 100644 --- a/tests/TestBaseApi.php +++ b/tests/TestBaseApi.php @@ -72,10 +72,26 @@ class TestBaseApi extends TestBase * @param string $urlSuffix Suffix for the URL * * @return HTTP_Request2 HTTP request object + */ + protected function getRequest($urlSuffix = null) + { + $url = $this->getTestUrl($urlSuffix); + $req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET); + + return $req; + } + + /** + * Creates an URL from $this->url plus $urlSuffix and an appended + * unittestMode=1 parameter. + * + * @param string $urlSuffix Suffix for the URL + * + * @return string URL * * @uses $url */ - protected function getRequest($urlSuffix = null) + protected function getTestUrl($urlSuffix = null) { $url = $this->url . $urlSuffix; if (strpos($urlSuffix, '?') !== false) { @@ -83,10 +99,7 @@ class TestBaseApi extends TestBase } else { $url .= '?unittestMode=1'; } - - $req = new HTTP_Request2($url, HTTP_Request2::METHOD_GET); - - return $req; + return $url; } @@ -170,7 +183,7 @@ class TestBaseApi extends TestBase $uid = $this->addUser($username, $password); $req = new HTTP_Request2( - $GLOBALS['unittestUrl'] . '/login.php', + $GLOBALS['unittestUrl'] . '/login.php?unittestMode=1', HTTP_Request2::METHOD_POST ); $cookies = $req->setCookieJar()->getCookieJar(); From 1bbc36f8a4a41fc1a55767fc28921ac44a6a60a7 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 20 May 2011 17:08:39 +0200 Subject: [PATCH 13/14] fix test --- tests/www/searchTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/www/searchTest.php b/tests/www/searchTest.php index 1220667..5dce69d 100644 --- a/tests/www/searchTest.php +++ b/tests/www/searchTest.php @@ -41,7 +41,7 @@ class www_SearchTest extends TestBaseApi 'No bookmark found', false ); - $res = $this->getRequest('/all/baz bat')->send(); + $res = $this->getRequest('/all/baz%20bat')->send(); $this->assertSelectCount( '.xfolkentry', false, $res->getBody(), 'Bookmarks found', false From 97bba97049eeed2ecec022caa641b50ca507cb72 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 20 May 2011 17:11:45 +0200 Subject: [PATCH 14/14] no need for that anymore --- src/SemanticScuttle/header-standalone.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SemanticScuttle/header-standalone.php b/src/SemanticScuttle/header-standalone.php index 50732a6..3755ea1 100644 --- a/src/SemanticScuttle/header-standalone.php +++ b/src/SemanticScuttle/header-standalone.php @@ -14,7 +14,6 @@ * @link http://sourceforge.net/projects/semanticscuttle */ $_SERVER['HTTP_HOST'] = 'http://localhost/'; -//define('UNIT_TEST_MODE', true); require_once dirname(__FILE__) . '/header.php'; ?> \ No newline at end of file