/** * Test insecure request for a secure route * * @expectedException \Magento\Framework\Webapi\Exception * @expectedExceptionMessage Operation allowed only in HTTPS */ public function testInSecureRequestOverSecureRoute() { $this->routeMock->expects($this->any())->method('isSecure')->will($this->returnValue(true)); $this->routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['1'])); $this->requestMock->expects($this->any())->method('isSecure')->will($this->returnValue(false)); $this->authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true)); $this->requestValidator->validate(); }
public function testGetMethodAllStoresInvalid() { $this->_routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['1'])); $this->_authorizationMock->expects($this->any())->method('isAllowed')->will($this->returnValue(true)); $this->storeMock->expects($this->once())->method('getCode')->willReturn('admin'); $this->_requestMock->expects($this->once())->method('getMethod')->willReturn('get'); $this->_restController->dispatch($this->_requestMock); $this->assertTrue($this->_responseMock->isException()); $this->assertSame("Cannot perform GET operation with store code 'all'", $this->_responseMock->getException()[0]->getMessage()); }
public function testDispatchAllSchemaRequest() { $params = [\Magento\Framework\Webapi\Request::REQUEST_PARAM_SERVICES => 'all']; $this->_requestMock->expects($this->any())->method('getPathInfo')->willReturn(\Magento\Webapi\Controller\Rest::SCHEMA_PATH); $this->_requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap([[\Magento\Framework\Webapi\Request::REQUEST_PARAM_SERVICES, null, 'all']])); $this->_requestMock->expects($this->any())->method('getParams')->will($this->returnValue($params)); $this->_requestMock->expects($this->any())->method('getRequestedServices')->will($this->returnValue('all')); $schema = 'Some REST schema content'; $this->swaggerGeneratorMock->expects($this->any())->method('generate')->willReturn($schema); $this->swaggerGeneratorMock->expects($this->once())->method('getListOfServices')->willReturn(['listOfServices']); $this->_restController->dispatch($this->_requestMock); $this->assertEquals($schema, $this->_responseMock->getBody()); }
/** * Test insecure request for a secure route */ public function testInSecureRequestOverSecureRoute() { $this->_serviceMock->expects($this->any())->method(self::SERVICE_METHOD)->will($this->returnValue([])); $this->_routeMock->expects($this->any())->method('isSecure')->will($this->returnValue(true)); $this->_routeMock->expects($this->any())->method('getAclResources')->will($this->returnValue(['1'])); $this->_requestMock->expects($this->any())->method('isSecure')->will($this->returnValue(false)); $this->_authorizationMock->expects($this->once())->method('isAllowed')->will($this->returnValue(true)); // Override default prepareResponse. It should never be called in this case $this->_responseMock->expects($this->never())->method('prepareResponse'); $this->_restController->dispatch($this->_requestMock); $this->assertTrue($this->_responseMock->isException()); $exceptionArray = $this->_responseMock->getException(); $this->assertEquals('Operation allowed only in HTTPS', $exceptionArray[0]->getMessage()); $this->assertEquals(\Magento\Framework\Webapi\Exception::HTTP_BAD_REQUEST, $exceptionArray[0]->getHttpCode()); }
/** * Test for getContentType() method. * * @dataProvider providerContentType * @param string $contentTypeHeader 'Content-Type' header value * @param string $contentType Appropriate content type for header value * @param string|boolean $exceptionMessage \Exception message (boolean FALSE if exception is not expected) */ public function testGetContentType($contentTypeHeader, $contentType, $exceptionMessage = false) { $this->_request->expects($this->once())->method('getHeader')->with('Content-Type')->will($this->returnValue($contentTypeHeader)); try { $this->assertEquals($contentType, $this->_request->getContentType()); } catch (\Magento\Framework\Exception\InputException $e) { if ($exceptionMessage) { $this->assertEquals($exceptionMessage, $e->getMessage(), 'Exception message does not match the expected one.'); return; } else { $this->fail('Exception is thrown on valid header: ' . $e->getMessage()); } } if ($exceptionMessage) { $this->fail('Expected exception was not raised.'); } }
/** * @dataProvider invalidFilterDataProvider */ public function testInvalidFilters($invalidFilter) { $this->requestMock->expects($this->any())->method('getParam')->will($this->returnValue($invalidFilter)); $filteredResponse = $this->processor->filter($this->sampleResponseValue); $this->assertEmpty($filteredResponse); }