Пример #1
0
 public function testHmacAndVerify()
 {
     $client = new Client();
     $client->setSharedKey($this->sharedkey);
     $data = ['fox' => 'quick', 'colour' => 'brown', 'dog' => 'lazy'];
     $signature = $client->createHMAC($data);
     $this->assertNotEmpty($signature);
     $this->assertTrue(is_string($data['cnonce']));
     $this->assertTrue(is_string($data['hmac']));
     $server = new Server();
     $server->setSharedKey($this->sharedkey);
     $server->verifyHMAC($data);
     $this->assertTrue(true);
     // Can't verify without signature
     unset($data['hmac']);
     try {
         $server->verifyHMAC($data);
         $this->assertTrue(false);
     } catch (SignatureException $e) {
         $this->assertTrue(true);
     }
     // Can't verify garbage signature
     $data['hmac'] = 'Garbage';
     try {
         $server->verifyHMAC($data);
         $this->assertTrue(false);
     } catch (SignatureException $e) {
         $this->assertTrue(true);
     }
     // Can't verify without cnonce
     $data = ['fox' => 'quick', 'colour' => 'brown', 'dog' => 'lazy'];
     $signature = $client->createHMAC($data);
     $this->assertNotEmpty($signature);
     unset($data['cnonce']);
     try {
         $server->verifyHMAC($data);
         $this->assertTrue(false);
     } catch (NonceException $e) {
         $this->assertTrue(true);
     }
 }