|
|
@@ -195,6 +195,13 @@ trait IntegrationTestTrait
|
|
|
protected $_cookieEncryptionKey;
|
|
|
|
|
|
/**
|
|
|
+ * List of fields that are excluded from field validation.
|
|
|
+ *
|
|
|
+ * @var string[]
|
|
|
+ */
|
|
|
+ protected $_unlockedFields = [];
|
|
|
+
|
|
|
+ /**
|
|
|
* Auto-detect if the HTTP middleware stack should be used.
|
|
|
*
|
|
|
* @before
|
|
|
@@ -271,6 +278,17 @@ trait IntegrationTestTrait
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Set list of fields that are excluded from field validation.
|
|
|
+ *
|
|
|
+ * @param string[] $unlockedFields List of fields that are excluded from field validation.
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function setUnlockedFields(array $unlockedFields = [])
|
|
|
+ {
|
|
|
+ $this->_unlockedFields = $unlockedFields;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Calling this method will add a CSRF token to the request.
|
|
|
*
|
|
|
* Both the POST data and cookie will be populated when this option
|
|
|
@@ -671,10 +689,14 @@ trait IntegrationTestTrait
|
|
|
protected function _addTokens($url, $data)
|
|
|
{
|
|
|
if ($this->_securityToken === true) {
|
|
|
+ $fields = array_diff_key($data, array_flip($this->_unlockedFields));
|
|
|
+
|
|
|
$keys = array_map(function ($field) {
|
|
|
return preg_replace('/(\.\d+)+$/', '', $field);
|
|
|
- }, array_keys(Hash::flatten($data)));
|
|
|
- $tokenData = $this->_buildFieldToken($url, array_unique($keys));
|
|
|
+ }, array_keys(Hash::flatten($fields)));
|
|
|
+
|
|
|
+ $tokenData = $this->_buildFieldToken($url, array_unique($keys), $this->_unlockedFields);
|
|
|
+
|
|
|
$data['_Token'] = $tokenData;
|
|
|
$data['_Token']['debug'] = 'SecurityComponent debug data would be added here';
|
|
|
}
|