TYPO3 CMS  TYPO3_6-2
SaltFactoryTest.php
Go to the documentation of this file.
1 <?php
3 
24 
30  protected $objectInstance = NULL;
31 
37  protected function setUp() {
39  }
40 
44  public function objectInstanceNotNull() {
45  $this->assertNotNull($this->objectInstance);
46  }
47 
52  $this->assertTrue(is_subclass_of($this->objectInstance, 'TYPO3\\CMS\\Saltedpasswords\\Salt\\AbstractSalt'));
53  }
54 
59  $this->assertTrue(method_exists($this->objectInstance, 'checkPassword'), 'Missing method checkPassword() from interface TYPO3\\CMS\\Saltedpasswords\\Salt\\SaltInterface.');
60  $this->assertTrue(method_exists($this->objectInstance, 'isHashUpdateNeeded'), 'Missing method isHashUpdateNeeded() from interface TYPO3\\CMS\\Saltedpasswords\\Salt\\SaltInterface.');
61  $this->assertTrue(method_exists($this->objectInstance, 'isValidSalt'), 'Missing method isValidSalt() from interface TYPO3\\CMS\\Saltedpasswords\\Salt\\SaltInterface.');
62  $this->assertTrue(method_exists($this->objectInstance, 'isValidSaltedPW'), 'Missing method isValidSaltedPW() from interface TYPO3\\CMS\\Saltedpasswords\\Salt\\SaltInterface.');
63  $this->assertTrue(method_exists($this->objectInstance, 'getHashedPassword'), 'Missing method getHashedPassword() from interface TYPO3\\CMS\\Saltedpasswords\\Salt\\SaltInterface.');
64  $this->assertTrue(method_exists($this->objectInstance, 'getSaltLength'), 'Missing method getSaltLength() from interface TYPO3\\CMS\\Saltedpasswords\\Salt\\SaltInterface.');
65  }
66 
70  public function base64EncodeReturnsProperLength() {
71  // 3 Bytes should result in a 6 char length base64 encoded string
72  // used for MD5 and PHPass salted hashing
73  $byteLength = 3;
74  $reqLengthBase64 = (int)ceil($byteLength * 8 / 6);
76  $this->assertTrue(strlen($this->objectInstance->base64Encode($randomBytes, $byteLength)) == $reqLengthBase64);
77  // 16 Bytes should result in a 22 char length base64 encoded string
78  // used for Blowfish salted hashing
79  $byteLength = 16;
80  $reqLengthBase64 = (int)ceil($byteLength * 8 / 6);
82  $this->assertTrue(strlen($this->objectInstance->base64Encode($randomBytes, $byteLength)) == $reqLengthBase64);
83  }
84 
88  public function objectInstanceForMD5Salts() {
89  $saltMD5 = '$1$rasmusle$rISCgZzpwk3UhDidwXvin0';
91  $this->assertTrue(get_class($this->objectInstance) == 'TYPO3\\CMS\\Saltedpasswords\\Salt\\Md5Salt' || is_subclass_of($this->objectInstance, 'TYPO3\\CMS\\Saltedpasswords\\Salt\\Md5Salt'));
92  }
93 
97  public function objectInstanceForBlowfishSalts() {
98  $saltBlowfish = '$2a$07$abcdefghijklmnopqrstuuIdQV69PAxWYTgmnoGpe0Sk47GNS/9ZW';
99  $this->objectInstance = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance($saltBlowfish);
100  $this->assertTrue(get_class($this->objectInstance) == 'TYPO3\\CMS\\Saltedpasswords\\Salt\\BlowfishSalt' || is_subclass_of($this->objectInstance, 'TYPO3\\CMS\\Saltedpasswords\\Salt\\BlowfishSalt'));
101  }
102 
106  public function objectInstanceForPhpassSalts() {
107  $saltPhpass = '$P$CWF13LlG/0UcAQFUjnnS4LOqyRW43c.';
108  $this->objectInstance = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance($saltPhpass);
109  $this->assertTrue(get_class($this->objectInstance) == 'TYPO3\\CMS\\Saltedpasswords\\Salt\\PhpassSalt' || is_subclass_of($this->objectInstance, 'TYPO3\\CMS\\Saltedpasswords\\Salt\\PhpassSalt'));
110  }
111 
117  if ($defaultClassNameToUse == 'TYPO3\\CMS\\Saltedpasswords\\Salt\\Md5Salt') {
118  $saltedPW = '$P$CWF13LlG/0UcAQFUjnnS4LOqyRW43c.';
119  } else {
120  $saltedPW = '$1$rasmusle$rISCgZzpwk3UhDidwXvin0';
121  }
122  $this->objectInstance = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance($saltedPW);
123  // resetting
125  $this->assertTrue(get_class($this->objectInstance) == $defaultClassNameToUse || is_subclass_of($this->objectInstance, $defaultClassNameToUse));
126  }
127 
128 }
static getSaltingInstance($saltedHash='', $mode=TYPO3_MODE)
Definition: SaltFactory.php:83
static generateRandomBytes($bytesToReturn)