13 const SERVICE_ID =
'Magento\Webapi\Controller\Rest\TestService';
18 private $requestValidator;
26 private $storeManagerMock;
34 private $authorizationMock;
43 $this->requestMock = $this->getMockBuilder(\
Magento\Framework\Webapi\Rest\Request::class)
50 'getRequestedServices',
55 )->disableOriginalConstructor()->getMock();
56 $this->requestMock->expects($this->any())
57 ->method(
'getHttpHost')
58 ->willReturn(
'testHostName.com');
59 $routerMock = $this->getMockBuilder(\
Magento\Webapi\Controller\Rest\Router::class)->setMethods([
'match'])
60 ->disableOriginalConstructor()->getMock();
61 $this->routeMock = $this->getMockBuilder(\
Magento\Webapi\Controller\Rest\Router\Route::class)
62 ->setMethods([
'isSecure',
'getServiceMethod',
'getServiceClass',
'getAclResources',
'getParameters'])
63 ->disableOriginalConstructor()->getMock();
64 $this->authorizationMock = $this->getMockBuilder(\
Magento\Framework\Webapi\Authorization::class)
65 ->disableOriginalConstructor()->getMock();
66 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
67 $this->storeMock = $this->createMock(\
Magento\
Store\Api\Data\StoreInterface::class);
68 $this->storeManagerMock = $this->createMock(\
Magento\
Store\Model\StoreManagerInterface::class);
69 $this->storeManagerMock->expects($this->any())->method(
'getStore')->willReturn($this->storeMock);
71 $this->requestValidator =
73 \
Magento\Webapi\Controller\Rest\RequestValidator::class,
75 'request' => $this->requestMock,
76 'router' => $routerMock,
77 'authorization' => $this->authorizationMock,
78 'storeManager' => $this->storeManagerMock
83 $this->routeMock->expects($this->any())->method(
'getServiceClass')->will($this->returnValue(self::SERVICE_ID));
84 $this->routeMock->expects($this->any())->method(
'getServiceMethod')
85 ->will($this->returnValue(self::SERVICE_METHOD));
86 $routerMock->expects($this->any())->method(
'match')->will($this->returnValue($this->routeMock));
98 $this->routeMock->expects($this->any())->method(
'isSecure')->will($this->returnValue($isSecureRoute));
99 $this->routeMock->expects($this->any())->method(
'getAclResources')->will($this->returnValue([
'1']));
100 $this->requestMock->expects($this->any())->method(
'getRequestData')->will($this->returnValue([]));
101 $this->requestMock->expects($this->any())->method(
'isSecure')->will($this->returnValue($isSecureRequest));
102 $this->authorizationMock->expects($this->once())->method(
'isAllowed')->will($this->returnValue(
true));
103 $this->requestValidator->validate();
114 return [[
true,
true], [
false,
true], [
false,
false]];
125 $this->routeMock->expects($this->any())->method(
'isSecure')->will($this->returnValue(
true));
126 $this->routeMock->expects($this->any())->method(
'getAclResources')->will($this->returnValue([
'1']));
127 $this->requestMock->expects($this->any())->method(
'isSecure')->will($this->returnValue(
false));
128 $this->authorizationMock->expects($this->once())->method(
'isAllowed')->will($this->returnValue(
true));
130 $this->requestValidator->validate();
139 $this->authorizationMock->expects($this->once())->method(
'isAllowed')->will($this->returnValue(
false));
140 $this->routeMock->expects($this->any())->method(
'getAclResources')->will($this->returnValue([
'5',
'6']));
141 $this->requestValidator->validate();
testInSecureRequestOverSecureRoute()
testSecureRouteAndRequest($isSecureRoute, $isSecureRequest)
dataProviderSecureRequestSecureRoute()
testAuthorizationFailed()