public function AcquiaSearchTest::testExtractHmacHeader in Acquia Connector 8
Covers extractHmac.
@covers ::extractHmac
File
- acquia_search/
tests/ src/ Unit/ AcquiaSearchTest.php, line 161
Class
- AcquiaSearchTest
- Isolated tests for Acquia Search.
Namespace
Drupal\Tests\acquia_search\UnitCode
public function testExtractHmacHeader() {
// Generate the expected hash.
$nonce = $this
->randomMachineName(32);
$string = $this
->randomMachineName(32);
$hmac = hash_hmac('sha1', $nonce . $string, $this->derivedKey);
// Pass header with an expected pragma.
$headers = [
'pragma/hmac_digest=' . $hmac . ';',
];
$extracted = $this->searchSubscriber
->extractHmac($headers);
$this
->assertEquals($hmac, $extracted, 'The HMAC digest was extracted from the response header.');
// Pass header with a bad pragma.
$bad_headers1 = [
'pragma/' . $this
->randomMachineName(),
];
$bad_extracted1 = $this->searchSubscriber
->extractHmac($bad_headers1);
$this
->assertEquals('', $bad_extracted1, 'Empty string returned by HMAC extraction function when an invalid pragma is passed.');
// Pass in junk as the header.
$bad_extracted2 = $this->searchSubscriber
->extractHmac($this
->randomMachineName());
$this
->assertEquals('', $bad_extracted2, 'Empty string returned by HMAC extraction function when an invalid header is passed.');
}