Ejemplo n.º 1
0
 /**
  * @expectedException \Magento\Integration\Exception
  * @expectedExceptionMessage Integration with ID '1' does not exist.
  */
 public function testGetException()
 {
     $this->_integrationMock->expects($this->any())->method('getId')->will($this->returnValue(null));
     $this->_integrationMock->expects($this->once())->method('load')->will($this->returnSelf());
     $this->_integrationMock->expects($this->never())->method('save');
     $this->_service->get(self::VALUE_INTEGRATION_ID)->getData();
 }
 /**
  * Check whether integration is inactive and don't allow using this integration in this case.
  *
  * It's ok that we break invocation chain since we're dealing with ACL here - if something is not allowed at any
  * point it couldn't be made allowed at some other point.
  *
  * @param \Magento\Authz\Service\AuthorizationV1 $subject
  * @param callable $proceed
  * @param mixed $resources
  * @param UserIdentifier $userIdentifier
  *
  * @return bool
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function aroundIsAllowed(\Magento\Authz\Service\AuthorizationV1 $subject, \Closure $proceed, $resources, \Magento\Authz\Model\UserIdentifier $userIdentifier = null)
 {
     /** @var UserIdentifier $userIdentifierObject */
     $userIdentifierObject = $userIdentifier ?: $this->_userIdentifier;
     if ($userIdentifierObject->getUserType() !== UserIdentifier::USER_TYPE_INTEGRATION) {
         return $proceed($resources, $userIdentifier);
     }
     try {
         $integration = $this->_integrationService->get($userIdentifierObject->getUserId());
     } catch (\Exception $e) {
         // Wrong integration ID or DB not reachable or whatever - give up and don't allow just in case
         $this->_logger->logException($e);
         return false;
     }
     if ($integration->getStatus() !== Integration::STATUS_ACTIVE) {
         return false;
     }
     return $proceed($resources, $userIdentifier);
 }