Skip to content
Permalink
Browse files

Adding Security.cipherSeed generation to bake project task, closes #237

  • Loading branch information...
lorenzo committed Jan 24, 2010
1 parent c2d19c2 commit 0387907d6de12d4cd11877b336c7a2bcf4fc281f
Showing with 48 additions and 0 deletions.
  1. +30 −0 cake/console/libs/tasks/project.php
  2. +18 −0 cake/tests/cases/console/libs/tasks/project.test.php
@@ -90,6 +90,12 @@ function execute($project = null) {
$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);
if ($corePath === true ) {
$this->out(sprintf(__('CAKE_CORE_INCLUDE_PATH set to %s in webroot/index.php', true), CAKE_CORE_INCLUDE_PATH));
@@ -215,6 +221,30 @@ function securitySalt($path) {
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
*
@@ -173,6 +173,24 @@ function testSecuritySaltGeneration() {
$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.
*

0 comments on commit 0387907

Please sign in to comment.
You can’t perform that action at this time.