Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 53a73c5

Browse files
committed
Revert "Revert "Merge branch 'superdweebie-rand-bugfix'""
This reverts commit b0ae4689135d62555cf9bbe55cdd7dddcd2d8f05 in order to allow forward-porting fixes to develop. Conflicts: library/Zend/ModuleManager/ModuleEvent.php

File tree

2 files changed

+81
-12
lines changed

2 files changed

+81
-12
lines changed

src/Adapter/Http.php

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,11 @@ public function authenticate()
336336

337337
$headers = $this->request->getHeaders();
338338
if (!$headers->has($getHeader)) {
339-
return $this->_challengeClient();
339+
return $this->challengeClient();
340340
}
341341
$authHeader = $headers->get($getHeader)->getFieldValue();
342342
if (!$authHeader) {
343-
return $this->_challengeClient();
343+
return $this->challengeClient();
344344
}
345345

346346
list($clientScheme) = explode(' ', $authHeader);
@@ -360,7 +360,7 @@ public function authenticate()
360360
// client sent a scheme that is not the one required
361361
if (!in_array($clientScheme, $this->acceptSchemes)) {
362362
// challenge again the client
363-
return $this->_challengeClient();
363+
return $this->challengeClient();
364364
}
365365

366366
switch ($clientScheme) {
@@ -377,6 +377,23 @@ public function authenticate()
377377
return $result;
378378
}
379379

380+
/**
381+
* @deprecated
382+
* @see Http::challengeClient()
383+
* @return Authentication\Result Always returns a non-identity Auth result
384+
*/
385+
protected function _challengeClient()
386+
{
387+
trigger_error(sprintf(
388+
'The method "%s" is deprecated and will be removed in the future; '
389+
. 'please use the public method "%s::challengeClient()" instead',
390+
__METHOD__,
391+
__CLASS__
392+
), E_USER_DEPRECATED);
393+
394+
return $this->challengeClient();
395+
}
396+
380397
/**
381398
* Challenge Client
382399
*
@@ -385,7 +402,7 @@ public function authenticate()
385402
*
386403
* @return Authentication\Result Always returns a non-identity Auth result
387404
*/
388-
protected function _challengeClient()
405+
public function challengeClient()
389406
{
390407
if ($this->imaProxy) {
391408
$statusCode = 407;
@@ -474,12 +491,12 @@ protected function _basicAuth($header)
474491
// implementation does. If invalid credentials are detected,
475492
// re-challenge the client.
476493
if (!ctype_print($auth)) {
477-
return $this->_challengeClient();
494+
return $this->challengeClient();
478495
}
479496
// Fix for ZF-1515: Now re-challenges on empty username or password
480497
$creds = array_filter(explode(':', $auth));
481498
if (count($creds) != 2) {
482-
return $this->_challengeClient();
499+
return $this->challengeClient();
483500
}
484501

485502
$result = $this->basicResolver->resolve($creds[0], $this->realm, $creds[1]);
@@ -498,7 +515,7 @@ protected function _basicAuth($header)
498515
return new Authentication\Result(Authentication\Result::SUCCESS, $result);
499516
}
500517

501-
return $this->_challengeClient();
518+
return $this->challengeClient();
502519
}
503520

504521
/**
@@ -530,17 +547,17 @@ protected function _digestAuth($header)
530547
// See ZF-1052. This code was a bit too unforgiving of invalid
531548
// usernames. Now, if the username is bad, we re-challenge the client.
532549
if ('::invalid::' == $data['username']) {
533-
return $this->_challengeClient();
550+
return $this->challengeClient();
534551
}
535552

536553
// Verify that the client sent back the same nonce
537554
if ($this->_calcNonce() != $data['nonce']) {
538-
return $this->_challengeClient();
555+
return $this->challengeClient();
539556
}
540557
// The opaque value is also required to match, but of course IE doesn't
541558
// play ball.
542559
if (!$this->ieNoOpaque && $this->_calcOpaque() != $data['opaque']) {
543-
return $this->_challengeClient();
560+
return $this->challengeClient();
544561
}
545562

546563
// Look up the user's password hash. If not found, deny access.
@@ -549,7 +566,7 @@ protected function _digestAuth($header)
549566
// to be recreatable with the current settings of this object.
550567
$ha1 = $this->digestResolver->resolve($data['username'], $data['realm']);
551568
if ($ha1 === false) {
552-
return $this->_challengeClient();
569+
return $this->challengeClient();
553570
}
554571

555572
// If MD5-sess is used, a1 value is made of the user's password
@@ -588,7 +605,7 @@ protected function _digestAuth($header)
588605
return new Authentication\Result(Authentication\Result::SUCCESS, $identity);
589606
}
590607

591-
return $this->_challengeClient();
608+
return $this->challengeClient();
592609
}
593610

594611
/**

test/Adapter/HttpTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
* @package Zend_Authentication
9+
*/
10+
11+
namespace ZendTest\Authentication\Adapter;
12+
13+
use Zend\Authentication\Adapter;
14+
15+
class HttpTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var Wrapper
19+
*/
20+
protected $_wrapper;
21+
22+
public function setUp()
23+
{
24+
$config = array(
25+
'accept_schemes' => 'basic',
26+
'realm' => 'testing',
27+
);
28+
29+
$this->_wrapper = new Wrapper($config);
30+
}
31+
32+
public function tearDown()
33+
{
34+
unset($this->_wrapper);
35+
}
36+
37+
/**
38+
* @expectedException PHPUnit_Framework_Error_Deprecated
39+
*/
40+
public function testProtectedMethodChallengeClientTriggersErrorDeprecated()
41+
{
42+
$this->_wrapper->_challengeClient();
43+
}
44+
}
45+
46+
class Wrapper extends Adapter\Http
47+
{
48+
public function __call($method, $args)
49+
{
50+
return call_user_func_array(array($this, $method), $args);
51+
}
52+
}

0 commit comments

Comments
 (0)