[Cs-webapplibs-commits] SF.net SVN: cs-webapplibs:[133] trunk/0.3
Status: Beta
Brought to you by:
crazedsanity
From: <cra...@us...> - 2009-08-21 16:45:17
|
Revision: 133 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=133&view=rev Author: crazedsanity Date: 2009-08-21 16:45:10 +0000 (Fri, 21 Aug 2009) Log Message: ----------- Modified Paths: -------------- trunk/0.3/cs_authToken.class.php trunk/0.3/tests/testOfCSWebAppLibs.php Modified: trunk/0.3/cs_authToken.class.php =================================================================== --- trunk/0.3/cs_authToken.class.php 2009-08-21 16:34:42 UTC (rev 132) +++ trunk/0.3/cs_authToken.class.php 2009-08-21 16:45:10 UTC (rev 133) @@ -298,19 +298,22 @@ public function remove_expired_tokens() { $sql = "SELECT * FROM ". $this->table ." WHERE NOW() > expiration"; + $destroyedTokens = 0; try { $data = $this->db->run_query($sql, 'auth_token_id'); if(is_array($data)) { foreach($data as $tokenId => $tokenData) { //TODO: add logging here? - $this->destroy_token($tokenId); + $destroyedTokens += $this->destroy_token($tokenId); } } } catch(exception $e) { throw new exception(__METHOD__ .": error encountered while expiring tokens::: ". $e->getMessage()); } + + return($destroyedTokens); }//end remove_expired_tokens() //========================================================================= Modified: trunk/0.3/tests/testOfCSWebAppLibs.php =================================================================== --- trunk/0.3/tests/testOfCSWebAppLibs.php 2009-08-21 16:34:42 UTC (rev 132) +++ trunk/0.3/tests/testOfCSWebAppLibs.php 2009-08-21 16:45:10 UTC (rev 133) @@ -178,6 +178,22 @@ $this->assertNotEqual($tokenData['hash'], $tok->doHash($tokenData['id'], $uid, $checksum, $hashThis), "hash is guessable"); } + + //test expiring tokens... + { + //create a token that is immediately expired. + $tokenData = $tok->create_token(22, 'token expiration test', 'Lorem ipsum dolor sit amet, consectetur.', '-5 days'); + $this->do_tokenTest($tokenData, 22, 'token expiration test'); + + $this->assertFalse(is_array($tok->tokenData($tokenData['id'], true))); + $this->assertTrue(is_array($tok->tokenData($tokenData['id'], false))); + $this->assertTrue(count($tok->tokenData($tokenData['id'],false)) == 9); + + //REMEMBER: we've created other tokens that will now expire... + $removedTokens = $tok->remove_expired_tokens(); + $this->assertEqual(2, $removedTokens); + } + }//end test_token_basics() //-------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |