public function testApprovesValidSignature()
{
$httpMethod = 'GET';
$url = 'http://imbo/users/christer/images/image';
$publicKey = 'christer';
$privateKey = 'key';
$timestamp = gmdate('Y-m-d\\TH:i:s\\Z');
$data = $httpMethod . '|' . $url . '|' . $publicKey . '|' . $timestamp;
$signature = hash_hmac('sha256', $data, $privateKey);
$this->accessControl->expects($this->once())->method('getPrivateKey')->will($this->returnValue($privateKey));
$this->headers->expects($this->at(0))->method('has')->with('x-imbo-authenticate-timestamp')->will($this->returnValue(true));
$this->headers->expects($this->at(1))->method('has')->with('x-imbo-authenticate-signature')->will($this->returnValue(true));
$this->headers->expects($this->at(2))->method('get')->with('x-imbo-authenticate-timestamp')->will($this->returnValue($timestamp));
$this->headers->expects($this->at(3))->method('get')->with('x-imbo-authenticate-signature')->will($this->returnValue($signature));
$this->request->expects($this->once())->method('getRawUri')->will($this->returnValue($url));
$this->request->expects($this->once())->method('getPublicKey')->will($this->returnValue($publicKey));
$this->request->expects($this->once())->method('getMethod')->will($this->returnValue($httpMethod));
$responseHeaders = $this->getMock('Symfony\\Component\\HttpFoundation\\ResponseHeaderBag');
$responseHeaders->expects($this->once())->method('set')->with('X-Imbo-AuthUrl', $url);
$this->response->headers = $responseHeaders;
$this->listener->authenticate($this->event);
}