You are here

public function AcquiaSearchUnitTestCase::testHmacCookie in Acquia Connector 7.3

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

Tests HMAC generation.

File

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

Class

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

Code

public function testHmacCookie() {

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

  // @todo Make the API function more testable.
  $authenticator = acquia_search_authenticator($string, $nonce, $this->derivedKey, $time);
  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');
}