8000 Merge branch '3.1' · symfony/symfony@36ec085 · GitHub
[go: up one dir, main page]

Skip to content

Commit 36ec085

Browse files
Merge branch '3.1'
* 3.1: [HttpKernel] fixed internal subrequests having an if-modified-since-header [Security] Fix deprecated usage of DigestAuthenticationEntryPoint::getKey() in DigestAuthenticationListener [Validator] Added additional MasterCard range to the CardSchemeValidator Make the exception message more clear. [Form] fixed bug - name in ButtonBuilder [DoctrineBridge] added missing error code for constraint. [ClassLoader] Fix declared classes being computed when not needed [varDumper] Fix missing usage of ExceptionCaster::$traceArgs
2 parents 5213778 + f2599e4 commit 36ec085

File tree

13 files changed

+188
-7
lines changed

13 files changed

+188
-7
lines changed

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ public function testValidateUniqueness()
168168
->atPath('property.path.name')
169169
->setParameter('{{ value }}', 'Foo')
170170
->setInvalidValue('Foo')
171+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
171172
->assertRaised();
172173
}
173174

@@ -192,6 +193,7 @@ public function testValidateCustomErrorPath()
192193
->atPath('property.path.bar')
193194
->setParameter('{{ value }}', 'Foo')
194195
->setInvalidValue('Foo')
196+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
195197
->assertRaised();
196198
}
197199

@@ -244,6 +246,7 @@ public function testValidateUniquenessWithIgnoreNull()
244246
->atPath('property.path.name')
245247
->setParameter('{{ value }}', 'Foo')
246248
->setInvalidValue('Foo')
249+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
247250
->assertRaised();
248251
}
249252

@@ -276,6 +279,7 @@ public function testValidateUniquenessWithValidCustomErrorPath()
276279
->atPath('property.path.name2')
277280
->setParameter('{{ value }}', 'Bar')
278281
->setInvalidValue('Bar')
282+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
279283
->assertRaised();
280284
}
281285

@@ -409,6 +413,7 @@ public function testAssociatedEntity()
409413
->atPath('property.path.single')
410414
->setParameter('{{ value }}', $entity1)
411415
->setInvalidValue($entity1)
416+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
412417
->assertRaised();
413418
}
414419

src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntity.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
class UniqueEntity extends Constraint
2525
{
26+
const NOT_UNIQUE_ERROR = '23bd9dbf-6b9b-41cd-a99e-4844bcf3077f';
27+
2628
public $message = 'This value is already used.';
2729
public $service = 'doctrine.orm.validator.unique';
2830
public $em = null;
@@ -31,6 +33,10 @@ class UniqueEntity extends Constraint
3133
public $errorPath = null;
3234
public $ignoreNull = true;
3335

36+
protected static $errorNames = array(
37+
self::NOT_UNIQUE_ERROR => 'NOT_UNIQUE_ERROR',
38+
);
39+
3440
public function getRequiredOptions()
3541
{
3642
return array('fields');

src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ public function validate($entity, Constraint $constraint)
135135
->atPath($errorPath)
136136
->setParameter('{{ value }}', $invalidValue)
137137
->setInvalidValue($invalidValue)
138+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
138139
->addViolation();
139140
}
140141
}

src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
4343

4444
self::$loaded[$name] = true;
4545

46-
$declared = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());
47-
4846
if ($adaptive) {
47+
$declared = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());
48+
4949
// don't include already declared classes
5050
$classes = array_diff($classes, $declared);
5151

@@ -84,11 +84,14 @@ public static function load($classes, $cacheDir, $name, $autoReload, $adaptive =
8484
}
8585
}
8686

