@@ -141,7 +141,6 @@ class FormHelperTest extends TestCase
141
141
public function setUp ()
142
142
{
143
143
parent ::setUp ();
144
- session_id ('' );
145
144
146
145
Configure::write ('Config.language ' , 'eng ' );
147
146
Configure::write ('App.base ' , '' );
@@ -1133,8 +1132,11 @@ public function testValidateHashNoModel()
1133
1132
{
1134
1133
$ this ->Form ->request ->params ['_Token ' ] = 'foo ' ;
1135
1134
1136
- $ result = $ this ->Form ->secure (['anything ' ]);
1137
- $ this ->assertRegExp ('/b9731869b9915e3dee6250db1a1fad464371fb94/ ' , $ result );
1135
+ $ fields = ['anything ' ];
1136
+ $ result = $ this ->Form ->secure ($ fields );
1137
+
1138
+ $ hash = hash_hmac ('sha1 ' , serialize ($ fields ) . session_id (), Security::salt ());
1139
+ $ this ->assertContains ($ hash , $ result );
1138
1140
}
1139
1141
1140
1142
/**
@@ -1165,7 +1167,7 @@ public function testFormSecurityFields()
1165
1167
$ this ->Form ->request ->params ['_Token ' ] = 'testKey ' ;
1166
1168
$ result = $ this ->Form ->secure ($ fields );
1167
1169
1168
- $ hash = hash_hmac ('sha1 ' , serialize ($ fields ), Security::salt ());
1170
+ $ hash = hash_hmac ('sha1 ' , serialize ($ fields ) . session_id () , Security::salt ());
1169
1171
$ hash .= ': ' . 'Model.valid ' ;
1170
1172
$ hash = urlencode ($ hash );
1171
1173
$ tokenDebug = urlencode (json_encode ([
@@ -1213,7 +1215,7 @@ public function testFormSecurityFieldsNoDebugMode()
1213
1215
$ this ->Form ->request ->params ['_Token ' ] = 'testKey ' ;
1214
1216
$ result = $ this ->Form ->secure ($ fields );
1215
1217
1216
- $ hash = hash_hmac ('sha1 ' , serialize ($ fields ), Security::salt ());
1218
+ $ hash = hash_hmac ('sha1 ' , serialize ($ fields ) . session_id () , Security::salt ());
1217
1219
$ hash .= ': ' . 'Model.valid ' ;
1218
1220
$ hash = urlencode ($ hash );
1219
1221
$ expected = [
@@ -1406,9 +1408,8 @@ public function testFormSecurityMultipleFields()
1406
1408
];
1407
1409
$ result = $ this ->Form ->secure ($ fields );
1408
1410
1409
- $ hash = '51e3b55a6edd82020b3f29c9ae200e14bbeb7ee5%3AModel.0.hidden%7CModel.0.valid ' ;
1410
- $ hash = '16e544e04f6d3007231e3e23f8f73427a53272d4%3AModel.0.hidden%7CModel.0.valid ' ;
1411
- $ hash .= '%7CModel.1.hidden%7CModel.1.valid ' ;
1411
+ $ hash = '8670192c3f040bf58680479060b4755b7a5c3596 ' .
1412
+ '%3AModel.0.hidden%7CModel.0.valid%7CModel.1.hidden%7CModel.1.valid ' ;
1412
1413
$ tokenDebug = urlencode (json_encode ([
1413
1414
'' ,
1414
1415
$ fields ,
@@ -1608,7 +1609,7 @@ public function testFormSecurityMultipleControlFields()
1608
1609
$ this ->Form ->control ('Addresses.1.primary ' , ['type ' => 'checkbox ' ]);
1609
1610
1610
1611
$ result = $ this ->Form ->secure ($ this ->Form ->fields );
1611
- $ hash = '587942c6810603a6d5a07a394316dda455580227 %3AAddresses.0.id%7CAddresses.1.id ' ;
1612
+ $ hash = 'a4fe49bde94894a01375e7aa2873ea8114a96471 %3AAddresses.0.id%7CAddresses.1.id ' ;
1612
1613
$ tokenDebug = urlencode (json_encode ([
1613
1614
'/articles/add ' ,
1614
1615
[
@@ -1705,7 +1706,7 @@ public function testFormSecurityMultipleControlDisabledFields()
1705
1706
$ this ->Form ->text ('Addresses.1.phone ' );
1706
1707
1707
1708
$ result = $ this ->Form ->secure ($ this ->Form ->fields );
1708
- $ hash = '8db4b5f1a912dfafd9c264964df7aa598ea322c0 %3AAddresses.0.id%7CAddresses.1.id ' ;
1709
+ $ hash = '43c4db25e4162c5e4edd9dea51f5f9d9d92215ec %3AAddresses.0.id%7CAddresses.1.id ' ;
1709
1710
$ tokenDebug = urlencode (json_encode ([
1710
1711
'/articles/add ' ,
1711
1712
[
@@ -1783,7 +1784,7 @@ public function testFormSecurityControlUnlockedFields()
1783
1784
1784
1785
$ result = $ this ->Form ->secure ($ expected , ['data-foo ' => 'bar ' ]);
1785
1786
1786
- $ hash = 'cdc8fa2dd2aa2804c12cd17279c39747f1c57354 %3AAddresses.id ' ;
1787
+ $ hash = 'f98315a7d5515e5ae32e35f7d680207c085fae69 %3AAddresses.id ' ;
1787
1788
$ tokenDebug = urlencode (json_encode ([
1788
1789
'/articles/add ' ,
1789
1790
[
@@ -1857,7 +1858,7 @@ public function testFormSecurityControlUnlockedFieldsDebugSecurityTrue()
1857
1858
$ this ->assertEquals ($ expected , $ result );
1858
1859
$ result = $ this ->Form ->secure ($ expected , ['data-foo ' => 'bar ' , 'debugSecurity ' => true ]);
1859
1860
1860
- $ hash = 'cdc8fa2dd2aa2804c12cd17279c39747f1c57354 %3AAddresses.id ' ;
1861
+ $ hash = 'f98315a7d5515e5ae32e35f7d680207c085fae69 %3AAddresses.id ' ;
1861
1862
$ tokenDebug = urlencode (json_encode ([
1862
1863
'/articles/add ' ,
1863
1864
[
@@ -1932,7 +1933,7 @@ public function testFormSecurityControlUnlockedFieldsDebugSecurityDebugFalse()
1932
1933
Configure::write ('debug ' , false );
1933
1934
$ result = $ this ->Form ->secure ($ expected , ['data-foo ' => 'bar ' , 'debugSecurity ' => true ]);
1934
1935
1935
- $ hash = 'cdc8fa2dd2aa2804c12cd17279c39747f1c57354 %3AAddresses.id ' ;
1936
+ $ hash = 'f98315a7d5515e5ae32e35f7d680207c085fae69 %3AAddresses.id ' ;
1936
1937
$ expected = [
1937
1938
'div ' => ['style ' => 'display:none; ' ],
1938
1939
['input ' => [
@@ -1985,8 +1986,7 @@ public function testFormSecurityControlUnlockedFieldsDebugSecurityFalse()
1985
1986
$ this ->assertEquals ($ expected , $ result );
1986
1987
1987
1988
$ result = $ this ->Form ->secure ($ expected , ['data-foo ' => 'bar ' , 'debugSecurity ' => false ]);
1988
-
1989
- $ hash = 'cdc8fa2dd2aa2804c12cd17279c39747f1c57354%3AAddresses.id ' ;
1989
+ $ hash = 'f98315a7d5515e5ae32e35f7d680207c085fae69%3AAddresses.id ' ;
1990
1990
1991
1991
$ expected = [
1992
1992
'div ' => ['style ' => 'display:none; ' ],
@@ -2480,7 +2480,7 @@ public function testSecuredFormUrlIgnoresHost()
2480
2480
{
2481
2481
$ this ->Form ->request ->params ['_Token ' ] = ['key ' => 'testKey ' ];
2482
2482
2483
- $ expected = '8312b8faa7e74c6f36e05c8d188eda58b39fab20 %3A ' ;
2483
+ $ expected = '2548654895b160d724042ed269a2a863fd9d66ee %3A ' ;
2484
2484
$ this ->Form ->create ($ this ->article , [
2485
2485
'url ' => ['controller ' => 'articles ' , 'action ' => 'view ' , 1 , '? ' => ['page ' => 1 ]]
2486
2486
]);
@@ -2511,7 +2511,7 @@ public function testSecuredFormUrlHasHtmlAndIdentifier()
2511
2511
{
2512
2512
$ this ->Form ->request ->params ['_Token ' ] = ['key ' => 'testKey ' ];
2513
2513
2514
- $ expected = '93acdc2336947d62cf057a17275264c1fecc2443 %3A ' ;
2514
+ $ expected = '0a913f45b887b4d9cc2650ef1edc50183896959c %3A ' ;
2515
2515
$ this ->Form ->create ($ this ->article , [
2516
2516
'url ' => [
2517
2517
'controller ' => 'articles ' ,
@@ -5578,8 +5578,8 @@ public function testSelectMultipleCheckboxSecurity()
5578
5578
$ this ->assertEquals (['Model.multi_field ' ], $ this ->Form ->fields );
5579
5579
5580
5580
$ result = $ this ->Form ->secure ($ this ->Form ->fields );
5581
- $ key = '3cecbba5b65c8792d963b0498c67741466e61d47 %3A ' ;
5582
- $ this ->assertRegExp ( ' / " ' . $ key . '"/ ' , $ result );
5581
+ $ key = '8af36fb34e6f2ef8ba0eb473bb4365ec232f3fe5 %3A ' ;
5582
+ $ this ->assertContains ( ' " ' . $ key . '" ' , $ result );
5583
5583
}
5584
5584
5585
5585
/**
@@ -7613,7 +7613,7 @@ public function testPostLinkWithData()
7613
7613
*/
7614
7614
public function testPostLinkSecurityHash ()
7615
7615
{
7616
- $ hash = hash_hmac ('sha1 ' , '/posts/delete/1 ' . serialize (['id ' => '1 ' ]), Security::getSalt ());
7616
+ $ hash = hash_hmac ('sha1 ' , '/posts/delete/1 ' . serialize (['id ' => '1 ' ]) . session_id () , Security::getSalt ());
7617
7617
$ hash .= '%3Aid ' ;
7618
7618
$ this ->Form ->request ->params ['_Token ' ]['key ' ] = 'test ' ;
7619
7619
@@ -7666,7 +7666,7 @@ public function testPostLinkSecurityHash()
7666
7666
*/
7667
7667
public function testPostLinkSecurityHashBlockMode ()
7668
7668
{
7669
- $ hash = hash_hmac ('sha1 ' , '/posts/delete/1 ' . serialize ([]), Security::getSalt ());
7669
+ $ hash = hash_hmac ('sha1 ' , '/posts/delete/1 ' . serialize ([]) . session_id () , Security::getSalt ());
7670
7670
$ hash .= '%3A ' ;
7671
7671
$ this ->Form ->request ->params ['_Token ' ]['key ' ] = 'test ' ;
7672
7672
@@ -7690,7 +7690,7 @@ public function testPostLinkSecurityHashBlockMode()
7690
7690
public function testPostLinkSecurityHashNoDebugMode ()
7691
7691
{
7692
7692
Configure::write ('debug ' , false );
7693
- $ hash = hash_hmac ('sha1 ' , '/posts/delete/1 ' . serialize (['id ' => '1 ' ]), Security::getSalt ());
7693
+ $ hash = hash_hmac ('sha1 ' , '/posts/delete/1 ' . serialize (['id ' => '1 ' ]) . session_id () , Security::getSalt ());
7694
7694
$ hash .= '%3Aid ' ;
7695
7695
$ this ->Form ->request ->params ['_Token ' ]['key ' ] = 'test ' ;
7696
7696
0 commit comments