예제 #1
0
 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;
 }
예제 #2
0
 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));
 }
예제 #3
0
 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));
 }
예제 #4
0
 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'));
 }
예제 #5
0
파일: OtpTest.php 프로젝트: z0x/phpSec
 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'));
 }