/** * Provides test instances for all tests. * * @return array the test data */ public function instancesProvider() { $res = array(); $cryptoFactory = new CryptoFactory(); // Session login method (duration: 2 seconds) $storage = new DefaultStorage(new JsonStorageEngine(true, __DIR__ . DIRECTORY_SEPARATOR . 'test.json')); $session = new Session($storage, 'session', '/', null, false, new DefaultCookieTransceiver(), new DefaultCookieTransceiver()); $session->setDuration(2); $sessionLoginMethod = new SessionLoginMethod($session); // Default persistence login method (duration: 5 seconds) $storage = new JsonLoginStorage(__DIR__ . DIRECTORY_SEPARATOR . 'login.json', new Md5HashFunction(), 100, 'mykey'); $transceiver = new DefaultCookieTransceiver(); $defaultPersistenceLoginMethod = new DefaultPersistentLoginMethod($storage, $transceiver); $defaultPersistenceLoginMethod->setDuration(5); // Secure persistence login method (duration: 5 seconds) $storage = new JsonLoginStorage(__DIR__ . DIRECTORY_SEPARATOR . 'login.json', new Md5HashFunction(), 100, 'mykey'); $transceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id'); $securePersistenceLoginMethod = new SecurePersistentLoginMethod($storage, $transceiver); $securePersistenceLoginMethod->setDuration(5); // User storage $userStorageMock = new MockUserStorage(self::GID); $res[] = array(new Login($sessionLoginMethod, $defaultPersistenceLoginMethod, $userStorageMock)); $res[] = array(new Login($sessionLoginMethod, $securePersistenceLoginMethod, $userStorageMock)); return $res; }
/** * Tests getting an symmetric cypher. * * @dataProvider getHashFunctionProvider * @covers empire\framework\crypto\CryptoFactory::getHashFunction * * @param string $name the name of the asymmetric cypher * @param boolean $exists whether the cypher exists */ public function testGetHashFunction($name, $success) { $function = $this->instance->getHashFunction($name); if ($success) { $this->assertInstanceOf('empire\\framework\\crypto\\hash\\HashFunction', $function); } else { $this->assertNull($function); } }
/** * Tests logout. * * @covers empire\framework\login\SecurePersistentLoginMethod::logout */ public function testLogout() { $gid = '58d93d649ffffffff5331ad0219ea200'; $storage = new JsonLoginStorage(__DIR__ . DIRECTORY_SEPARATOR . 'login.json', new Md5HashFunction(), 100, 'mykey'); $transceiver = new SecureCookieTransceiver(self::$cryptoFactory->getHashFunction('Sha256'), self::$cryptoFactory->getHashFunction('Sha256'), self::$cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id', $gid); $method = new SecurePersistentLoginMethod($storage, $transceiver); $method->setDuration(200); $this->remoteCall('login', $method, $gid); $this->remoteCall('logout', $method); $this->assertNull($this->remoteCall('authenticate', $method)); }
/** * Provides test data for the receive test. * * @return array the test data */ public function receiveProvider() { $cryptoFactory = new CryptoFactory(); $userGID = '58d93d649ffffffff5331ad0219ea200'; $res = array(); $cookie = new Cookie('test1', 0, '/', null, false, false); $cookie->setData('hello world'); $sendTransceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id', $userGID); $receiveTransceiver = $sendTransceiver; $success = true; $res[] = array($cookie, $sendTransceiver, $receiveTransceiver, $success); $cookie = new Cookie('test2', 0, '/', null, false, true); $sendTransceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id', $userGID); $receiveTransceiver = $sendTransceiver; $success = true; $res[] = array($cookie, $sendTransceiver, $receiveTransceiver, $success); $cookie = new Cookie('test3', 0, '/false', null, false, false); $sendTransceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id', $userGID); $receiveTransceiver = $sendTransceiver; $success = false; $res[] = array($cookie, $sendTransceiver, $receiveTransceiver, $success); $cookie = new Cookie('test', 0, '/', 'wrongdomain', false, false); $sendTransceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id', $userGID); $receiveTransceiver = $sendTransceiver; $success = false; $res[] = array($cookie, $sendTransceiver, $receiveTransceiver, $success); $cookie = new Cookie('test', 0, '/', null, true, false); $sendTransceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id', $userGID); $receiveTransceiver = $sendTransceiver; $success = false; $res[] = array($cookie, $sendTransceiver, $receiveTransceiver, $success); $cookie = new Cookie('test', 0, '/', null, false, false); $sendTransceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id1', $userGID); $receiveTransceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id2', $userGID); $success = false; $res[] = array($cookie, $sendTransceiver, $receiveTransceiver, $success); $cookie = new Cookie('test', 0, '/', null, false, false); $sendTransceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id', $userGID); $receiveTransceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id'); $success = true; $res[] = array($cookie, $sendTransceiver, $receiveTransceiver, $success); $cookie = new Cookie('test27', 0, '/', null, false, false); $sendTransceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id', $userGID); $receiveTransceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id', 'wrong gid'); $success = false; $res[] = array($cookie, $sendTransceiver, $receiveTransceiver, $success); $cookie = new Cookie('test', 0, '/', null, false, false); $sendTransceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id', $userGID); $receiveTransceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key2', new GID(), 'session id'); $success = false; $res[] = array($cookie, $sendTransceiver, $receiveTransceiver, $success); $cookie = new Cookie('test', 0, '/', null, false, false); $sendTransceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id', $userGID); $receiveTransceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha512'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id'); $success = false; $res[] = array($cookie, $sendTransceiver, $receiveTransceiver, $success); $cookie = new Cookie('test', 0, '/', null, false, false); $sendTransceiver = new SecureCookieTransceiver($cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getHashFunction('Sha256'), $cryptoFactory->getSymmetricCypher('Aes256'), 'secret key', new GID(), 'session id', $userGID); $receiveTransceiver = new DefaultCookieTransceiver(); $success = false; $res[] = array($cookie, $sendTransceiver, $receiveTransceiver, $success); return $res; }