Example #1
0
 function testStatic()
 {
     $loc = new folksoFabula();
     $this->assertEqual($loc->setServerUrl('example.com'), 'http://example.com', 'Not adding http:// to url with setServerUrl');
     $this->assertEqual($loc->web_url, 'http://example.com', '$web_url is not getting set correctly by setServerUrl');
     $this->assertEqual($loc->setServerUrl('http://bobworld.com'), 'http://bobworld.com', 'setServerUrl() is mangling url that already contained http://');
     $this->assertEqual($loc->setServerUrl('bobworld3/'), 'http://bobworld3', 'setServerUrl() is not removing trailing slash');
     $this->assertIsA($loc->locDBC(), folksoDBconnect, 'Not able to build a dbc object');
     $loc->loginPage = 'loggezmoi.php';
     $loc->setServerUrl('example.com');
     $loc->set_server_web_path('hooha');
     $this->assertEqual($loc->loginPage(), 'http://example.com/hooha/loggezmoi.php', 'Incorrect loginPage: ' . $loc->loginPage());
     $this->assertEqual($loc->web_url, 'http://example.com', 'Incorrect web_url is set: ' . $loc->web_url);
     $loc->loginPage = 'tagorama/loggezmoi.php';
     $this->assertEqual($loc->loginPage(), 'http://example.com/tagorama/loggezmoi.php', 'Incorrect login url with path in $loc->loginPage');
     $loc->loginPage = '/tagallday/loggezmoi.php';
     $this->assertEqual($loc->loginPage(), 'http://example.com/tagallday/loggezmoi.php', 'Incorrect login url with absolute path in $loc->loginPage' . $loc->loginPage());
 }
Example #2
0
 /**
  * Based on the request received, checks each response object is
  * checked to see if it is equiped to handle the request.
  */
 public function Respond()
 {
     if (!$this->valid_method()) {
         // some kind of error
         header('HTTP/1.0 405');
         print "NOT OK. Illegal request method for this resource.";
         return;
     }
     if (!$this->validClientAddress($_SERVER['REMOTE_HOST'], $_SERVER['REMOTE_ADDR'])) {
         header('HTTP/1.0 403');
         print "Sorry, this not available to you";
         return;
     }
     $q = new folksoQuery($_SERVER, $_GET, $_POST);
     $realm = 'folkso';
     $loc = new folksoFabula();
     $dbc = $loc->locDBC();
     $fks = new folksoSession($dbc);
     /**
      * $sid: session ID
      */
     $sid = $_COOKIE['folksosess'] ? $_COOKIE['folksosess'] : $q->get_param('session');
     try {
         $fks->setSid($sid);
     } catch (badSidException $e) {
         if ($q->is_write_method()) {
             header('HTTP/1.1 403 Login required');
             // redirect instead
             header('Location: ' . $loc->loginPage());
             exit;
         }
     }
     /* check each response object and run the response if activatep
        returns true*/
     $repflag = false;
     if (count($this->responseObjects) === 0) {
         trigger_error("No responseObjects available", E_USER_ERROR);
     }
     /** Walking the response objects **/
     foreach ($this->responseObjects as $resp) {
         if ($resp->activatep($q)) {
             $repflag = true;
             $resp->Respond($q, $dbc, $fks);
             break;
         }
     }
     /** check for no valid response **/
     if (!$repflag) {
         header('HTTP/1.1 400');
         print "Client did not make a valid query. (folksoServer)";
         // default response or error page...
     }
 }