You are here

function acquia_connector_test_nspi_update in Acquia Connector 7.3

Same name and namespace in other branches
  1. 7.2 acquia_agent/tests/acquia_connector_test.module \acquia_connector_test_nspi_update()

Test update.

1 call to acquia_connector_test_nspi_update()
acquia_connector_test_xmlrpc_server_emulator in acquia_agent/tests/acquia_connector_test.module
Needs comment.
1 string reference to 'acquia_connector_test_nspi_update'
acquia_connector_test_xmlrpc in acquia_agent/tests/acquia_connector_test.module
Test xmlrpc.

File

acquia_agent/tests/acquia_connector_test.module, line 310
Test endpoint for Acquia Connector XML-RPC calls.

Code

function acquia_connector_test_nspi_update($data) {
  $fields = array(
    'time' => 'is_numeric',
    'nonce' => 'is_string',
    'hash' => 'is_string',
  );
  $result = acquia_connector_test_basic_authenticator($fields, $data);
  if (!empty($result->is_error)) {
    return $result;
  }
  if (!empty($data['authenticator']['identifier'])) {

    // phpcs:ignore
    if (!in_array($data['authenticator']['identifier'], [
      ACQUIA_CONNECTOR_TEST_ID,
      ACQUIA_CONNECTOR_TEST_ERROR_ID,
      ACQUIA_CONNECTOR_TEST_REVOKED_ID,
    ])) {
      return xmlrpc_error(ACQUIA_CONNECTOR_TEST_SUBSCRIPTION_VALIDATION_ERROR, t('Subscription not found'));
    }
    if ($data['authenticator']['identifier'] == ACQUIA_CONNECTOR_TEST_ERROR_ID) {
      return FALSE;
    }
    else {
      $result = acquia_connector_test_validate_authenticator($data);
      $spi_data = $data['body'];
      $result->body = array(
        'spi_data_received' => TRUE,
        'site_revoked' => $data['authenticator']['identifier'] == ACQUIA_CONNECTOR_TEST_REVOKED_ID,
      );
      if (isset($spi_data['spi_def_update'])) {
        $result->body['update_spi_definition'] = TRUE;
      }

      // Reflect send_method as nspi_messages if set.
      if (isset($spi_data['send_method'])) {
        $result->body['nspi_messages'][] = $spi_data['send_method'];
      }
      $result->body['rpc_version'] = 3;
      $result->authenticator['hash'] = _acquia_agent_hmac($result->secret['key'], $result->authenticator['time'], $result->authenticator['nonce'], $result->body);
      if (isset($spi_data['test_validation_error'])) {

        // Force a validation fail.
        $result->authenticator['nonce'] = 'TEST';
      }
      $site_action = $spi_data['env_changed_action'];

      // First connection.
      if (empty($spi_data['site_uuid'])) {
        $site_action = 'create';
      }
      switch ($site_action) {
        case 'create':
          $result->body['site_uuid'] = ACQUIA_CONNECTOR_TEST_SITE_UUID;
          variable_set('acqtest_site_machine_name', $spi_data['machine_name']);
          variable_set('acqtest_site_name', $spi_data['name']);
          $acquia_hosted = (int) filter_var($spi_data['acquia_hosted'], FILTER_VALIDATE_BOOLEAN);
          variable_set('acqtest_site_acquia_hosted', $acquia_hosted);
          $result->body['nspi_messages'][] = t('This is the first connection from this site, it may take awhile for it to appear on the Acquia Network.');
          return (array) $result;
        case 'unblock':
        case 'block':
        case 'update':
          break;
      }
      unset($result->secret);
      return (array) $result;
    }
  }
  else {
    return xmlrpc_error(ACQUIA_CONNECTOR_TEST_SUBSCRIPTION_VALIDATION_ERROR, t('Invalid arguments'));
  }
}