Base64 encode token strings to allow them to contain newlines.
authorGunnar Wrobel <p@rdus.de>
Thu, 16 Dec 2010 14:32:08 +0000 (15:32 +0100)
committerGunnar Wrobel <p@rdus.de>
Thu, 16 Dec 2010 14:32:08 +0000 (15:32 +0100)
The initial timestamp that was recently added to the tokens may
match the binary representation of a newline which kills the file
based token driver (which is line oriented).

Should fix the flaky token test.

framework/Token/lib/Horde/Token/File.php

index e445552..c29f77f 100644 (file)
@@ -93,10 +93,11 @@ class Horde_Token_File extends Horde_Token_Base
         $this->_connect();
 
         /* Find already used IDs. */
+        $token = base64_encode($tokenID);
         $fileContents = file($this->_params['token_dir'] . '/conn_' . $this->_encodeRemoteAddress());
         if ($fileContents) {
             for ($i = 0, $iMax = count($fileContents); $i < $iMax; ++$i) {
-                if (chop($fileContents[$i]) == $tokenID) {
+                if (chop($fileContents[$i]) == $token) {
                     return true;
                 }
             }
@@ -117,7 +118,8 @@ class Horde_Token_File extends Horde_Token_Base
         $this->_connect();
 
         /* Write the entry. */
-        fwrite($this->_fd, $tokenID . "\n");
+        $token = base64_encode($tokenID);
+        fwrite($this->_fd, $token . "\n");
 
         $this->_disconnect();
     }