/**
  * Test setReason()
  *
  * @covers ::setReason
  */
 public function testSetReason()
 {
     $a = new AccessResultForbidden();
     $reason = $this->getRandomGenerator()->string();
     $return = $a->setReason($reason);
     $this->assertSame($reason, $a->getReason());
     $this->assertSame($a, $return);
 }
 /**
  * Access callback for json() callback.
  */
 public function access()
 {
     $request = \Drupal::request();
     $nonce = $request->get('nonce', FALSE);
     $connector_config = $this->config('acquia_connector.settings');
     // If we don't have all the query params, leave now.
     if (!$nonce) {
         return AccessResultForbidden::forbidden();
     }
     $sub_data = $connector_config->get('subscription_data');
     $sub_uuid = $this->getIdFromSub($sub_data);
     if (!empty($sub_uuid)) {
         $expected_hash = hash('sha1', "{$sub_uuid}:{$nonce}");
         // If the generated hash matches the hash from $_GET['key'], we're good.
         if ($request->get('key', FALSE) === $expected_hash) {
             return AccessResultAllowed::allowed();
         }
     }
     // Log the request if validation failed and debug is enabled.
     if ($connector_config->get('debug')) {
         $info = array('sub_data' => $sub_data, 'sub_uuid_from_data' => $sub_uuid, 'expected_hash' => $expected_hash, 'get' => $request->query->all(), 'server' => $request->server->all(), 'request' => $request->request->all());
         \Drupal::logger('acquia_agent')->notice('Site status request: @data', array('@data' => var_export($info, TRUE)));
     }
     return AccessResultForbidden::forbidden();
 }
 /**
  * Access callback for sendModuleData() callback.
  */
 public function access()
 {
     $request = \Drupal::request();
     $data = json_decode($request->getContent(), TRUE);
     // We only do this if we are on SSL
     $via_ssl = $request->isSecure();
     if ($this->config('acquia_connector.settings')->get('spi.ssl_override')) {
         $via_ssl = TRUE;
     }
     if ($this->config('acquia_connector.settings')->get('spi.module_diff_data') && $via_ssl) {
         if (Subscription::hasCredentials() && isset($data['body']['file']) && $this->isValidRequest($data, $data['body']['file'])) {
             return AccessResultAllowed::allowed();
         }
         // Log the request if validation failed and debug is enabled.
         if ($this->config('acquia_connector.settings')->get('debug')) {
             $info = array('data' => $data, 'get' => $request->query->all(), 'server' => $request->server->all(), 'request' => $request->request->all());
             \Drupal::logger('acquia module data')->notice('Site Module Data request: @data', array('@data' => var_export($info, TRUE)));
         }
     }
     return AccessResultForbidden::forbidden();
 }
 /**
  * Access callback check for SPI send independent call.
  */
 public function sendAccess()
 {
     $request = \Drupal::request();
     $acquia_key = $this->config('acquia_connector.settings')->get('key');
     if (!empty($acquia_key) && $request->get('key')) {
         $key = sha1(\Drupal::service('private_key')->get());
         if ($key === $request->get('key')) {
             return AccessResultAllowed::allowed();
         }
     }
     return AccessResultForbidden::forbidden();
 }