diff --git a/FileCookie.php b/FileCookie.php index 8e23a9d..1e1f6b7 100644 --- a/FileCookie.php +++ b/FileCookie.php @@ -26,8 +26,8 @@ class FileCookie public function __construct($ident, $rand) { global $conf; - $path = $conf['tmpdir'] . '/captcha/' . date('Y-m-d') . '/' . md5($ident . $rand) . '.cookie'; - io_makeFileDir($path); + $this->path = $conf['tmpdir'] . '/captcha/' . date('Y-m-d') . '/' . md5($ident . $rand) . '.cookie'; + io_makeFileDir($this->path); } /** diff --git a/_test/HelperTest.php b/_test/HelperTest.php index 42de482..ad37189 100644 --- a/_test/HelperTest.php +++ b/_test/HelperTest.php @@ -2,6 +2,7 @@ namespace dokuwiki\plugin\captcha\test; +use dokuwiki\plugin\captcha\FileCookie; use DokuWikiTest; /** @@ -57,7 +58,8 @@ public function testCheck() $rand = 0; $code = $helper->generateCaptchaCode($helper->fixedIdent(), $rand); - $this->callInaccessibleMethod($helper, 'storeCaptchaCookie', [$helper->fixedIdent(), $rand]); + $cookie = new FileCookie($helper->fixedIdent(), $rand); + $cookie->set(); // check with missing secrect -> fail $INPUT->set($this->getInaccessibleProperty($helper, 'field_in'), $code); @@ -71,7 +73,7 @@ public function testCheck() $this->assertFalse($helper->check(true)); // set the cookie but change the ID -> fail - $this->callInaccessibleMethod($helper, 'storeCaptchaCookie', [$helper->fixedIdent(), $rand]); + $cookie->set(); $ID = 'test:fail'; $this->assertFalse($helper->check(false)); } @@ -104,7 +106,8 @@ public function testCleanup() $this->assertEquals(array(), $dirs); // store a cookie - $this->callInaccessibleMethod($helper, 'storeCaptchaCookie', ['test', 0]); + $cookie = new FileCookie('test', 0); + $cookie->set(); // nothing but today's data $dirs = glob("$path/*"); @@ -130,7 +133,7 @@ public function testCleanup() ); // clean up - $helper->cleanCaptchaCookies(); + FileCookie::clean(); // nothing but today's data $dirs = glob("$path/*"); diff --git a/helper.php b/helper.php index 65f1ca5..2543a27 100644 --- a/helper.php +++ b/helper.php @@ -194,7 +194,8 @@ protected function generateMagicCode($ident, $rand) { $ident = hexdec(substr(md5($ident), 5, 5)); // use part of the md5 to generate an int $rand *= 0xFFFFF; // bitmask from the random number - return md5($rand ^ $ident); // combine both values + $comb = (int) $rand ^ $ident; // combine both values + return md5($comb); } /**