You are here

public function AcquiaSearchUnitTestCase::testHMACCookie in Acquia Search 6.3

Tests HMAC generation.

File

tests/acquia_search.test, line 79

Class

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

Code

public function testHMACCookie() {

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

  // @todo Make the API function more testable.
  $authenticator = acquia_search_authenticator($string, $nonce, $this->derivedKey);
  preg_match('/acquia_solr_hmac=([a-zA-Z0-9]{40});/', $authenticator, $matches);
  $this
    ->assertEqual($hmac, $matches[1], t('HMAC API function generates the expected hmac hash.'), 'Acquia Search');
  preg_match('/acquia_solr_time=([0-9]{10});/', $authenticator, $matches);
  $this
    ->assertNotNull($matches, t('HMAC API function generates a timestamp.'), 'Acquia Search');
  preg_match('/acquia_solr_nonce=([a-zA-Z0-9]{32});/', $authenticator, $matches);
  $this
    ->assertEqual($nonce, $matches[1], t('HMAC API function generates the expected nonce.'), 'Acquia Search');
}