[Cs-webapplibs-commits] SF.net SVN: cs-webapplibs:[111] trunk/0.3
Status: Beta
Brought to you by:
crazedsanity
From: <cra...@us...> - 2009-08-19 17:44:19
|
Revision: 111 http://cs-webapplibs.svn.sourceforge.net/cs-webapplibs/?rev=111&view=rev Author: crazedsanity Date: 2009-08-19 17:44:04 +0000 (Wed, 19 Aug 2009) Log Message: ----------- Testing of cs_authToken & ability to create a token. Modified Paths: -------------- trunk/0.3/cs_authToken.class.php trunk/0.3/setup/authtoken_schema.pgsql.sql trunk/0.3/tests/testOfAuthToken.php Modified: trunk/0.3/cs_authToken.class.php =================================================================== --- trunk/0.3/cs_authToken.class.php 2009-08-19 17:14:22 UTC (rev 110) +++ trunk/0.3/cs_authToken.class.php 2009-08-19 17:44:04 UTC (rev 111) @@ -18,6 +18,15 @@ /** Database object. */ private $db; + /** Object that helps deal with strings. */ + private $gfObj; + + /** Name of the table */ + private $table = 'cswal_auth_token_table'; + + /** Sequence name for the given table (for PostgreSQL) */ + private $seq = 'cswal_auth_token_table_auth_token_id_seq'; + //========================================================================= public function __construct(cs_phpDB $db) { @@ -27,6 +36,7 @@ else { throw new exception(__METHOD__ .": database object not connected"); } + $this->gfObj = new cs_globalFunctions(); }//end __construct() //========================================================================= @@ -54,7 +64,46 @@ //========================================================================= + protected function create_hash_string($tokenId, $uid, $checksum, $stringToHash=NULL) { + return(md5($tokenId ."_". $uid ."_". $checksum ."_". $stringToHash)); + }//end create_hash_string() //========================================================================= + + + //========================================================================= + public function create_token($uid, $checksum, $stringToHash) { + + $this->db->beginTrans(); + + $insertData = array( + 'uid' => $uid, + 'checksum' => $checksum, + 'token' => '____INCOMPLETE____' + ); + try { + $sql = "INSERT INTO cswal_auth_token_table ". + $this->gfObj->string_from_array($insertData, 'insert', null, 'sql'); + $tokenId = $this->db->run_insert($sql, $this->seq); + + //now that we have the ID, let's create the real has string. + $finalHash = $this->create_hash_string($tokenId, $uid, $checksum, $stringToHash); + + $this->db->run_update("UPDATE ". $this->table ." SET token='". $finalHash ."' WHERE " . + "auth_token_id=". $tokenId); + + $tokenInfo = array( + 'id' => $tokenId, + 'hash' => $finalHash + ); + } + catch(exception $e) { + throw new exception(__METHOD__ .": failed to create token::: ". $e->getMessage()); + } + + return($tokenInfo); + }//end create_token() + //========================================================================= + } ?> Modified: trunk/0.3/setup/authtoken_schema.pgsql.sql =================================================================== --- trunk/0.3/setup/authtoken_schema.pgsql.sql 2009-08-19 17:14:22 UTC (rev 110) +++ trunk/0.3/setup/authtoken_schema.pgsql.sql 2009-08-19 17:44:04 UTC (rev 111) @@ -13,6 +13,8 @@ uid integer NOT NULL DEFAULT 0, checksum text NOT NULL, token text NOT NULL, + use_limit integer DEFAULT NULL, + total_uses integer NOT NULL DEFAULT 0, creation date NOT NULL DEFAULT NOW(), duration interval NOT NULL DEFAULT '1 day'::interval ); \ No newline at end of file Modified: trunk/0.3/tests/testOfAuthToken.php =================================================================== --- trunk/0.3/tests/testOfAuthToken.php 2009-08-19 17:14:22 UTC (rev 110) +++ trunk/0.3/tests/testOfAuthToken.php 2009-08-19 17:44:04 UTC (rev 111) @@ -71,7 +71,14 @@ $db = $this->create_db(); $tok = new cs_authToken($db); - + //Generic test to ensure we get the appropriate data back. + $tokenData = $tok->create_token(0, 'test', 'abc123'); + $this->assertTrue(is_array($tokenData)); + $this->assertTrue((count($tokenData) == 2)); + $this->assertTrue(isset($tokenData['id'])); + $this->assertTrue(isset($tokenData['hash'])); + $this->assertTrue(($tokenData['id'] > 0)); + $this->assertTrue((strlen($tokenData['hash']) == 32)); }//end test_basics() //-------------------------------------------------------------------------- } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |