private function init_phpSec() { require_once 'application/libraries/phpSec-0.6.1/phpSec-0.6.1/lib/phpSec/bootstrap.php'; $psl = new phpSec\Core(); $psl['store'] = $psl->share(function ($psl) { return new phpSec\Store\File('uploads/phpSec', $psl); }); $this->psl = $psl; }
public function testKeyValid() { $psl = new \phpSec\Core(); $psl['store'] = $psl->share(function ($psl) { return new \phpSec\Store\File(sys_get_temp_dir(), $psl); }); $google = $psl['auth/google']; $key = $google->newKey(); $token = $google->getToken($key); $this->assertTrue($google->verify($token, $key)); $this->assertFalse($google->verify($token, $key)); }
public function testToken() { $psl = new \phpSec\Core(); $psl['store'] = $psl->share(function ($psl) { return new \phpSec\Store\File(sys_get_temp_dir(), $psl); }); $token = $psl['common/token']; $csrf = $token->set('test'); $this->assertTrue(strlen($csrf) == 32); $this->assertTrue($token->validate('test', $csrf)); $this->assertFalse($token->validate('test', $csrf)); }
public function testCache() { $psl = new \phpSec\Core(); $psl['store'] = $psl->share(function ($psl) { return new \phpSec\Store\File(sys_get_temp_dir(), $psl); }); $cache = $psl['cache']; $this->assertTrue($cache->cacheSet('name', 'data', 3)); $data = $cache->cacheGet('name'); $this->assertEquals('data', $data); sleep(4); $this->assertFalse($cache->cacheGet('name')); }
public function testOtp() { $psl = new \phpSec\Core(); $psl['store'] = $psl->share(function ($psl) { return new \phpSec\Store\File(sys_get_temp_dir(), $psl); }); $otp = $psl['auth/otp']; $pw = $otp->generate('f00'); $this->assertTrue(strlen($pw) == 6); $this->assertFalse($otp->validate($pw, 'baz')); $this->assertFalse($otp->validate($pw . '-invalid', 'f00')); $this->assertTrue($otp->validate($pw, 'f00')); $this->assertFalse($otp->validate($pw, 'f00')); }