Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ID#336: migrated mcrypt to openssl module for user attribute encrypti…
…on in UMGT. IMPORTANT: This is a breaking change! Manual migration is required: - Load and decrypt all users - Save all users w/ unencrypted values - Update APF - Load all users and save w/ encrypted values For details, please see migration documentation.
- Loading branch information
Christian Achatz
committed
Aug 12, 2018
1 parent
36d1873
commit 04ece24
Showing
2 changed files
with
199 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
tests/suites/modules/usermanagement/biz/provider/UserFieldEncryptionProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php | ||
/** | ||
* <!-- | ||
* This file is part of the adventure php framework (APF) published under | ||
* https://adventure-php-framework.org. | ||
* | ||
* The APF is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The APF is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with the APF. If not, see http://www.gnu.org/licenses/lgpl-3.0.txt. | ||
* --> | ||
*/ | ||
namespace APF\tests\suites\modules\usermanagement\biz\provider; | ||
|
||
use APF\modules\usermanagement\biz\model\UmgtUser; | ||
use APF\modules\usermanagement\biz\provider\UserFieldEncryptionProvider; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class UserFieldEncryptionProviderTest extends TestCase { | ||
|
||
public static function setUpBeforeClass() { | ||
ini_set('error_reporting', E_ALL & ~E_DEPRECATED); | ||
} | ||
|
||
public static function tearDownAfterClass() { | ||
ini_set('error_reporting', E_ALL); | ||
} | ||
|
||
public function testEncrypt() { | ||
$this->assertEquals('Q7N1fzCJIAczFsyzG+Mz5w==', UserFieldEncryptionProvider::encrypt('foo')); | ||
$this->assertEquals('', UserFieldEncryptionProvider::encrypt('')); | ||
} | ||
|
||
public function testDecrypt() { | ||
$this->assertEquals('foo', UserFieldEncryptionProvider::decrypt('Q7N1fzCJIAczFsyzG+Mz5w==')); | ||
$this->assertEquals('', UserFieldEncryptionProvider::decrypt('')); | ||
} | ||
|
||
public function testPropertyHasEncryptionEnabled() { | ||
$this->assertFalse(UserFieldEncryptionProvider::propertyHasEncryptionEnabled('foo')); | ||
|
||
UserFieldEncryptionProvider::$encryptedFieldNames = ['Username']; | ||
$this->assertFalse(UserFieldEncryptionProvider::propertyHasEncryptionEnabled('FirstName')); | ||
$this->assertTrue(UserFieldEncryptionProvider::propertyHasEncryptionEnabled('Username')); | ||
|
||
UserFieldEncryptionProvider::$encryptedFieldNames = null; | ||
} | ||
|
||
public function testEncryptProperties1() { | ||
|
||
$user = new UmgtUser(); | ||
|
||
$firstName = 'First name'; | ||
$userName = 'User name'; | ||
$user->setFirstName($firstName); | ||
$user->setUsername($userName); | ||
UserFieldEncryptionProvider::$encryptedFieldNames = ['Username']; | ||
UserFieldEncryptionProvider::encryptProperties($user); | ||
|
||
$this->assertEquals($firstName, $user->getFirstName()); | ||
$this->assertNotEquals($userName, $user->getUsername()); | ||
$this->assertEquals('8Xx3rHFKdWCnAwUrV0rq9A==', $user->getUsername()); | ||
|
||
UserFieldEncryptionProvider::$encryptedFieldNames = null; | ||
|
||
} | ||
|
||
public function testEncryptProperties2() { | ||
|
||
$user = new UmgtUser(); | ||
|
||
$firstName = 'First name'; | ||
$userName = 'User name'; | ||
$user->setFirstName($firstName); | ||
$user->setUsername($userName); | ||
UserFieldEncryptionProvider::$encryptedFieldNames = null; | ||
UserFieldEncryptionProvider::encryptProperties($user); | ||
|
||
$this->assertEquals($firstName, $user->getFirstName()); | ||
$this->assertEquals($userName, $user->getUsername()); | ||
|
||
UserFieldEncryptionProvider::$encryptedFieldNames = null; | ||
|
||
} | ||
|
||
public function testDecryptProperties1() { | ||
|
||
$user = new UmgtUser(); | ||
|
||
$firstName = 'First name'; | ||
$userName = '8Xx3rHFKdWCnAwUrV0rq9A=='; | ||
$user->setFirstName($firstName); | ||
$user->setUsername($userName); | ||
UserFieldEncryptionProvider::$encryptedFieldNames = ['Username']; | ||
UserFieldEncryptionProvider::decryptProperties($user); | ||
|
||
$this->assertEquals($firstName, $user->getFirstName()); | ||
$this->assertNotEquals($userName, $user->getUsername()); | ||
$this->assertEquals('User name', $user->getUsername()); | ||
|
||
UserFieldEncryptionProvider::$encryptedFieldNames = null; | ||
} | ||
|
||
public function testDecryptProperties2() { | ||
|
||
$user = new UmgtUser(); | ||
|
||
$firstName = 'First name'; | ||
$userName = 's0FvKrPjZPkY1mXKhU2tHQ=='; | ||
$user->setFirstName($firstName); | ||
$user->setUsername($userName); | ||
UserFieldEncryptionProvider::$encryptedFieldNames = null; | ||
UserFieldEncryptionProvider::decryptProperties($user); | ||
|
||
$this->assertEquals($firstName, $user->getFirstName()); | ||
$this->assertEquals($userName, $user->getUsername()); | ||
|
||
UserFieldEncryptionProvider::$encryptedFieldNames = null; | ||
} | ||
|
||
} |