/** * {@inheritdoc} */ protected function setUp() { // Generate and store a random set of credentials. // Make them as close to the production values as possible // Something like AAAA-1234 $this->id = $this->randomMachineName(10); // Most of the keys and salts have a 32char lenght $this->key = $this->randomMachineName(32); $this->salt = $this->randomMachineName(32); // Include Solarium autoloader. $dirs = drupal_phpunit_contrib_extension_directory_roots(); $extensions = []; foreach ($dirs as $path) { $extensions += drupal_phpunit_find_extension_directories($path); } require_once $extensions['search_api_solr'] . '/vendor/autoload.php'; unset($extensions); $this->searchSubscriber = new SearchSubscriber(); $this->derivedKey = CryptConnector::createDerivedKey($this->salt, $this->id, $this->key); }
/** * Get the derived key for the solr hmac using the information shared with acquia.com. * @param null $env_id * @return mixed */ public function getDerivedKey($env_id = NULL) { if (empty($env_id)) { $env_id = $this->client->getEndpoint()->getKey(); } if (!isset($this->derived_key[$env_id])) { // If we set an explicit environment, check if this needs to overridden // Use the default $identifier = \Drupal::config('acquia_connector.settings')->get('identifier'); $key = \Drupal::config('acquia_connector.settings')->get('key'); // See if we need to overwrite these values // In any case, this is equal for all subscriptions. Also // even if the search sub is different, the main subscription should be // active $derived_key_salt = $this->getDerivedKeySalt(); // We use a salt from acquia.com in key derivation since this is a shared // value that we could change on the AN side if needed to force any // or all clients to use a new derived key. We also use a string // ('solr') specific to the service, since we want each service using a // derived key to have a separate one. if (empty($derived_key_salt) || empty($key) || empty($identifier)) { // Expired or invalid subscription - don't continue. $this->derived_key[$env_id] = ''; } elseif (!isset($derived_key[$env_id])) { $this->derived_key[$env_id] = CryptConnector::createDerivedKey($derived_key_salt, $identifier, $key); } } return $this->derived_key[$env_id]; }