public function testAfterDelete()
 {
     $integrationsData = array(Integration::ID => 1, Integration::NAME => 'TestIntegration1', Integration::EMAIL => '*****@*****.**', Integration::ENDPOINT => 'http://endpoint.com', Integration::SETUP_TYPE => 1);
     $userIdentifierMock = $this->getMockBuilder('\\Magento\\Authz\\Model\\UserIdentifier')->disableOriginalConstructor()->getMock();
     $this->authzServiceMock->expects($this->once())->method('removePermissions')->with($userIdentifierMock);
     $this->userIdentifierFactoryMock->expects($this->at(0))->method('create')->with(UserIdentifier::USER_TYPE_INTEGRATION, 1)->will($this->returnValue($userIdentifierMock));
     $this->authzServiceMock->expects($this->once())->method('removePermissions')->with($userIdentifierMock);
     $this->integrationV1Plugin->afterDelete($this->subjectMock, $integrationsData);
 }
Example #2
0
 /**
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testAfterInitIntegrationProcessingSuccess()
 {
     $testIntegration1Resource = array('Magento_Customer::manage', 'Magento_Customer::online', 'Magento_Sales::create', 'Magento_SalesRule::quote');
     $testIntegration2Resource = array('Magento_Catalog::product_read');
     $this->integrationConfigMock->expects($this->once())->method('getIntegrations')->will($this->returnValue(array('TestIntegration1' => array('resources' => $testIntegration1Resource), 'TestIntegration2' => array('resources' => $testIntegration2Resource))));
     $integrationsData1 = new \Magento\Framework\Object(array('id' => 1, Integration::NAME => 'TestIntegration1', Integration::EMAIL => '*****@*****.**', Integration::ENDPOINT => 'http://endpoint.com', Integration::SETUP_TYPE => 1));
     $integrationsData2 = new \Magento\Framework\Object(array('id' => 2, Integration::NAME => 'TestIntegration2', Integration::EMAIL => '*****@*****.**', Integration::SETUP_TYPE => 1));
     $this->integrationServiceMock->expects($this->at(0))->method('findByName')->with('TestIntegration1')->will($this->returnValue($integrationsData1));
     $this->integrationServiceMock->expects($this->at(1))->method('findByName')->with('TestIntegration2')->will($this->returnValue($integrationsData2));
     $userIdentifierMock1 = $this->getMockBuilder('\\Magento\\Authz\\Model\\UserIdentifier')->disableOriginalConstructor()->getMock();
     $this->userIdentifierFactoryMock->expects($this->at(0))->method('create')->with(UserIdentifier::USER_TYPE_INTEGRATION, 1)->will($this->returnValue($userIdentifierMock1));
     $userIdentifierMock2 = $this->getMockBuilder('\\Magento\\Authz\\Model\\UserIdentifier')->disableOriginalConstructor()->getMock();
     $this->userIdentifierFactoryMock->expects($this->at(1))->method('create')->with(UserIdentifier::USER_TYPE_INTEGRATION, 2)->will($this->returnValue($userIdentifierMock2));
     $this->authzServiceMock->expects($this->at(0))->method('grantPermissions')->with($userIdentifierMock1, $testIntegration1Resource);
     $this->authzServiceMock->expects($this->at(1))->method('grantPermissions')->with($userIdentifierMock2, $testIntegration2Resource);
     $this->apiSetupPlugin->afterInitIntegrationProcessing($this->subjectMock, array('TestIntegration1', 'TestIntegration2'));
 }
Example #3
0
 /**
  * Process integration resource permissions after the integration is created
  *
  * @param \Magento\Integration\Model\Resource\Setup $subject
  * @param string[] $integrationNames Name of integrations passed as array from the invocation chain
  *
  * @return string[]
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterInitIntegrationProcessing(\Magento\Integration\Model\Resource\Setup $subject, $integrationNames)
 {
     if (empty($integrationNames)) {
         return array();
     }
     /** @var array $integrations */
     $integrations = $this->_integrationConfig->getIntegrations();
     foreach ($integrationNames as $name) {
         if (isset($integrations[$name])) {
             $integration = $this->_integrationService->findByName($name);
             if ($integration->getId()) {
                 $userIdentifier = $this->_userIdentifierFactory->create(UserIdentifier::USER_TYPE_INTEGRATION, $integration->getId());
                 $this->_authzService->grantPermissions($userIdentifier, $integrations[$name]['resources']);
             }
         }
     }
     return $integrationNames;
 }
 /**
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  * @expectedExceptionMessage No such entity with userType = Admin
  */
 public function testRemovePermissionsException()
 {
     // Wrong user identifier type
     $this->_authzService->removePermissions($this->_getUserIdentifierMock(UserIdentifier::USER_TYPE_ADMIN));
 }
 /**
  * Check if access to the specified resources is prohibited to the user.
  *
  * @param UserIdentifier $userIdentifier
  * @param string[] $resources
  */
 protected function _ensurePermissionsAreNotGranted($userIdentifier, $resources)
 {
     foreach ($resources as $resource) {
         $this->assertFalse($this->_service->isAllowed($resource, $userIdentifier), "Access to resource '{$resource}' is expected to be prohibited.");
     }
 }