Exemplo n.º 1
0
 public function testEncodeDecodeDifferentInstances()
 {
     $someData = 'someValue';
     $encrypted = $this->encryptor->encryptData($someData);
     $newInstance = $this->getInstance();
     $this->assertEquals($someData, $newInstance->decryptData($encrypted));
 }
Exemplo n.º 2
0
 /**
  * Pre submit event listener
  * Encrypt passwords and populate if empty
  * Populate websites choices from hidden fields
  *
  * @param FormEvent $event
  */
 public function preSubmit(FormEvent $event)
 {
     $data = (array) $event->getData();
     $form = $event->getForm();
     $oldPassword = $form->get('apiKey')->getData();
     if (empty($data['apiKey']) && $oldPassword) {
         // populate old password
         $data['apiKey'] = $oldPassword;
     } elseif (isset($data['apiKey'])) {
         $data['apiKey'] = $this->encryptor->encryptData($data['apiKey']);
     }
     // first time all websites comes from frontend(when run sync action)
     // otherwise loaded from entity
     if (!empty($data['websites'])) {
         $websites = $data['websites'];
         // reverseTransform, but not set back to event
         if (!is_array($websites)) {
             $websites = json_decode($websites, true);
         }
         $modifier = $this->getModifierWebsitesList($websites);
         $modifier($form);
     }
     $this->muteFields($form);
     $event->setData($data);
 }
Exemplo n.º 3
0
 /**
  * @param array $options
  *
  * @return callable
  */
 protected function getEncryptClosure($options)
 {
     $enc = $this->encryptor;
     $isEncode = !empty($options['encode']) && $options['encode'];
     return function (FormEvent $event) use($enc, $isEncode) {
         $form = $event->getForm();
         $password = $event->getData();
         $oldPassword = $form->getData();
         if (empty($password) && $oldPassword) {
             // populate old password
             $password = $oldPassword;
         } elseif (!empty($password) && $isEncode) {
             $password = $this->encryptor->encryptData($password);
         }
         $event->setData($password);
     };
 }
Exemplo n.º 4
0
 /**
  * @dataProvider keyDataProvider
  * @param string $key
  */
 public function testEncodeDecodeDifferentInstances($key)
 {
     $someData = 'someValue';
     $encryptor = new Mcrypt($key);
     $encrypted = $encryptor->encryptData($someData);
     $this->assertNotEquals($someData, $encrypted);
     $newInstance = new Mcrypt($key);
     $this->assertEquals($someData, $newInstance->decryptData($encrypted));
 }