You are here

public function AcquiaSearchUnitTestCase::testExtractHMACHeader in Acquia Connector 7.2

Same name and namespace in other branches
  1. 7.3 acquia_search/tests/acquia_search.test \AcquiaSearchUnitTestCase::testExtractHmacHeader()

Tests extracting the hmac digest from the response header.

File

acquia_search/tests/acquia_search.test, line 117
Tests for the Acquia Search module.

Class

AcquiaSearchUnitTestCase
Unit tests of the functionality of the Acquia Search module.

Code

public function testExtractHMACHeader() {

  // Generate the expected hash.
  $nonce = $this
    ->randomName(32);
  $string = $this
    ->randomName(32);
  $hmac = hash_hmac('sha1', $nonce . $string, $this->derivedKey);

  // Pass header with an expected pragma.
  $header = array(
    'pragma' => 'hmac_digest=' . $hmac . ';',
  );
  $extracted = acquia_search_extract_hmac($header);
  $this
    ->assertEqual($hmac, $extracted, t('The HMAC digest was extracted from the response header.'), 'Acquia Search');

  // Pass header with a bad pragma.
  $bad_header1 = array(
    'pragma' => $this
      ->randomName(),
  );
  $bad_extracted1 = acquia_search_extract_hmac($bad_header1);
  $this
    ->assertEqual('', $bad_extracted1, t('Empty string returned by HMAC extraction function when an invalid pragma is passed.'), 'Acquia Search');

  // Pass in junk as the header.
  $bad_extracted2 = acquia_search_extract_hmac($this
    ->randomName());
  $this
    ->assertEqual('', $bad_extracted2, t('Empty string returned by HMAC extraction function when an invalid header is passed.'), 'Acquia Search');
}