Пример #1
0
 /**
  * Handler for all SOAP operations.
  *
  * @param string $operation
  * @param array $arguments
  * @return \stdClass|null
  * @throws WebapiException
  * @throws \LogicException
  * @throws AuthorizationException
  */
 public function __call($operation, $arguments)
 {
     $requestedServices = $this->_request->getRequestedServices();
     $serviceMethodInfo = $this->_apiConfig->getServiceMethodInfo($operation, $requestedServices);
     $serviceClass = $serviceMethodInfo[SoapConfig::KEY_CLASS];
     $serviceMethod = $serviceMethodInfo[SoapConfig::KEY_METHOD];
     // check if the operation is a secure operation & whether the request was made in HTTPS
     if ($serviceMethodInfo[SoapConfig::KEY_IS_SECURE] && !$this->_request->isSecure()) {
         throw new WebapiException(__("Operation allowed only in HTTPS"));
     }
     $isAllowed = false;
     foreach ($serviceMethodInfo[SoapConfig::KEY_ACL_RESOURCES] as $resource) {
         if ($this->_authorization->isAllowed($resource)) {
             $isAllowed = true;
             break;
         }
     }
     if (!$isAllowed) {
         throw new AuthorizationException(__(AuthorizationException::NOT_AUTHORIZED, ['resources' => implode(', ', $serviceMethodInfo[SoapConfig::KEY_ACL_RESOURCES])]));
     }
     $service = $this->_objectManager->get($serviceClass);
     $inputData = $this->_prepareRequestData($serviceClass, $serviceMethod, $arguments);
     $outputData = call_user_func_array([$service, $serviceMethod], $inputData);
     return $this->_prepareResponseData($outputData, $serviceClass, $serviceMethod);
 }
Пример #2
0
 /**
  * Test generate uri with wsdl param as true
  */
 public function testGenerateUriWithNoWsdlParam()
 {
     $param = "testModule1AllSoapAndRest:V1,testModule2AllSoapNoRest:V1";
     $serviceKey = \Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_SERVICES;
     $this->_requestMock->expects($this->any())->method('getParam')->will($this->returnValue($param));
     $expectedResult = "http://magento.com/soap/storeCode?{$serviceKey}={$param}";
     $actualResult = $this->_soapServer->generateUri(false);
     $this->assertEquals($expectedResult, urldecode($actualResult), 'URI (without WSDL param) generated is invalid.');
 }
Пример #3
0
 /**
  * Get SOAP endpoint URL.
  *
  * @param bool $isWsdl
  * @return string
  */
 public function generateUri($isWsdl = false)
 {
     $params = [self::REQUEST_PARAM_SERVICES => $this->_request->getParam(self::REQUEST_PARAM_SERVICES)];
     if ($isWsdl) {
         $params[self::REQUEST_PARAM_WSDL] = true;
     }
     $query = http_build_query($params, '', '&');
     return $this->getEndpointUri() . '?' . $query;
 }
Пример #4
0
 public function testCall()
 {
     $requestedServices = array('requestedServices');
     $this->_requestMock->expects($this->once())->method('getRequestedServices')->will($this->returnValue($requestedServices));
     $this->_dataObjectConverter->expects($this->once())->method('convertStdObjectToArray')->will($this->returnValue(['field' => 1]));
     $operationName = 'soapOperation';
     $className = 'Magento\\Framework\\Object';
     $methodName = 'testMethod';
     $isSecure = false;
     $aclResources = array('Magento_TestModule::resourceA');
     $this->_apiConfigMock->expects($this->once())->method('getServiceMethodInfo')->with($operationName, $requestedServices)->will($this->returnValue(array(SoapConfig::KEY_CLASS => $className, SoapConfig::KEY_METHOD => $methodName, SoapConfig::KEY_IS_SECURE => $isSecure, SoapConfig::KEY_ACL_RESOURCES => $aclResources)));
     $this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
     $serviceMock = $this->getMockBuilder($className)->disableOriginalConstructor()->setMethods(array($methodName))->getMock();
     $serviceResponse = array('foo' => 'bar');
     $serviceMock->expects($this->once())->method($methodName)->will($this->returnValue($serviceResponse));
     $this->_objectManagerMock->expects($this->once())->method('get')->with($className)->will($this->returnValue($serviceMock));
     $this->_serializerMock->expects($this->once())->method('getInputData')->will($this->returnArgument(2));
     /** Execute SUT. */
     $this->assertEquals(array('result' => $serviceResponse), $this->_handler->__call($operationName, array((object) array('field' => 1))));
 }
Пример #5
0
 /**
  * Check if current request is WSDL request. SOAP operation execution request is another type of requests.
  *
  * @return bool
  */
 protected function _isWsdlRequest()
 {
     return $this->_request->getParam(\Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_WSDL) !== null;
 }
Пример #6
0
 /**
  * Mock getParam() of request object to return given value.
  *
  * @param $param
  * @param $value
  */
 protected function _mockGetParam($param, $value)
 {
     $this->_requestMock->expects($this->once())->method('getParam')->with($param)->will($this->returnValue($value));
 }
Пример #7
0
 /**
  * @dataProvider providerTestGetRequestedServicesSuccess
  * @param $requestParamServices
  * @param $expectedResult
  */
 public function testGetRequestedServicesSuccess($requestParamServices, $expectedResult)
 {
     $requestParams = [\Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_WSDL => true, \Magento\Webapi\Model\Soap\Server::REQUEST_PARAM_SERVICES => $requestParamServices];
     $this->_soapRequest->setParams($requestParams);
     $this->assertEquals($expectedResult, $this->_soapRequest->getRequestedServices());
 }