87-
if (!$reload && is_file($cache)) {
87+
if (!$reload && file_exists($cache)) {
8888
require_once $cache;
8989

9090
return;
9191
}
92+
if (!$adaptive) {
93+
$declared = array_merge(get_declared_classes(), get_declared_interfaces(), get_declared_traits());
94+
}
9295

9396
$files = array();
9497
$content = '';

src/Symfony/Component/Form/ButtonBuilder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ class ButtonBuilder implements \IteratorAggregate, FormBuilderInterface
6262
*/
6363
public function __construct($name, array $options = array())
6464
{
65-
if (empty($name) && 0 != $name) {
65+
$name = (string) $name;
66+
if ('' === $name) {
6667
throw new InvalidArgumentException('Buttons cannot have empty names.');
6768
}
6869

69-
$this->name = (string) $name;
70+
$this->name = $name;
7071
$this->options = $options;
7172
}
7273

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\Tests;
13+
14+
use Symfony\Component\Form\ButtonBuilder;
15+
16+
/**
17+
* @author Alexander Cheprasov <cheprasov.84@ya.ru>
18+
*/
19+
class ButtonBuilderTest extends \PHPUnit_Framework_TestCase
20+
{
21+
public function getValidNames()
22+
{
23+
return array(
24+
array('reset'),
25+
array('submit'),
26+
array('foo'),
27+
array('0'),
28+
array(0),
29+
array('button[]'),
30+
);
31+
}
32+
33+
/**
34+
* @dataProvider getValidNames
35+
*/
36+
public function testValidNames($name)
37+
{
38+
$this->assertInstanceOf('\Symfony\Component\Form\ButtonBuilder', new ButtonBuilder($name));
39+
}
40+
41+
public function getInvalidNames()
42+
{
43+
return array(
44+
array(''),
45+
array(false),
46+
array(null),
179B 47+
);
48+
}
49+
50+
/**
51+
* @dataProvider getInvalidNames
52+
*/
53+
public function testInvalidNames($name)
54+
{
55+
$this->setExpectedException(
56+
'\Symfony\Component\Form\Exception\InvalidArgumentException',
57+
'Buttons cannot have empty names.'
58+
);
59+
new ButtonBuilder($name);
60+
}
61+
}

src/Symfony/Component/HttpKernel/Fragment/InlineFragmentRenderer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ protected function createSubRequest($uri, Request $request)
129129
}
130130

131131
$server['REMOTE_ADDR'] = '127.0.0.1';
132+
unset($server['HTTP_IF_MODIFIED_SINCE']);
133+
unset($server['HTTP_IF_NONE_MATCH']);
132134

133135
$subRequest = Request::create($uri, 'get', array(), $cookies, array(), $server);
134136
if ($request->headers->has('Surrogate-Capability')) {

src/Symfony/Component/HttpKernel/Tests/Fragment/InlineFragmentRendererTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,19 @@ public function testESIHeaderIsKeptInSubrequestWithTrustedHeaderDisabled()
226226

227227
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, $trustedHeaderName);
228228
}
229+
230+
public function testHeadersPossiblyResultingIn304AreNotAssignedToSubrequest()
231+
{
232+
$expectedSubRequest = Request::create('/');
233+
if (Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP)) {
234+
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
235+
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
236+
}
237+
238+
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($expectedSubRequest));
239+
$request = Request::create('/', 'GET', array(), array(), array(), array('HTTP_IF_MODIFIED_SINCE' => 'Fri, 01 Jan 2016 00:00:00 GMT', 'HTTP_IF_NONE_MATCH' => '*'));
240+
$strategy->render('/', $request);
241+
}
229242
}
230243

231244
class Bar
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace Symfony\Component\Security\Http\Tests\Firewall;
4+
5+
use Symfony\Component\HttpFoundation\Request;
6+
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
7+
use Symfony\Component\Security\Http\EntryPoint\DigestAuthenticationEntryPoint;
8+
use Symfony\Component\Security\Http\Firewall\DigestAuthenticationListener;
9+
10+
class DigestAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
11+
{
12+
public function testHandleWithValidDigest()
13+
{
14+
$time = microtime(true) + 1000;
15+
$secret = 'ThisIsASecret';
16+
$nonce = base64_encode($time.':'.md5($time.':'.$secret));
17+
$username = 'user';
18+
$password = 'password';
19+
$realm = 'Welcome, robot!';
20+
$cnonce = 'MDIwODkz';
21+
$nc = '00000001';
22+
$qop = 'auth';
23+
$uri = '/path/info?p1=5&p2=5';
24+
25+
$serverDigest = $this->calculateServerDigest($username, $realm, $password, $nc, $nonce, $cnonce, $qop, 'GET', $uri);
26+
27+
$digestData =
28+
'username="'.$username.'", realm="'.$realm.'", nonce="'.$nonce.'", '.
29+
'uri="'.$uri.'", cnonce="'.$cnonce.'", nc='.$nc.', qop="'.$qop.'", '.
30+
'response="'.$serverDigest.'"'
31+
;
32+
33+
$request = new Request(array(), array(), array(), array(), array(), array('PHP_AUTH_DIGEST' => $digestData));
34+
35+
$entryPoint = new DigestAuthenticationEntryPoint($realm, $secret);
36+
37+
$user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
38+
$user->method('getPassword')->willReturn($password);
39+
40+
$providerKey = 'TheProviderKey';
41+
42+
$tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
43+
$tokenStorage
44+
->expects($this->once())
45+
->method('getToken')
46+
->will($this->returnValue(null))
47+
;
48+
$tokenStorage
49+
->expects($this->once())
50+
->method('setToken')
51+
->with($this->equalTo(new UsernamePasswordToken($user, $password, $providerKey)))
52+
;
53+
54+
$userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
55+
$userProvider->method('loadUserByUsername')->willReturn($user);
56+
57+
$listener = new DigestAuthenticationListener($tokenStorage, $userProvider, $providerKey, $entryPoint);
58+
59+
$event = $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false);
60+
$event
61+
->expects($this->any())
62+
->method('getRequest')
63+
->will($this->returnValue($request))
64+
;
65+
66+
$listener->handle($event);
67+
}
68+
69+
private function calculateServerDigest($username, $realm, $password, $nc, $nonce, $cnonce, $qop, $method, $uri)
70+
{
71+
$response = md5(
72+
md5($username.':'.$realm.':'.$password).':'.$nonce.':'.$nc.':'.$cnonce.':'.$qop.':'.md5($method.':'.$uri)
73+
);
74+
75+
return sprintf('username="%s", realm="%s", nonce="%s", uri="%s", cnonce="%s", nc=%s, qop="%s", response="%s"',
76+
$username, $realm, $nonce, $uri, $cnonce, $nc, $qop, $response
77+
);
78+
}
79+
}

