Skip to content

Commit

Permalink
Making Security a static class.
Browse files Browse the repository at this point in the history
Fixing static access issues in test case.
  • Loading branch information
markstory committed Apr 24, 2010
1 parent 33bfe0e commit 8400268
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 36 deletions.
26 changes: 4 additions & 22 deletions cake/libs/security.php
Expand Up @@ -24,30 +24,15 @@
* @package cake
* @subpackage cake.cake.libs
*/
class Security extends Object {
class Security {

/**
* Default hash method
*
* @var string
* @access public
*/
public $hashType = null;

/**
* Singleton implementation to get object instance.
*
* @return object
* @access public
* @static
*/
function &getInstance() {
static $instance = array();
if (!$instance) {
$instance[0] =& new Security;
}
return $instance[0];
}
public static $hashType = null;

/**
* Get allowed minutes of inactivity based on security level.
Expand Down Expand Up @@ -111,8 +96,6 @@ function validateAuthKey($authKey) {
* @static
*/
public static function hash($string, $type = null, $salt = false) {
$_this =& Security::getInstance();

if ($salt) {
if (is_string($salt)) {
$string = $salt . $string;
Expand All @@ -122,7 +105,7 @@ public static function hash($string, $type = null, $salt = false) {
}

if (empty($type)) {
$type = $_this->hashType;
$type = self::$hashType;
}
$type = strtolower($type);

Expand Down Expand Up @@ -155,8 +138,7 @@ public static function hash($string, $type = null, $salt = false) {
* @see Security::hash()
*/
public static function setHash($hash) {
$_this =& Security::getInstance();
$_this->hashType = $hash;
self::$hashType = $hash;
}

/**
Expand Down
17 changes: 3 additions & 14 deletions cake/tests/cases/libs/security.test.php
Expand Up @@ -35,16 +35,6 @@ class SecurityTest extends CakeTestCase {
*/
public $sut = null;

/**
* setUp method
*
* @access public
* @return void
*/
function setUp() {
$this->sut =& Security::getInstance();
}

/**
* testInactiveMins method
*
Expand Down Expand Up @@ -90,8 +80,7 @@ function testValidateAuthKey() {
* @return void
*/
function testHash() {
$Security =& Security::getInstance();
$_hashType = $Security->hashType;
$_hashType = Security::$hashType;

$key = 'someKey';
$hash = 'someHash';
Expand All @@ -109,7 +98,7 @@ function testHash() {

$hashType = 'sha1';
Security::setHash($hashType);
$this->assertIdentical($this->sut->hashType, $hashType);
$this->assertIdentical(Security::$hashType, $hashType);
$this->assertIdentical(strlen(Security::hash($key, null, true)), 40);
$this->assertIdentical(strlen(Security::hash($key, null, false)), 40);

Expand All @@ -118,7 +107,7 @@ function testHash() {

$hashType = 'md5';
Security::setHash($hashType);
$this->assertIdentical($this->sut->hashType, $hashType);
$this->assertIdentical(Security::$hashType, $hashType);
$this->assertIdentical(strlen(Security::hash($key, null, false)), 32);
$this->assertIdentical(strlen(Security::hash($key, null, true)), 32);

Expand Down

0 comments on commit 8400268

Please sign in to comment.