mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Adding Security.cipherSeed generation to bake project task, closes #237
This commit is contained in:
parent
c2d19c2011
commit
0387907d6d
2 changed files with 48 additions and 0 deletions
|
@ -90,6 +90,12 @@ class ProjectTask extends Shell {
|
||||||
$this->err(sprintf(__('Unable to generate random hash for \'Security.salt\', you should change it in %s', true), CONFIGS . 'core.php'));
|
$this->err(sprintf(__('Unable to generate random hash for \'Security.salt\', you should change it in %s', true), CONFIGS . 'core.php'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->securityCipherSeed($path) === true ) {
|
||||||
|
$this->out(__('Random seed created for \'Security.cipherSeed\'', true));
|
||||||
|
} else {
|
||||||
|
$this->err(sprintf(__('Unable to generate random seed for \'Security.cipherSeed\', you should change it in %s', true), CONFIGS . 'core.php'));
|
||||||
|
}
|
||||||
|
|
||||||
$corePath = $this->corePath($path);
|
$corePath = $this->corePath($path);
|
||||||
if ($corePath === true ) {
|
if ($corePath === true ) {
|
||||||
$this->out(sprintf(__('CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', true), CAKE_CORE_INCLUDE_PATH));
|
$this->out(sprintf(__('CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', true), CAKE_CORE_INCLUDE_PATH));
|
||||||
|
@ -215,6 +221,30 @@ class ProjectTask extends Shell {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates and writes 'Security.cipherSeed'
|
||||||
|
*
|
||||||
|
* @param string $path Project path
|
||||||
|
* @return boolean Success
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function securityCipherSeed($path) {
|
||||||
|
$File =& new File($path . 'config' . DS . 'core.php');
|
||||||
|
$contents = $File->read();
|
||||||
|
if (preg_match('/([\\t\\x20]*Configure::write\\(\\\'Security.cipherSeed\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) {
|
||||||
|
if (!class_exists('Security')) {
|
||||||
|
require LIBS . 'security.php';
|
||||||
|
}
|
||||||
|
$string = substr(bin2hex(Security::generateAuthKey()), 0, 30);
|
||||||
|
$result = str_replace($match[0], "\t" . 'Configure::write(\'Security.cipherSeed\', \''.$string.'\');', $contents);
|
||||||
|
if ($File->write($result)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates and writes CAKE_CORE_INCLUDE_PATH
|
* Generates and writes CAKE_CORE_INCLUDE_PATH
|
||||||
*
|
*
|
||||||
|
|
|
@ -173,6 +173,24 @@ class ProjectTaskTest extends CakeTestCase {
|
||||||
$this->assertNoPattern('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s');
|
$this->assertNoPattern('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test generation of Security.salt
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function testSecurityCipherSeedGeneration() {
|
||||||
|
$this->_setupTestProject();
|
||||||
|
|
||||||
|
$path = $this->Task->path . 'bake_test_app' . DS;
|
||||||
|
$result = $this->Task->securityCipherSeed($path);
|
||||||
|
$this->assertTrue($result);
|
||||||
|
|
||||||
|
$file =& new File($path . 'config' . DS . 'core.php');
|
||||||
|
$contents = $file->read();
|
||||||
|
$this->assertNoPattern('/76859309657453542496749683645/', $contents, 'Default Salt left behind. %s');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that index.php is generated correctly.
|
* Test that index.php is generated correctly.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue