Changeset 153

Show
Ignore:
Timestamp:
01/25/07 18:00:46 (2 years ago)
Author:
mikey
Message:

added test for net.stubbles.ipo.session.stubBaseSession

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/ipo/session/stubBaseSession.php

    r138 r153  
    11<?php 
    22/** 
    3  * interface for sessions 
     3 * Base class for session implementations. 
    44 * 
    55 * @author      Frank Kleine <mikey@stubbles.net> 
     
    99stubClassLoader::load('net.stubbles.ipo.session.stubSession'); 
    1010/** 
    11  * interface for sessions 
     11 * Base class for session implementations. 
     12 *  
     13 * This class offers a basic implementation for session handling, mainly for  
     14 * the default values of a session which are the start time of the session,  
     15 * the fingerprint of the user and the token of the current and the next  
     16 * request. While a concrete instance is created the class checks the session  
     17 * to prevent the user against session fixation and session hijacking. 
    1218 * 
    1319 * @package     stubbles 
    1420 * @subpackage  ipo_session 
    15  * @todo        create test 
    1621 */ 
    1722abstract class stubBaseSession extends stubBaseObject implements stubSession 
     
    4348    protected final function __construct($sessionName) 
    4449    { 
    45         $this->doConstuct($sessionName); 
     50        $this->doConstruct($sessionName); 
    4651         
    4752        if ($this->hasValue(stubSession::START_TIME) == false || $this->doGetValue(stubSession::FINGERPRINT) != $this->getFingerprint()) { 
     
    5560             
    5661            $this->putValue(stubSession::START_TIME, time()); 
    57            $this->isNew = true; 
    58            $this->putValue(stubSession::FINGERPRINT, $this->getFingerprint()); 
    59            $this->token = md5(uniqid(rand())); 
    60         } else { 
    61             $this->token = $this->doGetValue(stubSession::NEXT_TOKEN); 
    62        
    63          
    64         $this->putValue(stubSession::NEXT_TOKEN, md5(uniqid(rand()))); 
     62            $this->isNew = true; 
     63            $this->putValue(stubSession::FINGERPRINT, $this->getFingerprint()); 
     64            $this->token = md5(uniqid(rand())); 
     65        } else { 
     66            $this->token = $this->doGetValue(stubSession::NEXT_TOKEN); 
     67       
     68         
     69        $this->putValue(stubSession::NEXT_TOKEN, md5(uniqid(rand()))); 
    6570    } 
    6671     
     
    202207     * removes a value from the session 
    203208     * 
    204      * @param  string  $key  key where value is stored under 
     209     * @param   string  $key  key where value is stored under 
     210     * @return  bool    true if value existed and was removed, else false 
    205211     * @throws  stubSessionException 
    206212     */ 
     
    212218         
    213219        if ($this->hasValue($key) == true) { 
    214             $this->doRemoveValue($key); 
    215         } 
     220            return $this->doRemoveValue($key); 
     221        } 
     222         
     223        return false; 
    216224    } 
    217225     
     
    219227     * removes a value from the session 
    220228     * 
    221      * @param  string  $key  key where value is stored under 
     229     * @param   string  $key  key where value is stored under 
     230     * @return  bool   true if value existed and was removed, else false 
    222231     */ 
    223232    protected abstract function doRemoveValue($key); 
  • trunk/src/main/php/net/stubbles/ipo/session/stubPHPSession.php

    r138 r153  
    6464    { 
    6565        $this->reset(); 
    66        @session_destroy(); 
    67        @session_start(); 
     66        @session_destroy(); 
     67        @session_start(); 
    6868    } 
    6969     
     
    114114     * removes a value from the session 
    115115     * 
    116      * @param  string  $key  key where value is stored under 
     116     * @param   string  $key  key where value is stored under 
     117     * @return  bool    true if value existed and was removed, else false 
    117118     */ 
    118119    protected function doRemoveValue($key) 
    119120    { 
    120121        unset($_SESSION[$key]); 
     122        return true; 
    121123    } 
    122124     
  • trunk/src/main/php/net/stubbles/ipo/session/stubSession.php

    r138 r153  
    7474     
    7575    /** 
    76      * switch for disabling creation of a new token 
    77      *  
    78      * @param  bool  $recreateToken  FALSE if no new token should be created 
    79      */ 
    80     public function recreateToken($recreateToken); 
    81      
    82     /** 
    8376     * checks if this session is valid 
    8477     * 
     
    129122     * 
    130123     * @param   string  $key  key where value is stored under 
     124     * @return  bool    true if value existed and was removed, else false 
    131125     * @throws  stubSessionException 
    132126     */ 
  • trunk/src/test/php/net/stubbles/ipo/IPOTestSuite.php

    r113 r153  
    3434         
    3535        $this->addTestFile($dir . '/response/stubCookieTestCase.php'); 
     36         
     37        $this->addTestFile($dir . '/session/stubBaseSessionTestCase.php'); 
    3638    } 
    3739}