Skip to content
This repository
Browse code

Merge branch '1.3-bake' into 1.3

* 1.3-bake:
  Correcting error message in test
  Adding Security.cipherSeed generation to bake project task, closes #237
  • Loading branch information...
commit 6a0ddb0872168e6709f71adf7324af7efb73c8a3 2 parents 9c24c72 + ddf938c
José Lorenzo Rodríguez authored
30  cake/console/libs/tasks/project.php
@@ -90,6 +90,12 @@ function execute($project = null) {
90 90
 				$this->err(sprintf(__('Unable to generate random hash for \'Security.salt\', you should change it in %s', true), CONFIGS . 'core.php'));
91 91
 			}
92 92
 
  93
+			if ($this->securityCipherSeed($path) === true ) {
  94
+				$this->out(__('Random seed created for \'Security.cipherSeed\'', true));
  95
+			} else {
  96
+				$this->err(sprintf(__('Unable to generate random seed for \'Security.cipherSeed\', you should change it in %s', true), CONFIGS . 'core.php'));
  97
+			}
  98
+
93 99
 			$corePath = $this->corePath($path);
94 100
 			if ($corePath === true ) {
95 101
 				$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) {
215 221
 		return false;
216 222
 	}
217 223
 
  224
+	/**
  225
+	 * Generates and writes 'Security.cipherSeed'
  226
+	 *
  227
+	 * @param string $path Project path
  228
+	 * @return boolean Success
  229
+	 * @access public
  230
+	 */
  231
+		function securityCipherSeed($path) {
  232
+			$File =& new File($path . 'config' . DS . 'core.php');
  233
+			$contents = $File->read();
  234
+			if (preg_match('/([\\t\\x20]*Configure::write\\(\\\'Security.cipherSeed\\\',[\\t\\x20\'A-z0-9]*\\);)/', $contents, $match)) {
  235
+				if (!class_exists('Security')) {
  236
+					require LIBS . 'security.php';
  237
+				}
  238
+				$string = substr(bin2hex(Security::generateAuthKey()), 0, 30);
  239
+				$result = str_replace($match[0], "\t" . 'Configure::write(\'Security.cipherSeed\', \''.$string.'\');', $contents);
  240
+				if ($File->write($result)) {
  241
+					return true;
  242
+				}
  243
+				return false;
  244
+			}
  245
+			return false;
  246
+		}
  247
+
218 248
 /**
219 249
  * Generates and writes CAKE_CORE_INCLUDE_PATH
220 250
  *
18  cake/tests/cases/console/libs/tasks/project.test.php
@@ -173,6 +173,24 @@ function testSecuritySaltGeneration() {
173 173
 		$this->assertNoPattern('/DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi/', $contents, 'Default Salt left behind. %s');
174 174
 	}
175 175
 
  176
+	/**
  177
+	 * test generation of Security.salt
  178
+	 *
  179
+	 * @return void
  180
+	 * @access public
  181
+	 */
  182
+		function testSecurityCipherSeedGeneration() {
  183
+			$this->_setupTestProject();
  184
+
  185
+			$path = $this->Task->path . 'bake_test_app' . DS;
  186
+			$result = $this->Task->securityCipherSeed($path);
  187
+			$this->assertTrue($result);
  188
+
  189
+			$file =& new File($path . 'config' . DS . 'core.php');
  190
+			$contents = $file->read();
  191
+			$this->assertNoPattern('/76859309657453542496749683645/', $contents, 'Default CipherSeed left behind. %s');
  192
+		}
  193
+
176 194
 /**
177 195
  * Test that index.php is generated correctly.
178 196
  *

0 notes on commit 6a0ddb0

Please sign in to comment.
Something went wrong with that request. Please try again.