src/Symfony/Component/Validator/Constraints/CardSchemeValidator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ class CardSchemeValidator extends ConstraintValidator
7373
'/^6[0-9]{11,18}$/',
7474
),
7575
// All MasterCard numbers start with the numbers 51 through 55. All have 16 digits.
76+
// October 2016 MasterCard numbers can also start with 222100 through 272099.
7677
'MASTERCARD' => array(
7778
'/^5[1-5][0-9]{14}$/',
79+
'/^2(22[1-9][0-9]{12}|2[3-9][0-9]{13}|[3-6][0-9]{14}|7[0-1][0-9]{13}|720[0-9]{12})$/',
7880
),
7981
// All Visa card numbers start with a 4. New cards have 16 digits. Old cards have 13.
8082
'VISA' => array(

src/Symfony/Component/Validator/Mapping/PropertyMetadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class PropertyMetadata extends MemberMetadata
3939
public function __construct($class, $name)
4040
{
4141
if (!property_exists($class, $name)) {
42-
throw new ValidatorException(sprintf('Property %s does not exist in class %s', $name, $class));
42+
throw new ValidatorException(sprintf('Property "%s" does not exist in class "%s"', $name, $class));
4343
}
4444

4545
parent::__construct($class, $name, $name);

src/Symfony/Component/Validator/Tests/Constraints/CardSchemeValidatorTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ public function getValidNumbers()
9797
array('MAESTRO', '6594371785970435599'),
9898
array('MASTERCARD', '5555555555554444'),
9999
array('MASTERCARD', '5105105105105100'),
100+
array('MASTERCARD', '2221005555554444'),
101+
array('MASTERCARD', '2230000000000000'),
102+
array('MASTERCARD', '2300000000000000'),
103+
array('MASTERCARD', '2699999999999999'),
104+
array('MASTERCARD', '2709999999999999'),
105+
array('MASTERCARD', '2720995105105100'),
100106
array('VISA', '4111111111111111'),
101107
array('VISA', '4012888888881881'),
102108
array('VISA', '4222222222222'),
@@ -124,6 +130,8 @@ public function getInvalidNumbers()
124130
array('AMEX', '000000000000', CardScheme::INVALID_FORMAT_ERROR), // a lone number
125131
array('DINERS', '3056930', CardScheme::INVALID_FORMAT_ERROR), // only first part of the number
126132
array('DISCOVER', '1117', CardScheme::INVALID_FORMAT_ERROR), // only last 4 digits
133+
array('MASTERCARD', '2721001234567890', CardScheme::INVALID_FORMAT_ERROR), // Not assigned yet
134+
array('MASTERCARD', '2220991234567890', CardScheme::INVALID_FORMAT_ERROR), // Not assigned yet
127135
);
128136
}
129137
}

src/Symfony/Component/VarDumper/Caster/ExceptionCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ private static function filterExceptionArray($xClass, array $a, $xPrefix, $filte
198198
'file' => $a[Caster::PREFIX_PROTECTED.'file'],
199199
'line' => $a[Caster::PREFIX_PROTECTED.'line'],
200200
));
201-
$a[$xPrefix.'trace'] = new TraceStub($trace);
201+
$a[$xPrefix.'trace'] = new TraceStub($trace, self::$traceArgs);
202202
}
203203
if (empty($a[$xPrefix.'previous'])) {
204204
unset($a[$xPrefix.'previous']);

0 commit comments

Comments
 (0)
0