Add test cases for invalid server configurations

This commit is contained in:
Robin Appelman 2013-05-01 16:38:42 +02:00
commit 190ac9501d
2 changed files with 25 additions and 6 deletions

View file

@ -87,14 +87,17 @@ class Server {
exec($command, $output); exec($command, $output);
$line = $output[0]; $line = $output[0];
$authError = 'NT_STATUS_LOGON_FAILURE'; $line = rtrim($line, ')');
if (substr($line, -23) === $authError) { if (substr($line, -23) === 'NT_STATUS_LOGON_FAILURE') {
$this->pipes = array(null, null);
throw new AuthenticationException(); throw new AuthenticationException();
} }
$addressError = 'NT_STATUS_BAD_NETWORK_NAME'; if (substr($line, -26) === 'NT_STATUS_BAD_NETWORK_NAME') {
if (substr($line, -26) === $addressError) { throw new InvalidHostException();
$this->pipes = array(null, null); }
if (substr($line, -22) === 'NT_STATUS_UNSUCCESSFUL') {
throw new InvalidHostException();
}
if (substr($line, -28) === 'NT_STATUS_CONNECTION_REFUSED') {
throw new InvalidHostException(); throw new InvalidHostException();
} }

View file

@ -32,4 +32,20 @@ class Server extends \PHPUnit_Framework_TestCase {
$server = new \SMB\Server($this->config->host, uniqid(), $this->config->password); $server = new \SMB\Server($this->config->host, uniqid(), $this->config->password);
$server->listShares(); $server->listShares();
} }
/**
* @expectedException \SMB\AuthenticationException
*/
public function testWrongPassword() {
$server = new \SMB\Server($this->config->host, $this->config->user, uniqid());
$server->listShares();
}
/**
* @expectedException \SMB\InvalidHostException
*/
public function testWrongHost() {
$server = new \SMB\Server(uniqid(), $this->config->user, $this->config->password);
$server->listShares();
}
} }