public function testAgent() { $safe = new Safe(); $safe->setCreated(); $safe->setUpdated(); $keyPair = $safe->generateKeyPair(); $safe->setName('TestSafeName'); $safe->setPublicKey($keyPair->getPublicKey()); $this->getEntityManager()->persist($safe); $this->getEntityManager()->flush(); $secret = new Secret(); $secret->setCreated(); $secret->setUpdated(); $keyName = 'foo'; $value = 'bar'; $secret->setKey($keyName); $secret->setValue($keyPair->getPublicKey(), $value); $safeRef = $this->getEntityManager()->getReference(get_class($safe), $safe->getId()); $secret->setSafe($safeRef); $this->getEntityManager()->persist($secret); $this->getEntityManager()->flush(); $callback = function ($safeName) use($keyPair) { return $keyPair->getPrivateKey()->getKey(); }; $Agent = new Agent(); $Agent->setContainer($this->getContainer()); $Agent->setSafe($safe); $Agent->setPrivateKeyCallback($callback); $this->assertEquals($value, $Agent->getKey($keyName)); }
public function testDelete() { $safe = new Safe(); $keyPair = $safe->generateKeyPair(); $safe->setName(__CLASS__ . __METHOD__); $safe->setPublicKey($keyPair->getPublicKey()); $safe->setCreated(); $safe->setUpdated(); parent::remove($safe, array('name' => __CLASS__ . __METHOD__)); }
/** * @param $name * @return PrivateKey */ public function create($name) { $repository = $this->getEntityManager()->getRepository('Portunus\\Model\\Safe'); $safe = $repository->findOneBy(array('name' => $name)); if (!$safe) { $safe = new Safe(); $safe->setCreated(); } $keyPair = $safe->generateKeyPair(); $safe->setName($name); $safe->setPublicKey($keyPair->getPublicKey()); $safe->setUpdated(); $this->getEntityManager()->persist($safe); $this->getEntityManager()->flush(); return $keyPair->getPrivateKey(); }
public function testLongSecret() { $safe = new Safe(); $keyPair = $safe->generateKeyPair(); $safe->setName('TestSafeName'); $safe->setPublicKey($keyPair->getPublicKey()); $safe->setCreated(); $safe->setUpdated(); $this->getEntityManager()->persist($safe); $this->getEntityManager()->flush(); $secret = new Secret(); $secret->setCreated(); $secret->setUpdated(); $secret->setKey(__CLASS__ . __METHOD__); // generate enough text to require chunked data $value = str_repeat('a', $keyPair->getPublicKey()->getKeySize() / 8 * 2); $secret->setValue($keyPair->getPublicKey(), $value); $this->assertNotEquals($secret->getValue(), $value); $this->assertEquals($secret->getValue($keyPair->getPrivateKey()), $value); $safeRef = $this->getEntityManager()->getReference(get_class($safe), $safe->getId()); $secret->setSafe($safeRef); parent::remove($secret, array('key' => __CLASS__ . __METHOD__)); }