/**
  * 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();
 }
예제 #2
0
 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());
 }
예제 #3
0
 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());
 }
예제 #4
0
 /**
  * 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());
 }
예제 #5
0
 /**
  * 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.');
     }
 }
예제 #6
0
 /**
  * @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);
 }