コード例 #1
0
 /**
  * Instantiates the encryption utility object so that components depending
  * on {@link EncryptedFieldsBehavior} can also be instantiated.
  */
 public function cryptInit()
 {
     if (!$this->_cryptInit) {
         $key = $this->owner->basePath . '/config/encryption.key';
         $iv = $this->owner->basePath . '/config/encryption.iv';
         if (extension_loaded('openssl') && extension_loaded('mcrypt') && file_exists($key) && file_exists($iv)) {
             EncryptedFieldsBehavior::setup($key, $iv);
         } else {
             // Use unsafe method with encryption
             EncryptedFieldsBehavior::setupUnsafe();
         }
     }
 }
コード例 #2
0
 /**
  * Override that uses a specific key/iv for unit testing
  */
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     EncryptedFieldsBehavior::setupUnsafe();
 }
コード例 #3
0
ファイル: CredentialsTest.php プロジェクト: keyeMyria/CRM
 /**
  * Tests transparent transition between encrypted and unencrypted
  */
 public function testUnsafe()
 {
     $cred = $this->credentials('testUser');
     $expectedAttributes = $cred->auth->attributes;
     EncryptedFieldsBehavior::setupUnsafe();
     $cred->save();
     $unencryptedJSON = Yii::app()->db->createCommand()->select('auth')->from('x2_credentials')->where('id=:id', array(':id' => $cred->id))->queryScalar();
     $attributes = CJSON::decode($unencryptedJSON);
     $this->assertEquals($expectedAttributes, $attributes);
 }