Source of file KapostBridgeLoggerTest.php
Size: 4,073 Bytes - Last Modified: 2021-12-23T10:57:42+00:00
/var/www/docs.ssmods.com/process/src/tests/KapostBridgeLoggerTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 | <?php class KapostBridgeLoggerTest extends FunctionalTest { const USER_AGENT='Kapost XMLRPC::Client'; protected static $fixture_file='KapostBridgeLoggerTest.yml'; /** * Test that 404's are ignored */ public function testIgnorePageNotFound() { //Try just a get $response=$this->get('/kapost-service'); $this->assertEquals(404, $response->getStatusCode()); $this->assertEquals(0, KapostBridgeLog::get()->count()); //Try just a post $response=$this->post('/kapost-bridge', array()); $this->assertEquals(404, $response->getStatusCode()); $this->assertEquals(0, KapostBridgeLog::get()->count()); } /** * Test to see that the request/response was actaully logged */ public function testBridgeLogging() { $response=$this->call_service('get-post'); //Ensure we had a 200 response $this->assertEquals(200, $response->getStatusCode()); //Find the log $log=KapostBridgeLog::get()->sort('ID DESC')->first(); //Ensure it exists $this->assertNotEmpty($log); $this->assertNotEquals(false, $log); $this->assertTrue($log->exists()); //Verify the log has the request details $this->assertNotEmpty($log->Request); //Verify the log has the response details $this->assertNotEmpty($log->Response); //Verify the called method is correct $this->assertEquals('metaWeblog.getPost', $log->Method); } /** * Tests to verify the password was stripped from the request */ public function testPasswordStripping() { $response=$this->call_service('get-post'); //Ensure we had a 200 response $this->assertEquals(200, $response->getStatusCode()); //Find the log $log=KapostBridgeLog::get()->sort('ID DESC')->first(); //Ensure it exists $this->assertNotEmpty($log); $this->assertNotEquals(false, $log); $this->assertTrue($log->exists()); //Parse the XML $xml=simplexml_load_string($log->Request); $this->assertEquals('['._t('LoggedKapostService.PASSWORD_FILTERED', '_PASSWORD FILTERED').']', $xml->params->param[2]->value->string); } /** * Tests to verify that the bits of the asset were stripped from the request */ public function testBitsStripping() { $response=$this->call_service('new-media-asset'); //Ensure we had a 200 response $this->assertEquals(200, $response->getStatusCode()); //Find the log $log=KapostBridgeLog::get()->sort('ID DESC')->first(); //Ensure it exists $this->assertNotEmpty($log); $this->assertNotEquals(false, $log); $this->assertTrue($log->exists()); //Parse the XML $xml=simplexml_load_string($log->Request); $this->assertEquals('['._t('LoggedKapostService.BITS_FILTERED', '_BASE64 BITS FILTERED').']', $xml->params->param[3]->value->struct->member[2]->value->base64); } /** * Calls the api and returns the response * @param string $mockRequest Mock Request to load * @return SS_HTTPResponse Response Object */ protected function call_service($mockRequest) { return $this->post('kapost-service', array(), array('User-Agent'=>self::USER_AGENT), null, file_get_contents(dirname(__FILE__).'/mock_requests/'.$mockRequest.'.xml')); } /** * Parses the response from the api * @param string $body XML Response * @return PhpXmlRpc\Request XML RPC Response Object */ final protected function parseRPCResponse($body) { $xmlmsg=new PhpXmlRpc\Request(''); return $xmlmsg->parseResponse($body, true, 'phpvals'); } } ?> |