/**
  * @expectedException \PSX\Http\Exception\BadRequestException
  */
 public function testFailure()
 {
     $store = new Memory();
     $handle = $this->makeHandshake($store);
     $username = '******';
     $password = '******';
     $nonce = $store->load('digest')->getNonce();
     $opaque = $store->load('digest')->getOpaque();
     $cnonce = md5(uniqid());
     $nc = '00000001';
     $ha1 = md5($username . ':psx:' . $password);
     $ha2 = md5('GET:/index.php');
     $response = md5($ha1 . ':' . $nonce . ':' . $nc . ':' . $cnonce . ':auth:' . $ha2);
     $params = array('username' => $username, 'realm' => 'psx', 'nonce' => $nonce, 'qop' => 'auth', 'nc' => $nc, 'cnonce' => $cnonce, 'response' => $response, 'opaque' => $opaque);
     $request = new Request(new Url('http://localhost/index.php'), 'GET', array('Authorization' => 'Digest ' . Authentication::encodeParameters($params)));
     $response = new Response();
     $filterChain = $this->getMockFilterChain();
     $filterChain->expects($this->never())->method('handle');
     $handle->handle($request, $response, $filterChain);
 }
示例#2
0
文件: Dispatch.php 项目: seytar/psx
 protected function handleStatusCodeException(StatusCode\StatusCodeException $e, ResponseInterface $response)
 {
     $response->setStatus($e->getStatusCode());
     if ($e instanceof StatusCode\MethodNotAllowedException) {
         $allowedMethods = $e->getAllowedMethods();
         if (!empty($allowedMethods)) {
             $response->setHeader('Allow', implode(', ', $allowedMethods));
         }
     } elseif ($e instanceof StatusCode\UnauthorizedException) {
         $type = $e->getType();
         $parameters = $e->getParameters();
         if (!empty($type)) {
             if (!empty($parameters)) {
                 $response->setHeader('WWW-Authenticate', $type . ' ' . Authentication::encodeParameters($parameters));
             } else {
                 $response->setHeader('WWW-Authenticate', $type);
             }
         }
     }
 }