Skip to content

Commit

Permalink
Add check for empty server response and proper header for ASE includi…
Browse files Browse the repository at this point in the history
…ng tests. See #534
  • Loading branch information
Austinb committed May 3, 2020
1 parent 80e675a commit 64c490d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/GameQ/Protocols/Ase.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,22 @@ class Ase extends Protocol
*/
public function processResponse()
{

// Create a new buffer
$buffer = new Buffer(implode('', $this->packets_response));

// Burn the header
$buffer->skip(4);
// Check for valid response
if ($buffer->getLength() < 4) {
throw new \GameQ\Exception\Protocol(sprintf('%s The response from the server was empty.', __METHOD__));
}

// Read the header
$header = $buffer->read(4);

// Verify header
if ($header !== 'EYE1') {
throw new \GameQ\Exception\Protocol(sprintf('%s The response header "%s" does not match expected "EYE1"',
__METHOD__, $header));
}

// Create a new result
$result = new Result();
Expand Down
61 changes: 61 additions & 0 deletions tests/Protocols/Ase.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,65 @@ public function testPackets()
// Test to make sure packets are defined properly
$this->assertEquals($this->packets, \PHPUnit\Framework\Assert::readAttribute($this->stub, 'packets'));
}

/**
* Test invalid packet type without debug
*/
public function testInvalidPacketType()
{

// Read in a css source file
$source = file_get_contents(sprintf('%s/Providers/Mta/1_response.txt', __DIR__));

// Change the first packet to some unknown header
$source = str_replace("EYE1", "Something else", $source);

// Should show up as offline
$testResult = $this->queryTest('104.156.48.17:22003', 'mta', explode(PHP_EOL . '||' . PHP_EOL, $source), false);

$this->assertFalse($testResult['gq_online']);
}

/**
* Test for invalid packet type in response
*
* @expectedException \Exception
* @expectedExceptionMessage GameQ\Protocols\Ase::processResponse The response header "Some" does not match expected "EYE1"
*/
public function testInvalidPacketTypeDebug()
{

// Read in a css source file
$source = file_get_contents(sprintf('%s/Providers/Mta/1_response.txt', __DIR__));

// Change the first packet to some unknown header
$source = str_replace("EYE1", "Something else", $source);

// Should fail out
$this->queryTest('104.156.48.17:22003', 'mta', explode(PHP_EOL . '||' . PHP_EOL, $source), true);
}

/**
* Test empty server response without debug
*/
public function testEmptyServerResponse()
{

// Should show up as offline
$testResult = $this->queryTest('46.174.48.50:22051', 'mta', [], false);

$this->assertFalse($testResult['gq_online']);
}

/**
* Test empty server response
*
* @expectedException \Exception
* @expectedExceptionMessage GameQ\Protocols\Ase::processResponse The response from the server was empty.
*/
public function testEmptyServerResponseDebug()
{
// Should fail out
$this->queryTest('46.174.48.50:22051', 'mta', [], true);
}
}

0 comments on commit 64c490d

Please sign in to comment.