Beispiel #1
0
 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));
 }
Beispiel #2
0
 public function create(Safe $safe, $key, $value)
 {
     $repository = $this->getEntityManager()->getRepository('Portunus\\Model\\Secret');
     $secret = $repository->findOneBy(array('safe' => $safe, 'key' => $key));
     if (!$secret) {
         $secret = new Secret();
         $secret->setCreated();
     }
     $safeRef = $this->getEntityManager()->getReference('Portunus\\Model\\Safe', $safe->getId());
     $secret->setSafe($safeRef);
     $secret->setKey($key);
     $secret->setValue($safe->getPublicKey(), $value);
     $secret->setUpdated();
     $this->getEntityManager()->persist($secret);
     $this->getEntityManager()->flush();
 }
Beispiel #3
0
 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__));
 }